From 8cf99e5984fe8a4f4cdab6baaa9252a8cc32df13 Mon Sep 17 00:00:00 2001 From: berdir Date: Tue, 3 Mar 2015 19:17:54 -0600 Subject: [PATCH] Issue #2430797 by Berdir: Fixed request attribute _system_path was removed. --- src/Tests/TokenCurrentPageTest.php | 2 -- src/Tests/TokenMenuTest.php | 4 +-- token.pages.inc | 4 +-- token.tokens.inc | 40 +++++++++++++----------------- 4 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/Tests/TokenCurrentPageTest.php b/src/Tests/TokenCurrentPageTest.php index 4b68976..9d0517e 100644 --- a/src/Tests/TokenCurrentPageTest.php +++ b/src/Tests/TokenCurrentPageTest.php @@ -35,7 +35,6 @@ function testCurrentPageTokens() { '[current-page:page-number]' => 1, '[current-page:query:foo]' => NULL, '[current-page:query:bar]' => NULL, - '[current-page:query:q]' => 'user/login', // Deprecated tokens '[current-page:arg:0]' => 'user', '[current-page:arg:1]' => 'login', @@ -60,7 +59,6 @@ function testCurrentPageTokens() { '[current-page:page-number]' => 1, '[current-page:query:foo]' => 'bar', '[current-page:query:bar]' => NULL, - '[current-page:query:q]' => 'node/1', // Deprecated tokens '[current-page:arg:0]' => 'node', '[current-page:arg:1]' => 1, diff --git a/src/Tests/TokenMenuTest.php b/src/Tests/TokenMenuTest.php index 41963db..aa96fed 100644 --- a/src/Tests/TokenMenuTest.php +++ b/src/Tests/TokenMenuTest.php @@ -34,7 +34,7 @@ function testMenuTokens() { // Add a root link. /** @var \Drupal\menu_link_content\Plugin\Menu\MenuLinkContent $root_link */ $root_link = entity_create('menu_link_content', array( - 'link' => ['uri' => 'user-path:/admin'], + 'link' => ['uri' => 'internal:/admin'], 'title' => 'Administration', 'menu_name' => 'main-menu', )); @@ -43,7 +43,7 @@ function testMenuTokens() { // Add another link with the root link as the parent. /** @var \Drupal\menu_link_content\Plugin\Menu\MenuLinkContent $parent_link */ $parent_link = entity_create('menu_link_content', array( - 'link' => ['uri' => 'user-path:/admin/config'], + 'link' => ['uri' => 'internal:/admin/config'], 'title' => 'Configuration', 'menu_name' => 'main-menu', 'parent' => $root_link->getPluginId(), diff --git a/token.pages.inc b/token.pages.inc index 5fc4da4..97ee93d 100644 --- a/token.pages.inc +++ b/token.pages.inc @@ -111,10 +111,10 @@ function theme_token_tree($variables) { } $element = array( - '#cache' => array( + /*'#cache' => array( 'cid' => 'tree-rendered:' . hash('sha256', serialize(array('token_types' => $token_types, 'global_types' => NULL) + $variables)), 'tags' => array(Token::TOKEN_INFO_CACHE_TAG), - ), + ),*/ ); // @todo Find a way to use the render cache for this. diff --git a/token.tokens.inc b/token.tokens.inc index 4e3d788..327d7a4 100644 --- a/token.tokens.inc +++ b/token.tokens.inc @@ -381,12 +381,12 @@ function token_tokens($type, array $tokens, array $data = array(), array $option $replacements = array(); $url_options = array('absolute' => TRUE); - if (isset($options['language'])) { - $url_options['language'] = $options['language']; - $language_code = $options['language']->language; + if (isset($options['langcode'])) { + $url_options['language'] = language_load($options['langcode']); + $langcode = $options['langcode']; } else { - $language_code = NULL; + $langcode = NULL; } $sanitize = !empty($options['sanitize']); @@ -399,7 +399,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option $date_format_types = \Drupal::entityManager()->getStorage('date_format')->loadMultiple(); foreach ($tokens as $name => $original) { if (isset($date_format_types[$name]) && _token_module('date', $name) == 'token') { - $replacements[$original] = format_date($date, $name, '', NULL, $language_code); + $replacements[$original] = format_date($date, $name, '', NULL, $langcode); } } } @@ -697,9 +697,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option $replacements[$original] = $sanitize ? $title : String::decodeEntities($title); break; case 'url': - // Strip the query string from the result of Request::getUri(). - list($uri) = explode('?', \Drupal::request()->getUri()); - $replacements[$original] = Url::fromUri($uri, $url_options)->toString(); + $replacements[$original] = Url::fromRoute('', [], $url_options)->toString(); break; case 'page-number': if ($page = \Drupal::request()->query->get('page')) { @@ -715,7 +713,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option // @deprecated // [current-page:arg] dynamic tokens. if ($arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'arg')) { - $path = \Drupal::request()->attributes->get('_system_path'); + $path = ltrim(\Drupal::service('path.current')->getPath(), '/'); // Make sure its a system path. $path = \Drupal::service('path.alias_manager')->getPathByAlias($path); foreach ($arg_tokens as $name => $original) { @@ -734,16 +732,12 @@ function token_tokens($type, array $tokens, array $data = array(), array $option $value = \Drupal::request()->query->get($name); $replacements[$original] = $sanitize ? String::checkPlain($value) : $value; } - elseif ($name == 'q') { - $replacements[$original] = \Drupal::request()->attributes->get('_system_path'); - } } } // Chained token relationships. if ($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) { - $request = \Drupal::request(); - $url = new Url($request->attributes->get(RouteObjectInterface::ROUTE_OBJECT), $request->attributes->get('_raw_variables')->all()); + $url = Url::fromRoute(''); $replacements += \Drupal::token()->generate('url', $url_tokens, array('url' => $url), $options); } } @@ -759,12 +753,12 @@ function token_tokens($type, array $tokens, array $data = array(), array $option foreach ($tokens as $name => $original) { switch ($name) { case 'path': - $value = !($url->getOption('alias')) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $language_code) : $path; + $value = !($url->getOption('alias')) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $langcode) : $path; $replacements[$original] = $sanitize ? String::checkPlain($value) : $value; break; case 'alias': // @deprecated - $alias = \Drupal::service('path.alias_manager')->getAliasByPath($path, $language_code); + $alias = \Drupal::service('path.alias_manager')->getAliasByPath($path, $langcode); $replacements[$original] = $sanitize ? String::checkPlain($alias) : $alias; break; case 'absolute': @@ -781,7 +775,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option $replacements[$original] = $unaliased->setAbsolute()->setOption('alias', TRUE)->toString(); break; case 'args': - $value = !($url->getOption('alias')) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $language_code) : $path; + $value = !($url->getOption('alias')) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $langcode) : $path; $replacements[$original] = token_render_array(explode('/', $value), $options); break; @@ -790,7 +784,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option // [url:args:*] chained tokens. if ($arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'args')) { - $value = !($url->getOption('alias')) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $language_code) : $path; + $value = !($url->getOption('alias')) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $langcode) : $path; $replacements += \Drupal::token()->generate('array', $arg_tokens, array('array' => explode('/', $value)), $options); } @@ -1052,12 +1046,12 @@ function menu_ui_tokens($type, $tokens, array $data = array(), array $options = $menu_link_manager = \Drupal::service('plugin.manager.menu.link'); $url_options = array('absolute' => TRUE); - if (isset($options['language'])) { - $url_options['language'] = $options['language']; - $language_code = $options['language']->getId(); + if (isset($options['langcode'])) { + $url_options['language'] = language_load($options['langcode']); + $langcode = $options['langcode']; } else { - $language_code = NULL; + $langcode = NULL; } $sanitize = !empty($options['sanitize']); @@ -1248,7 +1242,7 @@ function _token_field_label($entity_type, $field_name) { function field_tokens($type, $tokens, array $data = array(), array $options = array()) { $replacements = array(); $sanitize = !empty($options['sanitize']); - $langcode = isset($options['language']) ? $options['language']->language : NULL; + $langcode = isset($options['langcode']) ? $options['langcode'] : NULL; // Entity tokens. if ($type == 'entity' && !empty($data['entity_type']) && !empty($data['entity']) && !empty($data['token_type'])) {