diff --git a/core/lib/Drupal/Core/Utility/Token.php b/core/lib/Drupal/Core/Utility/Token.php index 252fd0f..c7ac245 100644 --- a/core/lib/Drupal/Core/Utility/Token.php +++ b/core/lib/Drupal/Core/Utility/Token.php @@ -281,7 +281,7 @@ public function findWithPrefix(array $tokens, $prefix, $delimiter = ':') { * An associative array of token information, grouped by token type. */ function info() { - $data = &drupal_static(__FUNCTION__); + $data = &drupal_static('token_info'); if (!isset($data)) { $data = $this->moduleHandler->invokeAll('token_info'); $this->moduleHandler->alter('token_info', $data); diff --git a/core/modules/comment/comment.tokens.inc b/core/modules/comment/comment.tokens.inc index d02c09a..947c2a5 100644 --- a/core/modules/comment/comment.tokens.inc +++ b/core/modules/comment/comment.tokens.inc @@ -103,7 +103,7 @@ function comment_token_info() { * Implements hook_tokens(). */ function comment_tokens($type, $tokens, array $data = array(), array $options = array()) { - $token = \Drupal::token(); + $token_service = \Drupal::token(); $url_options = array('absolute' => TRUE); if (isset($options['langcode'])) { @@ -200,25 +200,25 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = } // Chained token relationships. - if ($node_tokens = $token->findwithPrefix($tokens, 'node')) { + if ($node_tokens = $token_service->findwithPrefix($tokens, 'node')) { $node = $comment->nid->entity; - $replacements += $token->generate('node', $node_tokens, array('node' => $node), $options); + $replacements += $token_service->generate('node', $node_tokens, array('node' => $node), $options); } - if ($date_tokens = $token->findwithPrefix($tokens, 'created')) { - $replacements += $token->generate('date', $date_tokens, array('date' => $comment->created->value), $options); + if ($date_tokens = $token_service->findwithPrefix($tokens, 'created')) { + $replacements += $token_service->generate('date', $date_tokens, array('date' => $comment->created->value), $options); } - if ($date_tokens = $token->findwithPrefix($tokens, 'changed')) { - $replacements += $token->generate('date', $date_tokens, array('date' => $comment->changed->value), $options); + if ($date_tokens = $token_service->findwithPrefix($tokens, 'changed')) { + $replacements += $token_service->generate('date', $date_tokens, array('date' => $comment->changed->value), $options); } - if (($parent_tokens = $token->findwithPrefix($tokens, 'parent')) && $parent = $comment->pid->entity) { - $replacements += $token->generate('comment', $parent_tokens, array('comment' => $parent), $options); + if (($parent_tokens = $token_service->findwithPrefix($tokens, 'parent')) && $parent = $comment->pid->entity) { + $replacements += $token_service->generate('comment', $parent_tokens, array('comment' => $parent), $options); } - if (($author_tokens = $token->findwithPrefix($tokens, 'author')) && $account = $comment->uid->entity) { - $replacements += $token->generate('user', $author_tokens, array('user' => $account), $options); + if (($author_tokens = $token_service->findwithPrefix($tokens, 'author')) && $account = $comment->uid->entity) { + $replacements += $token_service->generate('user', $author_tokens, array('user' => $account), $options); } } elseif ($type == 'node' & !empty($data['node'])) { diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php index 0c19c12..92be58f 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php @@ -23,7 +23,7 @@ public static function getInfo() { * Creates a comment, then tests the tokens generated from it. */ function testCommentTokenReplacement() { - $token = \Drupal::token(); + $token_service = \Drupal::token(); $language_interface = language(LANGUAGE_TYPE_INTERFACE); $url_options = array( 'absolute' => TRUE, @@ -73,7 +73,7 @@ function testCommentTokenReplacement() { $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { - $output = $token->replace($input, array('comment' => $comment), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->langcode)); $this->assertEqual($output, $expected, format_string('Sanitized comment token %token replaced.', array('%token' => $input))); } @@ -89,7 +89,7 @@ function testCommentTokenReplacement() { $tests['[comment:author:name]'] = $this->admin_user->name; foreach ($tests as $input => $expected) { - $output = $token->replace($input, array('comment' => $comment), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); + $output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized comment token %token replaced.', array('%token' => $input))); } @@ -102,7 +102,7 @@ function testCommentTokenReplacement() { $tests['[node:comment-count-new]'] = 2; foreach ($tests as $input => $expected) { - $output = $token->replace($input, array('node' => $node), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array('node' => $node), array('langcode' => $language_interface->langcode)); $this->assertEqual($output, $expected, format_string('Node comment token %token replaced.', array('%token' => $input))); } } diff --git a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php index 4cf37c8..36b32b1 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php @@ -23,7 +23,7 @@ public static function getInfo() { * Creates a file, then tests the tokens generated from it. */ function testFileTokenReplacement() { - $token = \Drupal::token(); + $token_service = \Drupal::token(); $language_interface = language(LANGUAGE_TYPE_INTERFACE); $url_options = array( 'absolute' => TRUE, @@ -66,7 +66,7 @@ function testFileTokenReplacement() { $this->assertFalse(in_array(0, array_map('strlen', $tests)), t('No empty tokens generated.')); foreach ($tests as $input => $expected) { - $output = $token->replace($input, array('file' => $file), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array('file' => $file), array('langcode' => $language_interface->langcode)); $this->assertEqual($output, $expected, t('Sanitized file token %token replaced.', array('%token' => $input))); } @@ -77,7 +77,7 @@ function testFileTokenReplacement() { $tests['[file:size]'] = format_size($file->filesize); foreach ($tests as $input => $expected) { - $output = $token->replace($input, array('file' => $file), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); + $output = $token_service->replace($input, array('file' => $file), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); $this->assertEqual($output, $expected, t('Unsanitized file token %token replaced.', array('%token' => $input))); } } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php index 3905d47..7a9e5f0 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php @@ -23,7 +23,7 @@ public static function getInfo() { * Creates a node, then tests the tokens generated from it. */ function testNodeTokenReplacement() { - $token = \Drupal::token(); + $token_service = \Drupal::token(); $language_interface = language(LANGUAGE_TYPE_INTERFACE); $url_options = array( 'absolute' => TRUE, @@ -67,7 +67,7 @@ function testNodeTokenReplacement() { $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { - $output = $token->replace($input, array('node' => $node), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array('node' => $node), array('langcode' => $language_interface->langcode)); $this->assertEqual($output, $expected, format_string('Sanitized node token %token replaced.', array('%token' => $input))); } @@ -79,7 +79,7 @@ function testNodeTokenReplacement() { $tests['[node:author:name]'] = user_format_name($account); foreach ($tests as $input => $expected) { - $output = $token->replace($input, array('node' => $node), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); + $output = $token_service->replace($input, array('node' => $node), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized node token %token replaced.', array('%token' => $input))); } @@ -100,7 +100,7 @@ function testNodeTokenReplacement() { $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated for node without a summary.'); foreach ($tests as $input => $expected) { - $output = $token->replace($input, array('node' => $node), array('language' => $language_interface)); + $output = $token_service->replace($input, array('node' => $node), array('language' => $language_interface)); $this->assertEqual($output, $expected, format_string('Sanitized node token %token replaced for node without a summary.', array('%token' => $input))); } @@ -108,7 +108,7 @@ function testNodeTokenReplacement() { $tests['[node:summary]'] = $node->body[$node->langcode][0]['value']; foreach ($tests as $input => $expected) { - $output = $token->replace($input, array('node' => $node), array('language' => $language_interface, 'sanitize' => FALSE)); + $output = $token_service->replace($input, array('node' => $node), array('language' => $language_interface, 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized node token %token replaced for node without a summary.', array('%token' => $input))); } } diff --git a/core/modules/node/node.tokens.inc b/core/modules/node/node.tokens.inc index 53e2238..63b51e1 100644 --- a/core/modules/node/node.tokens.inc +++ b/core/modules/node/node.tokens.inc @@ -90,7 +90,7 @@ function node_token_info() { * Implements hook_tokens(). */ function node_tokens($type, $tokens, array $data = array(), array $options = array()) { - $token = \Drupal::token(); + $token_service = \Drupal::token(); $url_options = array('absolute' => TRUE); if (isset($options['langcode'])) { @@ -199,17 +199,17 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr } } - if ($author_tokens = $token->findWithPrefix($tokens, 'author')) { + if ($author_tokens = $token_service->findWithPrefix($tokens, 'author')) { $author = user_load($node->uid); - $replacements += $token->generate('user', $author_tokens, array('user' => $author), $options); + $replacements += $token_service->generate('user', $author_tokens, array('user' => $author), $options); } - if ($created_tokens = $token->findWithPrefix($tokens, 'created')) { - $replacements += $token->generate('date', $created_tokens, array('date' => $node->created), $options); + if ($created_tokens = $token_service->findWithPrefix($tokens, 'created')) { + $replacements += $token_service->generate('date', $created_tokens, array('date' => $node->created), $options); } - if ($changed_tokens = $token->findWithPrefix($tokens, 'changed')) { - $replacements += $token->generate('date', $changed_tokens, array('date' => $node->changed), $options); + if ($changed_tokens = $token_service->findWithPrefix($tokens, 'changed')) { + $replacements += $token_service->generate('date', $changed_tokens, array('date' => $node->changed), $options); } } diff --git a/core/modules/statistics/statistics.tokens.inc b/core/modules/statistics/statistics.tokens.inc index 90dc988..5320e4f 100644 --- a/core/modules/statistics/statistics.tokens.inc +++ b/core/modules/statistics/statistics.tokens.inc @@ -32,7 +32,7 @@ function statistics_token_info() { * Implements hook_tokens(). */ function statistics_tokens($type, $tokens, array $data = array(), array $options = array()) { - $token = \Drupal::token(); + $token_service = \Drupal::token(); $url_options = array('absolute' => TRUE); $replacements = array(); @@ -55,9 +55,9 @@ function statistics_tokens($type, $tokens, array $data = array(), array $options } } - if ($created_tokens = $token->findWithPrefix($tokens, 'last-view')) { + if ($created_tokens = $token_service->findWithPrefix($tokens, 'last-view')) { $statistics = statistics_get($node->nid); - $replacements += $token->generate('date', $created_tokens, array('date' => $statistics['timestamp']), $options); + $replacements += $token_service->generate('date', $created_tokens, array('date' => $statistics['timestamp']), $options); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php b/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php index a8c520f..e869c71 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php @@ -25,7 +25,7 @@ public static function getInfo() { * Creates a user and a node, then tests the tokens generated from them. */ function testTokenReplacement() { - $token = \Drupal::token(); + $token_service = \Drupal::token(); // Create the initial objects. $account = $this->drupalCreateUser(); @@ -49,13 +49,13 @@ function testTokenReplacement() { $target .= format_date(REQUEST_TIME, 'short', '', NULL, $language_interface->langcode); // Test that the clear parameter cleans out non-existent tokens. - $result = $token->replace($source, array('node' => $node), array('langcode' => $language_interface->langcode, 'clear' => TRUE)); + $result = $token_service->replace($source, array('node' => $node), array('langcode' => $language_interface->langcode, 'clear' => TRUE)); $result = $this->assertEqual($target, $result, 'Valid tokens replaced while invalid tokens cleared out.'); // Test without using the clear parameter (non-existent token untouched). $target .= '[user:name]'; $target .= '[bogus:token]'; - $result = $token->replace($source, array('node' => $node), array('langcode' => $language_interface->langcode)); + $result = $token_service->replace($source, array('node' => $node), array('langcode' => $language_interface->langcode)); $this->assertEqual($target, $result, 'Valid tokens replaced while invalid tokens ignored.'); // Check that the results of Token::generate are sanitized properly. This @@ -63,21 +63,21 @@ function testTokenReplacement() { // flag is being passed properly through the call stack and being handled // correctly by a 'known' token, [node:title]. $raw_tokens = array('title' => '[node:title]'); - $generated = $token->generate('node', $raw_tokens, array('node' => $node)); + $generated = $token_service->generate('node', $raw_tokens, array('node' => $node)); $this->assertEqual($generated['[node:title]'], check_plain($node->title), 'Token sanitized.'); - $generated = $token->generate('node', $raw_tokens, array('node' => $node), array('sanitize' => FALSE)); + $generated = $token_service->generate('node', $raw_tokens, array('node' => $node), array('sanitize' => FALSE)); $this->assertEqual($generated['[node:title]'], $node->title, 'Unsanitized token generated properly.'); // Test token replacement when the string contains no tokens. - $this->assertEqual($token->replace('No tokens here.'), 'No tokens here.'); + $this->assertEqual($token_service->replace('No tokens here.'), 'No tokens here.'); } /** * Test whether token-replacement works in various contexts. */ function testSystemTokenRecognition() { - $token = \Drupal::token(); + $token_service = \Drupal::token(); $language_interface = language(LANGUAGE_TYPE_INTERFACE); // Generate prefixes and suffixes for the token context. @@ -98,7 +98,7 @@ function testSystemTokenRecognition() { foreach ($tests as $test) { $input = $test['prefix'] . '[site:name]' . $test['suffix']; $expected = $test['prefix'] . 'Drupal' . $test['suffix']; - $output = $token->replace($input, array(), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array(), array('langcode' => $language_interface->langcode)); $this->assertTrue($output == $expected, format_string('Token recognized in string %string', array('%string' => $input))); } } @@ -107,7 +107,7 @@ function testSystemTokenRecognition() { * Tests the generation of all system site information tokens. */ function testSystemSiteTokenReplacement() { - $token = \Drupal::token(); + $token_service = \Drupal::token(); $language_interface = language(LANGUAGE_TYPE_INTERFACE); $url_options = array( 'absolute' => TRUE, @@ -133,7 +133,7 @@ function testSystemSiteTokenReplacement() { $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { - $output = $token->replace($input, array(), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array(), array('langcode' => $language_interface->langcode)); $this->assertEqual($output, $expected, format_string('Sanitized system site information token %token replaced.', array('%token' => $input))); } @@ -142,7 +142,7 @@ function testSystemSiteTokenReplacement() { $tests['[site:slogan]'] = config('system.site')->get('slogan'); foreach ($tests as $input => $expected) { - $output = $token->replace($input, array(), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); + $output = $token_service->replace($input, array(), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized system site information token %token replaced.', array('%token' => $input))); } } @@ -151,7 +151,7 @@ function testSystemSiteTokenReplacement() { * Tests the generation of all system date tokens. */ function testSystemDateTokenReplacement() { - $token = \Drupal::token(); + $token_service = \Drupal::token(); $language_interface = language(LANGUAGE_TYPE_INTERFACE); // Set time to one hour before request. @@ -170,7 +170,7 @@ function testSystemDateTokenReplacement() { $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { - $output = $token->replace($input, array('date' => $date), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array('date' => $date), array('langcode' => $language_interface->langcode)); $this->assertEqual($output, $expected, format_string('Date token %token replaced.', array('%token' => $input))); } } diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 035360b..3fbd873 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -3227,7 +3227,7 @@ function hook_url_outbound_alter(&$path, &$options, $original_path) { * @see hook_tokens_alter() */ function hook_tokens($type, $tokens, array $data = array(), array $options = array()) { - $token = \Drupal::token(); + $token_service = \Drupal::token(); $url_options = array('absolute' => TRUE); if (isset($options['langcode'])) { @@ -3271,13 +3271,13 @@ function hook_tokens($type, $tokens, array $data = array(), array $options = arr } } - if ($author_tokens = $token->findWithPrefix($tokens, 'author')) { + if ($author_tokens = $token_service->findWithPrefix($tokens, 'author')) { $author = user_load($node->uid); - $replacements += $token->generate('user', $author_tokens, array('user' => $author), $options); + $replacements += $token_service->generate('user', $author_tokens, array('user' => $author), $options); } - if ($created_tokens = $token->findWithPrefix($tokens, 'created')) { - $replacements += $token->generate('date', $created_tokens, array('date' => $node->created), $options); + if ($created_tokens = $token_service->findWithPrefix($tokens, 'created')) { + $replacements += $token_service->generate('date', $created_tokens, array('date' => $node->created), $options); } } diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 7f53639..fdf6ef7 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -3591,12 +3591,12 @@ function system_cron() { * Implements hook_mail(). */ function system_mail($key, &$message, $params) { - $token = \Drupal::token(); + $token_service = \Drupal::token(); $context = $params['context']; - $subject = $token->replace($context['subject'], $context); - $body = $token->replace($context['message'], $context); + $subject = $token_service->replace($context['subject'], $context); + $body = $token_service->replace($context['message'], $context); $message['subject'] .= str_replace(array("\r", "\n"), '', $subject); $message['body'][] = $body; diff --git a/core/modules/system/system.tokens.inc b/core/modules/system/system.tokens.inc index b4882f9..78056c5 100644 --- a/core/modules/system/system.tokens.inc +++ b/core/modules/system/system.tokens.inc @@ -129,7 +129,7 @@ function system_token_info() { * Implements hook_tokens(). */ function system_tokens($type, $tokens, array $data = array(), array $options = array()) { - $token = \Drupal::token(); + $token_service = \Drupal::token(); $url_options = array('absolute' => TRUE); if (isset($options['langcode'])) { @@ -207,7 +207,7 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a } } - if ($created_tokens = $token->findWithPrefix($tokens, 'custom')) { + if ($created_tokens = $token_service->findWithPrefix($tokens, 'custom')) { foreach ($created_tokens as $name => $original) { $replacements[$original] = format_date($date, 'custom', $name, NULL, $langcode); } @@ -258,12 +258,12 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a } } - if ($date_tokens = $token->findWithPrefix($tokens, 'timestamp')) { - $replacements += $token->generate('date', $date_tokens, array('date' => $file->timestamp), $options); + if ($date_tokens = $token_service->findWithPrefix($tokens, 'timestamp')) { + $replacements += $token_service->generate('date', $date_tokens, array('date' => $file->timestamp), $options); } - if (($owner_tokens = $token->findWithPrefix($tokens, 'owner')) && $account = user_load($file->uid)) { - $replacements += $token->generate('user', $owner_tokens, array('user' => $account), $options); + if (($owner_tokens = $token_service->findWithPrefix($tokens, 'owner')) && $account = user_load($file->uid)) { + $replacements += $token_service->generate('user', $owner_tokens, array('user' => $account), $options); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php index 60437e1..a792aad 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php @@ -62,7 +62,7 @@ function setUp() { * Creates some terms and a node, then tests the tokens generated from them. */ function testTaxonomyTokenReplacement() { - $token = \Drupal::token(); + $token_service = \Drupal::token(); $language_interface = language(LANGUAGE_TYPE_INTERFACE); // Create two taxonomy terms. @@ -92,7 +92,7 @@ function testTaxonomyTokenReplacement() { $tests['[term:vocabulary:name]'] = check_plain($this->vocabulary->name); foreach ($tests as $input => $expected) { - $output = $token->replace($input, array('term' => $term1), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array('term' => $term1), array('langcode' => $language_interface->langcode)); $this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', array('%token' => $input))); } @@ -112,7 +112,7 @@ function testTaxonomyTokenReplacement() { $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { - $output = $token->replace($input, array('term' => $term2), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array('term' => $term2), array('langcode' => $language_interface->langcode)); $this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', array('%token' => $input))); } @@ -123,7 +123,7 @@ function testTaxonomyTokenReplacement() { $tests['[term:vocabulary:name]'] = $this->vocabulary->name; foreach ($tests as $input => $expected) { - $output = $token->replace($input, array('term' => $term2), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); + $output = $token_service->replace($input, array('term' => $term2), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized taxonomy term token %token replaced.', array('%token' => $input))); } @@ -139,7 +139,7 @@ function testTaxonomyTokenReplacement() { $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { - $output = $token->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->langcode)); $this->assertEqual($output, $expected, format_string('Sanitized taxonomy vocabulary token %token replaced.', array('%token' => $input))); } @@ -148,7 +148,7 @@ function testTaxonomyTokenReplacement() { $tests['[vocabulary:description]'] = $this->vocabulary->description; foreach ($tests as $input => $expected) { - $output = $token->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); + $output = $token_service->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized taxonomy vocabulary token %token replaced.', array('%token' => $input))); } } diff --git a/core/modules/taxonomy/taxonomy.tokens.inc b/core/modules/taxonomy/taxonomy.tokens.inc index 07272e5..82d3a52 100644 --- a/core/modules/taxonomy/taxonomy.tokens.inc +++ b/core/modules/taxonomy/taxonomy.tokens.inc @@ -89,7 +89,7 @@ function taxonomy_token_info() { * Implements hook_tokens(). */ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = array()) { - $token = \Drupal::token(); + $token_service = \Drupal::token(); $replacements = array(); $sanitize = !empty($options['sanitize']); @@ -138,14 +138,14 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = } } - if ($vocabulary_tokens = $token->findWithPrefix($tokens, 'vocabulary')) { + if ($vocabulary_tokens = $token_service->findWithPrefix($tokens, 'vocabulary')) { $vocabulary = taxonomy_vocabulary_load($term->bundle()); - $replacements += $token->generate('vocabulary', $vocabulary_tokens, array('vocabulary' => $vocabulary), $options); + $replacements += $token_service->generate('vocabulary', $vocabulary_tokens, array('vocabulary' => $vocabulary), $options); } - if (($vocabulary_tokens = $token->findWithPrefix($tokens, 'parent')) && $parents = taxonomy_term_load_parents($term->tid)) { + if (($vocabulary_tokens = $token_service->findWithPrefix($tokens, 'parent')) && $parents = taxonomy_term_load_parents($term->tid)) { $parent = array_pop($parents); - $replacements += $token->generate('term', $vocabulary_tokens, array('term' => $parent), $options); + $replacements += $token_service->generate('term', $vocabulary_tokens, array('term' => $parent), $options); } } diff --git a/core/modules/user/lib/Drupal/user/Tests/UserTokenReplaceTest.php b/core/modules/user/lib/Drupal/user/Tests/UserTokenReplaceTest.php index ccb9107..e7fbec7 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserTokenReplaceTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserTokenReplaceTest.php @@ -42,7 +42,7 @@ public function setUp() { * Creates a user, then tests the tokens generated from it. */ function testUserTokenReplacement() { - $token = \Drupal::token(); + $token_service = \Drupal::token(); $language_interface = language(LANGUAGE_TYPE_INTERFACE); $url_options = array( 'absolute' => TRUE, @@ -76,7 +76,7 @@ function testUserTokenReplacement() { $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { - $output = $token->replace($input, array('user' => $account), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array('user' => $account), array('langcode' => $language_interface->langcode)); $this->assertEqual($output, $expected, format_string('Sanitized user token %token replaced.', array('%token' => $input))); } @@ -86,7 +86,7 @@ function testUserTokenReplacement() { $tests['[current-user:name]'] = user_format_name($global_account); foreach ($tests as $input => $expected) { - $output = $token->replace($input, array('user' => $account), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); + $output = $token_service->replace($input, array('user' => $account), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized user token %token replaced.', array('%token' => $input))); } @@ -98,7 +98,7 @@ function testUserTokenReplacement() { // Generate tokens with interface language. $link = url('user', array('absolute' => TRUE)); foreach ($tests as $input => $expected) { - $output = $token->replace($input, array('user' => $account), array('langcode' => $language_interface->langcode, 'callback' => 'user_mail_tokens', 'sanitize' => FALSE, 'clear' => TRUE)); + $output = $token_service->replace($input, array('user' => $account), array('langcode' => $language_interface->langcode, 'callback' => 'user_mail_tokens', 'sanitize' => FALSE, 'clear' => TRUE)); $this->assertTrue(strpos($output, $link) === 0, 'Generated URL is in interface language.'); } @@ -107,7 +107,7 @@ function testUserTokenReplacement() { $account->save(); $link = url('user', array('language' => language_load($account->preferred_langcode), 'absolute' => TRUE)); foreach ($tests as $input => $expected) { - $output = $token->replace($input, array('user' => $account), array('callback' => 'user_mail_tokens', 'sanitize' => FALSE, 'clear' => TRUE)); + $output = $token_service->replace($input, array('user' => $account), array('callback' => 'user_mail_tokens', 'sanitize' => FALSE, 'clear' => TRUE)); $this->assertTrue(strpos($output, $link) === 0, "Generated URL is in the user's preferred language."); } @@ -115,7 +115,7 @@ function testUserTokenReplacement() { $link = url('user', array('language' => language_load('de'), 'absolute' => TRUE)); foreach ($tests as $input => $expected) { foreach (array($user1, $user2) as $account) { - $output = $token->replace($input, array('user' => $account), array('langcode' => 'de', 'callback' => 'user_mail_tokens', 'sanitize' => FALSE, 'clear' => TRUE)); + $output = $token_service->replace($input, array('user' => $account), array('langcode' => 'de', 'callback' => 'user_mail_tokens', 'sanitize' => FALSE, 'clear' => TRUE)); $this->assertTrue(strpos($output, $link) === 0, "Generated URL in in the requested language."); } } diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 5ae4b52..c1df0e0 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1731,7 +1731,7 @@ function user_view_multiple($accounts, $view_mode = 'full', $langcode = NULL) { * Implements hook_mail(). */ function user_mail($key, &$message, $params) { - $token = \Drupal::token(); + $token_service = \Drupal::token(); $langcode = $message['langcode']; $variables = array('user' => $params['account']); @@ -1746,8 +1746,8 @@ function user_mail($key, &$message, $params) { // We do not sanitize the token replacement, since the output of this // replacement is intended for an e-mail message, not a web browser. $token_options = array('langcode' => $langcode, 'callback' => 'user_mail_tokens', 'sanitize' => FALSE, 'clear' => TRUE); - $message['subject'] .= $token->replace($mail_config->get($key . '.subject'), $variables, $token_options); - $message['body'][] = $token->replace($mail_config->get($key . '.body'), $variables, $token_options); + $message['subject'] .= $token_service->replace($mail_config->get($key . '.subject'), $variables, $token_options); + $message['body'][] = $token_service->replace($mail_config->get($key . '.body'), $variables, $token_options); // Return the previous config context. config_context_leave(); diff --git a/core/modules/user/user.tokens.inc b/core/modules/user/user.tokens.inc index f9f3434..1c7f16f 100644 --- a/core/modules/user/user.tokens.inc +++ b/core/modules/user/user.tokens.inc @@ -63,7 +63,7 @@ function user_token_info() { */ function user_tokens($type, $tokens, array $data = array(), array $options = array()) { - $token = \Drupal::token(); + $token_service = \Drupal::token(); $url_options = array('absolute' => TRUE); if (isset($options['langcode'])) { $url_options['language'] = language_load($options['langcode']); @@ -115,18 +115,18 @@ function user_tokens($type, $tokens, array $data = array(), array $options = arr } } - if ($login_tokens = $token->findWithPrefix($tokens, 'last-login')) { - $replacements += $token->generate('date', $login_tokens, array('date' => $account->login), $options); + if ($login_tokens = $token_service->findWithPrefix($tokens, 'last-login')) { + $replacements += $token_service->generate('date', $login_tokens, array('date' => $account->login), $options); } - if ($registered_tokens = $token->findWithPrefix($tokens, 'created')) { - $replacements += $token->generate('date', $registered_tokens, array('date' => $account->created), $options); + if ($registered_tokens = $token_service->findWithPrefix($tokens, 'created')) { + $replacements += $token_service->generate('date', $registered_tokens, array('date' => $account->created), $options); } } if ($type == 'current-user') { $account = user_load($GLOBALS['user']->uid); - $replacements += $token->generate('user', $tokens, array('user' => $account), $options); + $replacements += $token_service->generate('user', $tokens, array('user' => $account), $options); } return $replacements; diff --git a/core/modules/views/lib/Drupal/views/Tests/TokenReplaceTest.php b/core/modules/views/lib/Drupal/views/Tests/TokenReplaceTest.php index be0673f..6bea043 100644 --- a/core/modules/views/lib/Drupal/views/Tests/TokenReplaceTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/TokenReplaceTest.php @@ -38,7 +38,7 @@ function setUp() { * Tests core token replacements generated from a view. */ function testTokenReplacement() { - $token = \Drupal::token(); + $token_handler = \Drupal::token(); $view = views_get_view('test_tokens'); $view->setDisplay('page_1'); $this->executeView($view); @@ -58,7 +58,7 @@ function testTokenReplacement() { ); foreach ($expected as $token => $expected_output) { - $output = $token->replace($token, array('view' => $view)); + $output = $token_handler->replace($token, array('view' => $view)); $this->assertIdentical($output, $expected_output, format_string('Token %token replaced correctly.', array('%token' => $token))); } } diff --git a/core/modules/views/views.tokens.inc b/core/modules/views/views.tokens.inc index 79ab4bc..70c354a 100644 --- a/core/modules/views/views.tokens.inc +++ b/core/modules/views/views.tokens.inc @@ -67,7 +67,7 @@ function views_token_info() { * Implements hook_tokens(). */ function views_tokens($type, $tokens, array $data = array(), array $options = array()) { - $token = \Drupal::token(); + $token_service = \Drupal::token(); $url_options = array('absolute' => TRUE); if (isset($options['language'])) { @@ -129,9 +129,9 @@ function views_tokens($type, $tokens, array $data = array(), array $options = ar } // [view:url:*] nested tokens. This only works if Token module is installed. - if ($url_tokens = $token->findWithPrefix($tokens, 'url')) { + if ($url_tokens = $token_service->findWithPrefix($tokens, 'url')) { if ($path = $view->getUrl()) { - $replacements += $token->generate('url', $url_tokens, array('path' => $path), $options); + $replacements += $token_service->generate('url', $url_tokens, array('path' => $path), $options); } } }