diff --git a/src/Tests/Tree/TreeTest.php b/src/Tests/Tree/TreeTest.php index 12e1d18..ed1dd3c 100644 --- a/src/Tests/Tree/TreeTest.php +++ b/src/Tests/Tree/TreeTest.php @@ -125,6 +125,9 @@ class TreeTest extends TokenTestBase { * link and the token. This then replaces the options query parameter with the * specified options. * + * The page also uses a title callback to set title to a render array, which + * allows us to test if [current-page:title] works properly. + * * @param array $options * The options for the token tree browser. * @@ -133,6 +136,7 @@ class TreeTest extends TokenTestBase { */ protected function getTokenTreeUrl($options = []) { $this->drupalGet('token_module_test/browse'); + $this->assertTitle('Available Tokens | Drupal'); $links = $this->xpath('//a[contains(@href, :href)]/@href', array(':href' => 'token/tree')); $link = $this->getAbsoluteUrl((string) current($links)); if (!empty($options)) { diff --git a/tests/modules/token_module_test/src/Controller/TokenTreeBrowseController.php b/tests/modules/token_module_test/src/Controller/TokenTreeBrowseController.php index d80104e..9b2ba08 100644 --- a/tests/modules/token_module_test/src/Controller/TokenTreeBrowseController.php +++ b/tests/modules/token_module_test/src/Controller/TokenTreeBrowseController.php @@ -11,8 +11,27 @@ class TokenTreeBrowseController extends ControllerBase { * Page callback to output a link. */ function outputLink(Request $request) { - $build['#title'] = $this->t('Available tokens'); $build['tree']['#theme'] = 'token_tree_link'; + $build['tokenarea'] = [ + '#markup' => \Drupal::token()->replace('[current-page:title]'), + '#type' => 'markup', + ]; return $build; } + + /** + * Title callback for the page outputting a link. + * + * We are using a title callback instead of directly defining the title in the + * routing YML file. This is so that we could return an array instead of a + * simple string. This allows us to test if [current-page:title] works with + * render arrays and other objects as titles. + */ + public function getTitle() { + return [ + '#type' => 'markup', + '#markup' => 'Available Tokens', + ]; + } + } diff --git a/tests/modules/token_module_test/token_module_test.routing.yml b/tests/modules/token_module_test/token_module_test.routing.yml index 8fbdb82..fb99f1c 100644 --- a/tests/modules/token_module_test/token_module_test.routing.yml +++ b/tests/modules/token_module_test/token_module_test.routing.yml @@ -2,5 +2,6 @@ token_module_test.browse: path: '/token_module_test/browse' defaults: _controller: '\Drupal\token_module_test\Controller\TokenTreeBrowseController::outputLink' + _title_callback: '\Drupal\token_module_test\Controller\TokenTreeBrowseController::getTitle' requirements: _access: 'TRUE' diff --git a/token.tokens.inc b/token.tokens.inc index 70c8672..d5a0d7c 100644 --- a/token.tokens.inc +++ b/token.tokens.inc @@ -738,7 +738,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option $request = \Drupal::request(); $route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT); $title = \Drupal::service('title_resolver')->getTitle($request, $route); - $replacements[$original] = $title; + $replacements[$original] = token_render_array_value($title); break; case 'url': $replacements[$original] = Url::fromRoute('', [], $url_options)->toString();