From 94085605ff4e242b4272e388f1cd85646810877d Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Wed, 4 Apr 2012 21:07:34 -0500
Subject: [PATCH 001/230] Issue #1515776: Add an [entity:original] token.

---
 token.test       | 28 ++++++++++++++++++++++++++++
 token.tokens.inc | 24 +++++++++++++++++++++++-
 2 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/token.test b/token.test
index 2f943c6..cc7a6f5 100644
--- a/token.test
+++ b/token.test
@@ -698,6 +698,34 @@ class TokenEntityTestCase extends TokenTestHelper {
     taxonomy_term_save($term);
     return $term;
   }
+
+  /**
+   * Test the [entity:original:*] tokens.
+   */
+  function testEntityOriginal() {
+    $node = $this->drupalCreateNode(array('title' => 'Original title'));
+
+    $tokens = array(
+      'nid' => $node->nid,
+      'title' => 'Original title',
+      'original' => NULL,
+      'original:nid' => NULL,
+    );
+    $this->assertTokens('node', array('node' => $node), $tokens);
+
+    // Emulate the original entity property that would be available from
+    // node_save() and change the title for the node.
+    $node->original = entity_load_unchanged('node', $node->nid);
+    $node->title = 'New title';
+
+    $tokens = array(
+      'nid' => $node->nid,
+      'title' => 'New title',
+      'original' => 'Original title',
+      'original:nid' => $node->nid,
+    );
+    $this->assertTokens('node', array('node' => $node), $tokens);
+  }
 }
 
 /**
diff --git a/token.tokens.inc b/token.tokens.inc
index 13df37f..63b1e81 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -62,6 +62,16 @@ function token_token_info_alter(&$info) {
         'type' => 'url',
       );
     }
+
+    // Add [entity:original] tokens if they do not already exist.
+    if (!isset($info['tokens'][$token_type]['original'])) {
+      $info['tokens'][$token_type]['original'] = array(
+        'name' => t('Original @entity', array('@entity' => drupal_strtolower($entity_info['label']))),
+        'description' => t('The original @entity data if the @entity is being updated or saved.', array('@entity' => drupal_strtolower($entity_info['label']))),
+        'module' => 'token',
+        'type' => $token_type,
+      );
+    }
   }
 
   // Add support for custom date formats.
@@ -762,14 +772,26 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
             $replacements[$original] = url($uri['path'], $uri['options']);
           }
           break;
+
+        case 'original':
+          if (_token_module($type, 'original') == 'token' && !empty($entity->original)) {
+            $label = entity_label($entity_type, $entity->original);
+            $replacements[$original] = $sanitize ? check_plain($label) : $label;
+          }
+          break;
       }
     }
 
-    // Chained token relationships.
+    // [entity:url:*] chained tokens.
     if (($url_tokens = token_find_with_prefix($tokens, 'url')) && _token_module($type, 'url') == 'token') {
       $replacements += token_generate('url', $url_tokens, entity_uri($entity_type, $entity), $options);
     }
 
+    // [entity:original:*] chained tokens.
+    if (($original_tokens = token_find_with_prefix($tokens, 'original')) && _token_module($type, 'original') == 'token' && !empty($entity->original)) {
+      $replacements += token_generate($type, $original_tokens, array($type => $entity->original), $options);
+    }
+
     // Pass through to an generic 'entity' token type generation.
     $entity_data = array(
       'entity_type' => $entity_type,
-- 
1.9.3 (Apple Git-50)


From 873d9d082f20104ba229388d0260687d249ef790 Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Wed, 4 Apr 2012 22:42:17 -0500
Subject: [PATCH 002/230] Issue #1515864: Added a [file:basename] token.

---
 token.test       | 38 ++++++++++++++++++++++++++++++++++++++
 token.tokens.inc | 10 +++++++++-
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/token.test b/token.test
index cc7a6f5..a4e19a7 100644
--- a/token.test
+++ b/token.test
@@ -1012,3 +1012,41 @@ class TokenDateTestCase extends TokenTestHelper {
     $this->assertTokens('date', array('date' => 453859200), $tokens);
   }
 }
+
+class TokenFileTestCase extends TokenTestHelper {
+  public static function getInfo() {
+    return array(
+      'name' => 'File token tests',
+      'description' => 'Test the file tokens.',
+      'group' => 'Token',
+    );
+  }
+
+  function testFileTokens() {
+    // Create a test file object.
+    $file = new stdClass();
+    $file->fid = 1;
+    $file->filename = 'test.png';
+    $file->filesize = 100;
+    $file->uri = 'public://images/test.png';
+    $file->filemime = 'image/png';
+
+    $tokens = array(
+      'basename' => 'test.png',
+      'extension' => 'png',
+      'size-raw' => 100,
+    );
+    $this->assertTokens('file', array('file' => $file), $tokens);
+
+    // Test a file with no extension and a fake name.
+    $file->filename = 'Test PNG image';
+    $file->uri = 'public://images/test';
+
+    $tokens = array(
+      'basename' => 'test',
+      'extension' => '',
+      'size-raw' => 100,
+    );
+    $this->assertTokens('file', array('file' => $file), $tokens);
+  }
+}
diff --git a/token.tokens.inc b/token.tokens.inc
index 63b1e81..4b4daa1 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -166,6 +166,10 @@ function token_token_info() {
   }
 
   // File tokens.
+  $info['tokens']['file']['basename'] = array(
+    'name' => t('Base name'),
+    'description' => t('The base name of the file.'),
+  );
   $info['tokens']['file']['extension'] = array(
     'name' => t('Extension'),
     'description' => t('The extension of the file.'),
@@ -535,8 +539,12 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
     foreach ($tokens as $name => $original) {
       switch ($name) {
+        case 'basename':
+          $basename = pathinfo($file->uri, PATHINFO_BASENAME);
+          $replacements[$original] = $sanitize ? check_plain($basename) : $basename;
+          break;
         case 'extension':
-          $extension = pathinfo($file->filename, PATHINFO_EXTENSION);
+          $extension = pathinfo($file->uri, PATHINFO_EXTENSION);
           $replacements[$original] = $sanitize ? check_plain($extension) : $extension;
           break;
         case 'size-raw':
-- 
1.9.3 (Apple Git-50)


From 34b61423535ccdf0ad00bd55afc1a4540df8db70 Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Wed, 4 Apr 2012 23:57:09 -0500
Subject: [PATCH 003/230] Issue #1508404 by arpieb, jec006: Fixed token fields
 not rendered properly if replacement called from inside field_attach_view()
 and the fields' display were set to hidden.

---
 token.tokens.inc | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/token.tokens.inc b/token.tokens.inc
index 4b4daa1..c1cd4ad 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -1398,9 +1398,14 @@ function field_tokens($type, $tokens, array $data = array(), array $options = ar
   // Entity tokens.
   if ($type == 'entity' && !empty($data['entity_type']) && !empty($data['entity']) && !empty($data['token_type'])) {
     $entity_type = $data['entity_type'];
+
     // The field API does weird stuff to the entity, so let's clone it.
     $entity = clone $data['entity'];
 
+    // Reset the prepared view flag in case token generation is called from
+    // inside field_attach_view().
+    unset($entity->_field_view_prepared);
+
     list(, , $bundle) = entity_extract_ids($entity_type, $entity);
     $fields = field_info_instances($entity_type, $bundle);
 
-- 
1.9.3 (Apple Git-50)


From f306b408d6b8ca378ae79c45c8724148686deed0 Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Thu, 5 Apr 2012 17:35:23 -0500
Subject: [PATCH 004/230] Issue #1515978: Added support for token replacement
 in block titles.

---
 token.module | 28 ++++++++++++++++++++++++++++
 token.test   | 53 +++++++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 73 insertions(+), 8 deletions(-)

diff --git a/token.module b/token.module
index bd366da..eaeb826 100644
--- a/token.module
+++ b/token.module
@@ -197,6 +197,34 @@ function token_form_alter(&$form, $form_state, $form_id) {
 }
 
 /**
+ * Implements hook_block_view_alter().
+ */
+function token_block_view_alter(&$data, $block) {
+  if (!empty($block->title) && $block->title != '<none>') {
+    // Perform unsanitized token replacement since _block_render_blocks() will
+    // call check_plain() on $block->title.
+    $block->title = token_replace($block->title, array(), array('sanitize' => FALSE));
+  }
+}
+
+/**
+ * Implements hook_form_FORM_ID_alter().
+ */
+function token_form_block_add_block_form_alter(&$form, $form_state) {
+  token_form_block_admin_configure_alter($form, $form_state);
+}
+
+/**
+ * Implements hook_form_FORM_ID_alter().
+ */
+function token_form_block_admin_configure_alter(&$form, $form_state) {
+  $form['settings']['title']['#description'] .= ' ' . t('This field supports tokens.');
+  // @todo Figure out why this token validation does not seem to be working here.
+  $form['settings']['title']['#element_validate'][] = 'token_element_validate';
+  $form['settings']['title']['#token_types'] = array();
+}
+
+/**
  * Implements hook_field_info_alter().
  */
 function token_field_info_alter(&$info) {
diff --git a/token.test b/token.test
index a4e19a7..ee3db9f 100644
--- a/token.test
+++ b/token.test
@@ -11,7 +11,7 @@
 class TokenTestHelper extends DrupalWebTestCase {
   protected $profile = 'testing';
 
-  function setUp($modules = array()) {
+  public function setUp($modules = array()) {
     $modules[] = 'path';
     $modules[] = 'token';
     $modules[] = 'token_test';
@@ -210,7 +210,7 @@ class TokenURLTestCase extends TokenTestHelper {
     );
   }
 
-  function setUp($modules = array()) {
+  public function setUp($modules = array()) {
     parent::setUp($modules);
     $this->saveAlias('node/1', 'first-node');
   }
@@ -247,7 +247,7 @@ class TokenCommentTestCase extends TokenTestHelper {
     );
   }
 
-  function setUp($modules = array()) {
+  public function setUp($modules = array()) {
     $modules[] = 'comment';
     parent::setUp($modules);
   }
@@ -368,7 +368,7 @@ class TokenMenuTestCase extends TokenTestHelper {
     );
   }
 
-  function setUp($modules = array()) {
+  public function setUp($modules = array()) {
     $modules[] = 'menu';
     parent::setUp($modules);
   }
@@ -473,7 +473,7 @@ class TokenTaxonomyTestCase extends TokenTestHelper {
     );
   }
 
-  function setUp($modules = array()) {
+  public function setUp($modules = array()) {
     $modules[] = 'taxonomy';
     parent::setUp($modules);
 
@@ -578,7 +578,7 @@ class TokenUserTestCase extends TokenTestHelper {
     );
   }
 
-  function setUp($modules = array()) {
+  public function setUp($modules = array()) {
     parent::setUp($modules);
 
     // Enable user pictures.
@@ -658,7 +658,7 @@ class TokenEntityTestCase extends TokenTestHelper {
     );
   }
 
-  function setUp($modules = array()) {
+  public function setUp($modules = array()) {
     $modules[] = 'taxonomy';
     parent::setUp($modules);
 
@@ -742,7 +742,7 @@ class TokenProfileTestCase extends TokenTestHelper {
     );
   }
 
-  function setUp($modules = array()) {
+  public function setUp($modules = array()) {
     $modules[] = 'profile';
     parent::setUp($modules);
     $this->account = $this->drupalCreateUser(array('administer users'));
@@ -1050,3 +1050,40 @@ class TokenFileTestCase extends TokenTestHelper {
     $this->assertTokens('file', array('file' => $file), $tokens);
   }
 }
+
+class TokenBlockTestCase extends TokenTestHelper {
+  //protected $profile = 'standard';
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Block token tests',
+      'description' => 'Test the block title token replacement.',
+      'group' => 'Token',
+    );
+  }
+
+  public function setUp($modules = array()) {
+    $modules[] = 'block';
+    parent::setUp($modules);
+
+    $this->admin_user = $this->drupalCreateUser(array('access content', 'administer blocks'));
+    $this->drupalLogin($this->admin_user);
+  }
+
+  public function testBlockTitleTokens() {
+    $edit['title'] = '[current-page:title] block title';
+    $edit['info'] = 'Test token title block';
+    $edit['body[value]'] = 'This is the test token title block.';
+    $edit['regions[bartik]'] = 'sidebar_first';
+    $this->drupalPost('admin/structure/block/add', $edit, 'Save block');
+
+    $this->drupalGet('node');
+    $this->assertText('Welcome to ' . variable_get('site_name', 'Drupal') . ' block title');
+
+    // Ensure that tokens are not double-escaped when output as a block title.
+    $node = $this->drupalCreateNode(array('title' => "Site's first node"));
+    $this->drupalGet('node/' . $node->nid);
+    // The apostraphe should only be escaped once via check_plain().
+    $this->assertRaw("Site&#039;s first node block title");
+  }
+}
-- 
1.9.3 (Apple Git-50)


From 7afd95cb37d4f9089f18b78dbee07e9553cfefbb Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Thu, 5 Apr 2012 19:00:43 -0500
Subject: [PATCH 005/230] Issue #1512934: Added workaround for core bug
 #1477932 in which the cache_token table does not exist but
 drupal_flush_all_caches() is called.

---
 token.module | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/token.module b/token.module
index eaeb826..4047f6f 100644
--- a/token.module
+++ b/token.module
@@ -293,7 +293,9 @@ function token_field_delete_instance($instance) {
  * Clear token caches and static variables.
  */
 function token_clear_cache() {
-  cache_clear_all('*', 'cache_token', TRUE);
+  if (db_table_exists('cache_token')) {
+    cache_clear_all('*', 'cache_token', TRUE);
+  }
   drupal_static_reset('token_get_info');
   drupal_static_reset('token_get_global_token_types');
   drupal_static_reset('token_get_entity_mapping');
@@ -397,7 +399,9 @@ function token_module_implements_alter(&$implementations, $hook) {
  * Implements hook_flush_caches().
  */
 function token_flush_caches() {
-  return array('cache_token');
+  if (db_table_exists('cache_token')) {
+    return array('cache_token');
+  }
 }
 
 /**
-- 
1.9.3 (Apple Git-50)


From 27f65a72a9bbe5dab04bdd903e744a6af627d356 Mon Sep 17 00:00:00 2001
From: megachriz <megachriz@654114.no-reply.drupal.org>
Date: Thu, 5 Apr 2012 19:29:29 -0500
Subject: [PATCH 006/230] Issue #1438512: Fixed extra closing brace in
 token_update_token_text().

---
 token.install | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/token.install b/token.install
index 5ac9651..c2b57fd 100644
--- a/token.install
+++ b/token.install
@@ -220,11 +220,11 @@ function _token_upgrade_token_date_list($old_token, $new_token) {
  * @return
  *   A string with the tokens upgraded
  *
- * @see _token_upgrade_token_list();
+ * @see _token_upgrade_token_list()
  */
 function token_update_token_text($text, $updates = array(), $leading = '[', $trailing = ']') {
   $updates += _token_upgrade_token_list();
-  $regex = '/' . preg_quote($leading, '/') . '([^\s]*)' . preg_quote($trailing, '/') . ']/';
+  $regex = '/' . preg_quote($leading, '/') . '([^\s]*)' . preg_quote($trailing, '/') . '/';
   preg_match_all($regex, $text, $matches);
 
   foreach ($matches[1] as $index => $old_token) {
-- 
1.9.3 (Apple Git-50)


From c3d836f7c1f339ce71e615d28b905138ba5f0d67 Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Thu, 5 Apr 2012 19:56:20 -0500
Subject: [PATCH 007/230] Fix some coding standard violations.

---
 tests/token_test.module |  5 +++++
 token.module            | 19 ++++++++++++++++---
 token.test              |  2 --
 token.tokens.inc        | 10 +++++-----
 4 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/tests/token_test.module b/tests/token_test.module
index 5c8bab0..3174cb6 100644
--- a/tests/token_test.module
+++ b/tests/token_test.module
@@ -1,6 +1,11 @@
 <?php
 
 /**
+ * @file
+ * Helper module for token tests.
+ */
+
+/**
  * Implements hook_exit().
  */
 function token_test_exit() {
diff --git a/token.module b/token.module
index 4047f6f..0f8c2b2 100644
--- a/token.module
+++ b/token.module
@@ -1,6 +1,11 @@
 <?php
 
 /**
+ * @file
+ * Enhances the token API in core: adds a browseable UI, missing tokens, etc.
+ */
+
+/**
  * The maximum depth for token tree recursion.
  */
 define('TOKEN_MAX_DEPTH', 9);
@@ -480,8 +485,16 @@ function token_get_info($token_type = NULL, $token = NULL) {
 }
 
 /**
- * Return the module responsible for a token if defined in
- * $info['tokens']['type']['module'].
+ * Return the module responsible for a token.
+ *
+ * @param string $type
+ *   The token type.
+ * @param string $name
+ *   The token name.
+ *
+ * @return mixed
+ *   The value of $info['tokens'][$type][$name]['module'] from token_get_info(),
+ *   or NULL if the value does not exist.
  */
 function _token_module($type, $name) {
   $token_info = token_get_info($type, $name);
@@ -857,7 +870,7 @@ function token_flatten_tree($tree) {
     $result[$token] = $token_info;
     if (isset($token_info['children']) && is_array($token_info['children'])) {
       $result += token_flatten_tree($token_info['children']);
-      //unset($result[$token]['children']);
+      // unset($result[$token]['children']);
     }
   }
   return $result;
diff --git a/token.test b/token.test
index ee3db9f..1cd2740 100644
--- a/token.test
+++ b/token.test
@@ -1052,8 +1052,6 @@ class TokenFileTestCase extends TokenTestHelper {
 }
 
 class TokenBlockTestCase extends TokenTestHelper {
-  //protected $profile = 'standard';
-
   public static function getInfo() {
     return array(
       'name' => 'Block token tests',
diff --git a/token.tokens.inc b/token.tokens.inc
index c1cd4ad..aae319a 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -133,7 +133,7 @@ function token_token_info() {
   $info['tokens']['content-type']['edit-url'] = array(
     'name' => t('Edit URL'),
     'description' => t("The URL of the content type's edit page."),
-    //'type' => 'url',
+    // 'type' => 'url',
   );
 
   // Taxonomy term and vocabulary tokens.
@@ -141,7 +141,7 @@ function token_token_info() {
     $info['tokens']['term']['edit-url'] = array(
       'name' => t('Edit URL'),
       'description' => t("The URL of the taxonomy term's edit page."),
-      //'type' => 'url',
+      // 'type' => 'url',
     );
     $info['tokens']['term']['parents'] = array(
       'name' => t('Parents'),
@@ -161,7 +161,7 @@ function token_token_info() {
     $info['tokens']['vocabulary']['edit-url'] = array(
       'name' => t('Edit URL'),
       'description' => t("The URL of the vocabulary's edit page."),
-      //'type' => 'url',
+      // 'type' => 'url',
     );
   }
 
@@ -185,13 +185,13 @@ function token_token_info() {
     'name' => t('Account cancellation URL'),
     'description' => t('The URL of the confirm delete page for the user account.'),
     'restricted' => TRUE,
-    //'type' => 'url',
+    // 'type' => 'url',
   );
   $info['tokens']['user']['one-time-login-url'] = array(
     'name' => t('One-time login URL'),
     'description' => t('The URL of the one-time login page for the user account.'),
     'restricted' => TRUE,
-    //'type' => 'url',
+    // 'type' => 'url',
   );
   if (variable_get('user_pictures', 0)) {
     $info['tokens']['user']['picture'] = array(
-- 
1.9.3 (Apple Git-50)


From 28358931a0b38a544d85d665b3e6c89a364a9fa6 Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Thu, 26 Apr 2012 21:43:04 -0500
Subject: [PATCH 008/230] Add default token formatters for the core list field
 types.

---
 token.module | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/token.module b/token.module
index 0f8c2b2..8a84ef5 100644
--- a/token.module
+++ b/token.module
@@ -230,6 +230,15 @@ function token_form_block_admin_configure_alter(&$form, $form_state) {
 }
 
 /**
+ * Implements hook_widget_form_alter().
+ */
+function token_field_widget_form_alter(&$element, &$form_state, $context) {
+  if (!empty($element['#description']) && is_string($element['#description'])) {
+    $element['#description'] = token_replace($element['#description']);
+  }
+}
+
+/**
  * Implements hook_field_info_alter().
  */
 function token_field_info_alter(&$info) {
@@ -243,6 +252,10 @@ function token_field_info_alter(&$info) {
     'text' => 'text_default',
     'text_long' => 'text_default',
     'text_with_summary' => 'text_default',
+    'list_integer' => 'list_default',
+    'list_float' => 'list_default',
+    'list_text' => 'list_default',
+    'list_boolean' => 'list_default',
   );
   foreach ($defaults as $field_type => $default_token_formatter) {
     if (isset($info[$field_type])) {
@@ -691,7 +704,11 @@ function token_form_field_ui_field_edit_form_alter(&$form, $form_state) {
       '#token_types' => array(),
       '#weight' => $form['instance']['settings']['file_directory']['#weight'] + 0.5,
     );
+    $form['instance']['settings']['file_directory']['#description'] .= ' ' . t('This field supports tokens.');
   }
+
+  // Note that the description is tokenized via token_field_widget_form_alter().
+  $form['instance']['description']['#description'] .= '<br />' . t('This field supports tokens.');
 }
 
 /**
-- 
1.9.3 (Apple Git-50)


From eb99aec6241b9801db0d9e9809f798754599fbfd Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Wed, 9 May 2012 09:47:52 -0500
Subject: [PATCH 009/230] Fix testing failure in TokenUserTestCase with user
 pictures.

---
 token.test | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.test b/token.test
index 1cd2740..9482ecf 100644
--- a/token.test
+++ b/token.test
@@ -583,7 +583,7 @@ class TokenUserTestCase extends TokenTestHelper {
 
     // Enable user pictures.
     variable_set('user_pictures', 1);
-    variable_set('user_picture_file_size', 0);
+    variable_set('user_picture_file_size', '');
 
     // Set up the pictures directory.
     $picture_path = file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures');
-- 
1.9.3 (Apple Git-50)


From 02dfbd40315dc14727d13d7fca94e3eba15e251c Mon Sep 17 00:00:00 2001
From: auth <auth@378489.no-reply.drupal.org>
Date: Wed, 9 May 2012 09:59:23 -0500
Subject: [PATCH 010/230] Issue #1557766: The list token types in entity API
 break the token browser because HTML characters weren't converted to dashes.

---
 token.pages.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.pages.inc b/token.pages.inc
index c111519..d2f06e9 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -163,7 +163,7 @@ function _token_token_tree_format_row($token, array $token_info, $is_group = FAL
  * @see drupal_clean_css_identifier()
  */
 function _token_clean_css_identifier($id) {
-  static $replacements = array(' ' => '-', '_' => '-', '/' => '-', '[' => '-', ']' => '', ':' => '--', '?' => '');
+  static $replacements = array(' ' => '-', '_' => '-', '/' => '-', '[' => '-', ']' => '', ':' => '--', '?' => '', '<' => '-', '>' => '-');
   return 'token-' . rtrim(strtr(trim($id, '[]'), $replacements), '-');
 }
 
-- 
1.9.3 (Apple Git-50)


From a2c55a9944d3765041cba311a0bd745178f9aa62 Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Tue, 15 May 2012 15:50:49 -0500
Subject: [PATCH 011/230] Fixing a couple minor bugs with filtering field
 descriptions, altering field forms, and not using _token_module() in
 field_tokens().

---
 token.module     |  6 +++++-
 token.tokens.inc | 11 +++--------
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/token.module b/token.module
index 8a84ef5..56e3ceb 100644
--- a/token.module
+++ b/token.module
@@ -234,7 +234,7 @@ function token_form_block_admin_configure_alter(&$form, $form_state) {
  */
 function token_field_widget_form_alter(&$element, &$form_state, $context) {
   if (!empty($element['#description']) && is_string($element['#description'])) {
-    $element['#description'] = token_replace($element['#description']);
+    $element['#description'] = filter_xss_admin(token_replace($element['#description']));
   }
 }
 
@@ -695,6 +695,10 @@ function token_element_validate_token_context(&$element, &$form_state) {
  * Implements hook_form_FORM_ID_alter().
  */
 function token_form_field_ui_field_edit_form_alter(&$form, $form_state) {
+  if (!isset($form['instance'])) {
+    return;
+  }
+
   if (($form['#field']['type'] == 'file' || $form['#field']['type'] == 'image') && isset($form['instance']['settings']['file_directory']) && !module_exists('filefield_paths')) {
     // GAH! We can only support global tokens in the upload file directory path.
     $form['instance']['settings']['file_directory']['#element_validate'][] = 'token_element_validate';
diff --git a/token.tokens.inc b/token.tokens.inc
index aae319a..3dc2d3b 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -1415,16 +1415,11 @@ function field_tokens($type, $tokens, array $data = array(), array $options = ar
         continue;
       }
 
-      // Replace the [entity:field-name] token.
-      if (isset($tokens[$field_name])) {
+      // Replace the [entity:field-name] token only if token module added this
+      // token.
+      if (isset($tokens[$field_name]) && _token_module($data['token_type'], $field_name) == 'token') {
         $original = $tokens[$field_name];
 
-        // Assert that this field was added by token.module.
-        $token_info = token_get_info($data['token_type'], $field_name);
-        if (!isset($token_info['module']) || $token_info['module'] != 'token') {
-          continue;
-        }
-
         $field_output = field_view_field($entity_type, $entity, $field_name, 'token', $langcode);
         $field_output['#token_options'] = $options;
         $field_output['#pre_render'][] = 'token_pre_render_field_token';
-- 
1.9.3 (Apple Git-50)


From f9016e7e9f3d101bff2a5b037e93dec43c490458 Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Tue, 24 Jul 2012 17:56:53 -0500
Subject: [PATCH 012/230] Issue #1515978: Fixed token validation was skipped on
 block titles.

---
 token.module |  2 +-
 token.test   | 10 ++++++++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/token.module b/token.module
index 56e3ceb..9ff59f0 100644
--- a/token.module
+++ b/token.module
@@ -674,7 +674,7 @@ function token_element_validate(&$element, &$form_state) {
   }
 
   // Check if the field defines specific token types.
-  if (!empty($element['#token_types'])) {
+  if (isset($element['#token_types'])) {
     $invalid_tokens = token_get_invalid_tokens_by_context($tokens, $element['#token_types']);
     if ($invalid_tokens) {
       form_error($element, t('The %element-title is using the following invalid tokens: @invalid-tokens.', array('%element-title' => $title, '@invalid-tokens' => implode(', ', $invalid_tokens))));
diff --git a/token.test b/token.test
index 9482ecf..b7e9582 100644
--- a/token.test
+++ b/token.test
@@ -1069,11 +1069,17 @@ class TokenBlockTestCase extends TokenTestHelper {
   }
 
   public function testBlockTitleTokens() {
-    $edit['title'] = '[current-page:title] block title';
+    $edit['title'] = '[user:name]';
     $edit['info'] = 'Test token title block';
     $edit['body[value]'] = 'This is the test token title block.';
-    $edit['regions[bartik]'] = 'sidebar_first';
     $this->drupalPost('admin/structure/block/add', $edit, 'Save block');
+    // Ensure token validation is working on the block.
+    $this->assertText('The Block title is using the following invalid tokens: [user:name].');
+
+    // Create the block for real now with a valid title.
+    $edit['title'] = '[current-page:title] block title';
+    $edit['regions[bartik]'] = 'sidebar_first';
+    $this->drupalPost(NULL, $edit, 'Save block');
 
     $this->drupalGet('node');
     $this->assertText('Welcome to ' . variable_get('site_name', 'Drupal') . ' block title');
-- 
1.9.3 (Apple Git-50)


From fb05b225ee0c93835f4a998996a94d53594b51e8 Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Sat, 14 Jul 2012 14:12:08 -0500
Subject: [PATCH 013/230] Issue #1684984: Added support for the token tree to
 be output in an AJAX dialog using #theme => token_tree_link.

---
 token.css       |  4 ++++
 token.js        | 26 ++++++++++++++++++++++++++
 token.module    | 54 +++++++++++++++++++++++++++++++++++++++++++++++-------
 token.pages.inc | 35 +++++++++++++++++++++++++++++++++++
 4 files changed, 112 insertions(+), 7 deletions(-)

diff --git a/token.css b/token.css
index 5c3b3ba..5432f0f 100644
--- a/token.css
+++ b/token.css
@@ -4,6 +4,10 @@
   margin-left: 19px;
 }
 
+.ui-dialog-content .token-tree {
+  margin-left: 0;
+}
+
 .token-tree td, .token-tree th {
   padding-top: 0;
   padding-bottom: 0;
diff --git a/token.js b/token.js
index 59715f4..88a75c1 100644
--- a/token.js
+++ b/token.js
@@ -9,6 +9,32 @@ Drupal.behaviors.tokenTree = {
   }
 };
 
+Drupal.behaviors.tokenDialog = {
+  attach: function (context, settings) {
+    $('a.token-dialog', context).once('token-dialog').click(function() {
+      var url = $(this).attr('href');
+      var dialog = $('<div style="display: none" class="loading">' + Drupal.t('Loading token browser...') + '</div>').appendTo('body');
+      dialog.dialog({
+        title: $(this).attr('title') || Drupal.t('Available tokens'),
+        width: 700,
+        close: function(event, ui) {
+          dialog.remove();
+        }
+      });
+      // Load the token tree using AJAX.
+      dialog.load(
+        url,
+        {},
+        function (responseText, textStatus, XMLHttpRequest) {
+          dialog.removeClass('loading');
+        }
+      );
+      // Prevent browser from following the link.
+      return false;
+    });
+  }
+}
+
 Drupal.behaviors.tokenInsert = {
   attach: function (context, settings) {
     // Keep track of which textfield was last selected/focused.
diff --git a/token.module b/token.module
index 9ff59f0..509a4da 100644
--- a/token.module
+++ b/token.module
@@ -73,6 +73,13 @@ function token_menu() {
     'file' => 'token.pages.inc',
   );*/
 
+  $items['token/tree'] = array(
+    'page callback' => 'token_page_output_tree',
+    'access callback' => TRUE,
+    'type' => MENU_CALLBACK,
+    'file' => 'token.pages.inc',
+  );
+
   // Devel token pages.
   if (module_exists('devel')) {
     $items['node/%node/devel/token'] = array(
@@ -146,16 +153,38 @@ function token_type_load($token_type) {
  * Implements hook_theme().
  */
 function token_theme() {
-  return array(
-    'tree_table' => array(
-      'variables' => array('header' => array(), 'rows' => array(), 'attributes' => array(), 'empty' => '', 'caption' => ''),
-      'file' => 'token.pages.inc',
+  $info['tree_table'] = array(
+    'variables' => array(
+      'header' => array(),
+      'rows' => array(),
+      'attributes' => array(),
+      'empty' => '',
+      'caption' => '',
     ),
-    'token_tree' => array(
-      'variables' => array('token_types' => array(), 'global_types' => TRUE, 'click_insert' => TRUE, 'show_restricted' => FALSE, 'recursion_limit' => 3),
-      'file' => 'token.pages.inc',
+    'file' => 'token.pages.inc',
+  );
+  $info['token_tree'] = array(
+    'variables' => array(
+      'token_types' => array(),
+      'global_types' => TRUE,
+      'click_insert' => TRUE,
+      'show_restricted' => FALSE,
+      'recursion_limit' => 3,
+      'dialog' => FALSE,
     ),
+    'file' => 'token.pages.inc',
   );
+  $info['token_tree_link'] = array(
+    'variables' => array(
+      'text' => NULL,
+      'options' => array(),
+      'dialog' => TRUE,
+    ),
+    'file' => 'token.pages.inc',
+  );
+  $info['token_tree_link']['variables'] += $info['token_tree']['variables'];
+
+  return $info;
 }
 
 /**
@@ -175,6 +204,17 @@ function token_library() {
     ),
   );
 
+  $libraries['dialog'] = array(
+    'title' => 'Token dialog',
+    'version' => '1.0',
+    'js' => array(
+      drupal_get_path('module', 'token') . '/token.js' => array(),
+    ),
+    'dependencies' => array(
+      array('system', 'ui.dialog'),
+    ),
+  );
+
   return $libraries;
 }
 
diff --git a/token.pages.inc b/token.pages.inc
index d2f06e9..264a14a 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -6,6 +6,37 @@
  */
 
 /**
+ * Theme a link to a token tree either as a regular link or a dialog.
+ */
+function theme_token_tree_link($variables) {
+  if (empty($variables['text'])) {
+    $variables['text'] = t('Browse available tokens.');
+  }
+
+  if (!empty($variables['dialog'])) {
+    drupal_add_library('token', 'dialog');
+    $variables['options']['attributes']['class'][] = 'token-dialog';
+  }
+
+  $info = token_theme();
+  $variables['options']['query']['token_tree'] = array_intersect_key($variables, $info['token_tree']['variables']);
+  $variables['options']['attributes'] + array('target' => '_blank');
+
+  return l($variables['text'], 'token/tree', $variables['options']);
+}
+
+/**
+ * Page callback to output a token tree as an empty page.
+ */
+function token_page_output_tree() {
+  $options = isset($_GET['token_tree']) ? $_GET['token_tree'] : array();
+  $output = theme('token_tree', array('dialog' => FALSE) + $options);
+  print '<html><head><title></title>' . drupal_get_css() . drupal_get_js() . '</head>';
+  print '<body class="token-tree">' . $output . '</body></html>';
+  drupal_exit();
+}
+
+/**
  * Theme a tree table.
  *
  * @ingroup themeable
@@ -32,6 +63,10 @@ function theme_tree_table($variables) {
  * @ingroup themeable
  */
 function theme_token_tree($variables) {
+  if (!empty($variables['dialog'])) {
+    return theme_token_tree_link($variables);
+  }
+
   $token_types = $variables['token_types'];
   $info = token_get_info();
 
-- 
1.9.3 (Apple Git-50)


From c1f18d23699feb9201cab19ddaa2bcb8dcde4f45 Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Thu, 30 Aug 2012 11:56:24 -0500
Subject: [PATCH 014/230] Issue #1764024 by Dave Reid, klausi: Added some
 access restrictions to the token/tree page callback to ensure they cannot
 just be viewed without context.

---
 token.module    |  1 -
 token.pages.inc | 32 +++++++++++++++++++++++++++++---
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/token.module b/token.module
index 509a4da..9aa6fca 100644
--- a/token.module
+++ b/token.module
@@ -182,7 +182,6 @@ function token_theme() {
     ),
     'file' => 'token.pages.inc',
   );
-  $info['token_tree_link']['variables'] += $info['token_tree']['variables'];
 
   return $info;
 }
diff --git a/token.pages.inc b/token.pages.inc
index 264a14a..4e281af 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -19,7 +19,22 @@ function theme_token_tree_link($variables) {
   }
 
   $info = token_theme();
-  $variables['options']['query']['token_tree'] = array_intersect_key($variables, $info['token_tree']['variables']);
+  $variables['options']['query']['options'] = array_intersect_key($variables, $info['token_tree']['variables']);
+
+  // We should never pass the dialog option to theme_token_tree(). It is only
+  // used for this function.
+  unset($variables['options']['query']['options']['dialog']);
+
+  // Add a security token so that the tree page should only work when used
+  // when the dialog link is output with theme('token_tree_link').
+  $variables['options']['query']['token'] = drupal_get_token('token-tree:' . serialize($variables['options']['query']['options']));
+
+  // Because PHP converts query strings with arrays into a different syntax on
+  // the next request, the options have to be encoded with JSON in the query
+  // string so that we can reliably decode it for token comparison.
+  $variables['options']['query']['options'] = drupal_json_encode($variables['options']['query']['options']);
+
+  // Set the token tree to open in a separate window.
   $variables['options']['attributes'] + array('target' => '_blank');
 
   return l($variables['text'], 'token/tree', $variables['options']);
@@ -29,8 +44,19 @@ function theme_token_tree_link($variables) {
  * Page callback to output a token tree as an empty page.
  */
 function token_page_output_tree() {
-  $options = isset($_GET['token_tree']) ? $_GET['token_tree'] : array();
-  $output = theme('token_tree', array('dialog' => FALSE) + $options);
+  $options = isset($_GET['options']) ? drupal_json_decode($_GET['options']) : array();
+
+  // Check the token against the serialized options to prevent random access to
+  // the token browser page.
+  if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], 'token-tree:' . serialize($options))) {
+    return MENU_ACCESS_DENIED;
+  }
+
+  // Force the dialog option to be false so we're not creating a dialog within
+  // a dialog.
+  $options['dialog'] = FALSE;
+
+  $output = theme('token_tree', array($options));
   print '<html><head><title></title>' . drupal_get_css() . drupal_get_js() . '</head>';
   print '<body class="token-tree">' . $output . '</body></html>';
   drupal_exit();
-- 
1.9.3 (Apple Git-50)


From 3df64ac42202c2295bfae262a696db68a0ac40f9 Mon Sep 17 00:00:00 2001
From: nick_schuch <nick_schuch@1412036.no-reply.drupal.org>
Date: Thu, 30 Aug 2012 11:59:58 -0500
Subject: [PATCH 015/230] Issue #1743472: Fixed misspelling of implements in
 token_help() documentation.

---
 token.module | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.module b/token.module
index 9aa6fca..110a729 100644
--- a/token.module
+++ b/token.module
@@ -11,7 +11,7 @@
 define('TOKEN_MAX_DEPTH', 9);
 
 /**
- * Impelements hook_help().
+ * Implements hook_help().
  */
 function token_help($path, $arg) {
   if ($path == 'admin/help#token') {
-- 
1.9.3 (Apple Git-50)


From 2ee0d9de6a1e3dc0b6219dcd1329dba4424b9f00 Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Tue, 4 Sep 2012 17:26:57 -0500
Subject: [PATCH 016/230] Fixed token_field_display_alter() should attempt to
 use the default field formatter in addition to the default token formatter,
 rather than not display a field token value.

---
 token.module | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/token.module b/token.module
index 110a729..71a7488 100644
--- a/token.module
+++ b/token.module
@@ -313,14 +313,17 @@ function token_field_display_alter(&$display, $context) {
     // use the default token formatter.
     if (empty($view_mode_settings[$context['view_mode']]['custom_settings'])) {
       $field_type_info = field_info_field_types($context['field']['type']);
-      if (!empty($field_type_info['default_token_formatter'])) {
-        $display['type'] = $field_type_info['default_token_formatter'];
 
-        $formatter_info = field_info_formatter_types($display['type']);
-        $display['settings'] = isset($formatter_info['settings']) ? $formatter_info['settings'] : array();
-        $display['settings']['label'] = 'hidden';
-        $display['module'] = $formatter_info['module'];
-      }
+      // If the field has specified a specific formatter to be used by default
+      // with tokens, use that, otherwise use the default formatter.
+      $formatter = !empty($field_type_info['default_token_formatter']) ? $field_type_info['default_token_formatter'] : $field_type_info['default_formatter'];
+
+      // Now that we have a formatter, fill in all the settings.
+      $display['type'] = $formatter;
+      $formatter_info = field_info_formatter_types($formatter);
+      $display['settings'] = isset($formatter_info['settings']) ? $formatter_info['settings'] : array();
+      $display['settings']['label'] = 'hidden';
+      $display['module'] = $formatter_info['module'];
     }
   }
 }
-- 
1.9.3 (Apple Git-50)


From e130ea57eba82efae70112febbd87e314d9f43c5 Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Wed, 12 Sep 2012 09:45:08 -0500
Subject: [PATCH 017/230] Issue #1782374 by pounard, Dave Reid: Fixed
 token_module_implements_alter() should set FALSE instead of TRUE for the
 group value.

---
 token.module | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.module b/token.module
index 71a7488..21831e9 100644
--- a/token.module
+++ b/token.module
@@ -445,7 +445,7 @@ function token_module_implements_alter(&$implementations, $hook) {
   if ($hook == 'tokens' || $hook == 'token_info') {
     foreach (_token_core_supported_modules() as $module) {
       if (module_exists($module)) {
-        $implementations[$module] = TRUE;
+        $implementations[$module] = FALSE;
       }
     }
     // Move token.module to get included first since it is responsible for
-- 
1.9.3 (Apple Git-50)


From 963569d1f28b2627ba7511b4cadd7fed40bde75f Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Wed, 12 Sep 2012 11:09:04 -0500
Subject: [PATCH 018/230] Ensure that added core implementations of
 hook_token_info_alter() are properly set in token_module_implements_alter().

---
 token.module | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/token.module b/token.module
index 21831e9..7bba8a7 100644
--- a/token.module
+++ b/token.module
@@ -442,9 +442,11 @@ function token_entity_info_alter(&$info) {
  * Adds missing token support for core modules.
  */
 function token_module_implements_alter(&$implementations, $hook) {
-  if ($hook == 'tokens' || $hook == 'token_info') {
+  module_load_include('inc', 'token', 'token.tokens');
+
+  if ($hook == 'tokens' || $hook == 'token_info' || $hook == 'token_info_alter' || $hook == 'tokens_alter') {
     foreach (_token_core_supported_modules() as $module) {
-      if (module_exists($module)) {
+      if (module_exists($module) && function_exists($module . '_' . $hook)) {
         $implementations[$module] = FALSE;
       }
     }
-- 
1.9.3 (Apple Git-50)


From c5b20e07ed91fa5e6ed036a45be8be5a924378dc Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Sat, 22 Sep 2012 10:46:02 -0500
Subject: [PATCH 019/230] Issue #1791536: Fixed options not properly passed to
 theme('token_tree') in token_page_output_tree().

---
 token.pages.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.pages.inc b/token.pages.inc
index 4e281af..905943c 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -56,7 +56,7 @@ function token_page_output_tree() {
   // a dialog.
   $options['dialog'] = FALSE;
 
-  $output = theme('token_tree', array($options));
+  $output = theme('token_tree', $options);
   print '<html><head><title></title>' . drupal_get_css() . drupal_get_js() . '</head>';
   print '<body class="token-tree">' . $output . '</body></html>';
   drupal_exit();
-- 
1.9.3 (Apple Git-50)


From 4a1977f0f59f6f4883305bd4c5ac85a733404cac Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Mon, 21 Jan 2013 15:18:05 -0600
Subject: [PATCH 020/230] Issue #1894880: Added a fallback parameter to
 token_get_entity_mapping().

---
 token.module | 9 ++++++---
 token.test   | 2 ++
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/token.module b/token.module
index 7bba8a7..e3b4f82 100644
--- a/token.module
+++ b/token.module
@@ -377,23 +377,26 @@ function token_clear_cache() {
  * @see token_entity_info_alter()
  * @see http://drupal.org/node/737726
  */
-function token_get_entity_mapping($value_type = 'token', $value = NULL) {
+function token_get_entity_mapping($value_type = 'token', $value = NULL, $fallback = FALSE) {
   $mapping = &drupal_static(__FUNCTION__, array());
 
   if (empty($mapping)) {
     foreach (entity_get_info() as $entity_type => $info) {
       $mapping[$entity_type] = !empty($info['token type']) ? $info['token type'] : $entity_type;
     }
+    // Allow modules to alter the mapping array.
+    drupal_alter('token_entity_mapping', $mapping);
   }
 
   if (!isset($value)) {
     return $mapping;
   }
   elseif ($value_type == 'token') {
-    return array_search($value, $mapping);
+    $return = array_search($value, $mapping);
+    return $return !== FALSE ? $return : ($fallback ? $value : FALSE);
   }
   elseif ($value_type == 'entity') {
-    return isset($mapping[$value]) ? $mapping[$value] : FALSE;
+    return isset($mapping[$value]) ? $mapping[$value] : ($fallback ? $value : FALSE);
   }
 }
 
diff --git a/token.test b/token.test
index b7e9582..59fa645 100644
--- a/token.test
+++ b/token.test
@@ -676,10 +676,12 @@ class TokenEntityTestCase extends TokenTestHelper {
     $this->assertIdentical(token_get_entity_mapping('token', 'term'), 'taxonomy_term');
     $this->assertIdentical(token_get_entity_mapping('token', 'vocabulary'), 'taxonomy_vocabulary');
     $this->assertIdentical(token_get_entity_mapping('token', 'invalid'), FALSE);
+    $this->assertIdentical(token_get_entity_mapping('token', 'invalid', TRUE), 'invalid');
     $this->assertIdentical(token_get_entity_mapping('entity', 'node'), 'node');
     $this->assertIdentical(token_get_entity_mapping('entity', 'taxonomy_term'), 'term');
     $this->assertIdentical(token_get_entity_mapping('entity', 'taxonomy_vocabulary'), 'vocabulary');
     $this->assertIdentical(token_get_entity_mapping('entity', 'invalid'), FALSE);
+    $this->assertIdentical(token_get_entity_mapping('entity', 'invalid', TRUE), 'invalid');
 
     // Test that when we send the mis-matched entity type into token_replace()
     // that we still get the tokens replaced.
-- 
1.9.3 (Apple Git-50)


From 75a541485e39a2ba8000e35d0311ee199b932775 Mon Sep 17 00:00:00 2001
From: grisendo <grisendo@848238.no-reply.drupal.org>
Date: Mon, 21 Jan 2013 17:39:04 -0600
Subject: [PATCH 021/230] Issue #1894890: Fixed date type titles need
 sanitization.

---
 token.tokens.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index 3dc2d3b..e0c0b5e 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -80,7 +80,7 @@ function token_token_info_alter(&$info) {
   foreach ($date_format_types as $date_format_type => $date_format_type_info) {
     if (!isset($info['tokens']['date'][$date_format_type])) {
       $info['tokens']['date'][$date_format_type] = array(
-        'name' => $date_format_type_info['title'],
+        'name' => check_plain($date_format_type_info['title']),
         'description' => t("A date in '@type' format. (%date)", array('@type' => $date_format_type, '%date' => format_date(REQUEST_TIME, $date_format_type))),
         'module' => 'token',
       );
-- 
1.9.3 (Apple Git-50)


From a88bcd93baeca0c40e2298927ea48482f3a59d5d Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Fri, 25 Jan 2013 15:46:07 -0600
Subject: [PATCH 022/230] Added Drush intergration for clearing token cache.

---
 token.drush.inc | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 token.drush.inc

diff --git a/token.drush.inc b/token.drush.inc
new file mode 100644
index 0000000..fc32357
--- /dev/null
+++ b/token.drush.inc
@@ -0,0 +1,22 @@
+<?php
+
+/**
+ * @file
+ * Drush integration for the Token module.
+ */
+
+/**
+ * Implements hook_drush_cache_clear().
+ */
+function token_drush_cache_clear(&$types) {
+  if (function_exists('module_exists') && module_exists('token')) {
+    $types['token'] = 'drush_token_cache_clear_token_info';
+  }
+}
+
+/**
+ * Clear caches internal to Token module.
+ */
+function drush_token_cache_clear_token_info() {
+  token_clear_cache();
+}
-- 
1.9.3 (Apple Git-50)


From 4799924e57a6025fb4df1ebd46afe44b70c4f394 Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Fri, 25 Jan 2013 15:55:02 -0600
Subject: [PATCH 023/230] Support passing in a third argument to override the
 token type in token_devel_token_object().

---
 token.pages.inc | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/token.pages.inc b/token.pages.inc
index 905943c..dbe3f8f 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -231,7 +231,7 @@ function _token_clean_css_identifier($id) {
 /**
  * Menu callback; prints the available tokens and values for an object.
  */
-function token_devel_token_object($entity_type, $entity) {
+function token_devel_token_object($entity_type, $entity, $token_type = NULL) {
   $header = array(
     t('Token'),
     t('Value'),
@@ -243,7 +243,10 @@ function token_devel_token_object($entity_type, $entity) {
     'values' => TRUE,
     'data' => array($entity_type => $entity),
   );
-  $tree = token_build_tree($entity_type, $options);
+  if (!isset($token_type)) {
+    $token_type = $entity_type;
+  }
+  $tree = token_build_tree($token_type, $options);
   foreach ($tree as $token => $token_info) {
     if (!empty($token_info['restricted'])) {
       continue;
-- 
1.9.3 (Apple Git-50)


From 05550da25a1b75d70127033a0721f0625f9d922a Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Wed, 30 Jan 2013 00:14:36 -0600
Subject: [PATCH 024/230] Use the dialog version of the token tree in all
 internal uses for core.

---
 token.module | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/token.module b/token.module
index e3b4f82..f5ebdab 100644
--- a/token.module
+++ b/token.module
@@ -749,17 +749,21 @@ function token_form_field_ui_field_edit_form_alter(&$form, $form_state) {
   if (($form['#field']['type'] == 'file' || $form['#field']['type'] == 'image') && isset($form['instance']['settings']['file_directory']) && !module_exists('filefield_paths')) {
     // GAH! We can only support global tokens in the upload file directory path.
     $form['instance']['settings']['file_directory']['#element_validate'][] = 'token_element_validate';
-    $form['instance']['settings']['file_directory']['#token_types'] = array();
-    $form['instance']['settings']['token_tree'] = array(
-      '#theme' => 'token_tree',
-      '#token_types' => array(),
-      '#weight' => $form['instance']['settings']['file_directory']['#weight'] + 0.5,
-    );
+    $form['instance']['settings']['file_directory'] += array('#token_types' => array());
     $form['instance']['settings']['file_directory']['#description'] .= ' ' . t('This field supports tokens.');
   }
 
   // Note that the description is tokenized via token_field_widget_form_alter().
   $form['instance']['description']['#description'] .= '<br />' . t('This field supports tokens.');
+  $form['instance']['description']['#element_validate'][] = 'token_element_validate';
+  $form['instance']['description'] += array('#token_types' => array());
+
+  $form['instance']['settings']['token_tree'] = array(
+    '#theme' => 'token_tree',
+    '#token_types' => array(),
+    '#dialog' => TRUE,
+    '#weight' => $form['instance']['description']['#weight'] + 0.5,
+  );
 }
 
 /**
@@ -778,6 +782,7 @@ function token_form_system_actions_configure_alter(&$form, $form_state) {
       $form['token_tree'] = array(
         '#theme' => 'token_tree',
         '#token_types' => 'all',
+        '#dialog' => TRUE,
         '#weight' => 100,
       );
       // @todo Add token validation to the action fields that can use tokens.
@@ -839,10 +844,11 @@ function token_form_user_admin_settings_alter(&$form, &$form_state) {
   }
 
   // Add the token tree UI.
-  $form['token_tree'] = array(
+  $form['email']['token_tree'] = array(
     '#theme' => 'token_tree',
     '#token_types' => array('user'),
     '#show_restricted' => TRUE,
+    '#dialog' => TRUE,
     '#weight' => 90,
   );
 }
-- 
1.9.3 (Apple Git-50)


From 0b4457eccee91e838cb7152b9f2bba6a01ea351a Mon Sep 17 00:00:00 2001
From: simongeorges <simongeorges@172312.no-reply.drupal.org>
Date: Wed, 6 Feb 2013 01:25:55 -0600
Subject: [PATCH 025/230] Issue #1909308: Removed unnecessary files[]
 directives from token.info.

---
 token.info | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/token.info b/token.info
index b65e29f..4a00628 100644
--- a/token.info
+++ b/token.info
@@ -1,8 +1,4 @@
 name = Token
 description = Provides a user interface for the Token API and some missing core tokens.
 core = 7.x
-files[] = token.module
-files[] = token.install
-files[] = token.tokens.inc
-files[] = token.pages.inc
 files[] = token.test
-- 
1.9.3 (Apple Git-50)


From cf25888d3350a3d92eefc2af0a6735e312b56636 Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Sat, 23 Feb 2013 16:38:16 -0600
Subject: [PATCH 026/230] Issue #1859452 by Dave Reid: jnettik, kalabro: Fixed
 token dialog did not render in the same theme as the current page, causing
 CSS conflicts.

---
 token.js        | 8 +++++++-
 token.module    | 1 +
 token.pages.inc | 2 +-
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/token.js b/token.js
index 88a75c1..98d1ac3 100644
--- a/token.js
+++ b/token.js
@@ -14,6 +14,12 @@ Drupal.behaviors.tokenDialog = {
     $('a.token-dialog', context).once('token-dialog').click(function() {
       var url = $(this).attr('href');
       var dialog = $('<div style="display: none" class="loading">' + Drupal.t('Loading token browser...') + '</div>').appendTo('body');
+
+      // Emulate the AJAX data sent normally so that we get the same theme.
+      var data = {};
+      data['ajax_page_state[theme]'] = Drupal.settings.ajaxPageState.theme;
+      data['ajax_page_state[theme_token]'] = Drupal.settings.ajaxPageState.theme_token;
+
       dialog.dialog({
         title: $(this).attr('title') || Drupal.t('Available tokens'),
         width: 700,
@@ -24,7 +30,7 @@ Drupal.behaviors.tokenDialog = {
       // Load the token tree using AJAX.
       dialog.load(
         url,
-        {},
+        data,
         function (responseText, textStatus, XMLHttpRequest) {
           dialog.removeClass('loading');
         }
diff --git a/token.module b/token.module
index f5ebdab..3c19879 100644
--- a/token.module
+++ b/token.module
@@ -78,6 +78,7 @@ function token_menu() {
     'access callback' => TRUE,
     'type' => MENU_CALLBACK,
     'file' => 'token.pages.inc',
+    'theme callback' => 'ajax_base_page_theme',
   );
 
   // Devel token pages.
diff --git a/token.pages.inc b/token.pages.inc
index dbe3f8f..2341a9f 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -57,7 +57,7 @@ function token_page_output_tree() {
   $options['dialog'] = FALSE;
 
   $output = theme('token_tree', $options);
-  print '<html><head><title></title>' . drupal_get_css() . drupal_get_js() . '</head>';
+  print '<html><head>' . drupal_get_css() . drupal_get_js() . '</head>';
   print '<body class="token-tree">' . $output . '</body></html>';
   drupal_exit();
 }
-- 
1.9.3 (Apple Git-50)


From 7a37d4be8583b4b32ed8da26dc259419f7b29b6a Mon Sep 17 00:00:00 2001
From: daffie <daffie@116368.no-reply.drupal.org>
Date: Sat, 23 Feb 2013 17:28:18 -0600
Subject: [PATCH 027/230] Issue #1720576: Prevent notices in
 token_form_field_ui_field_edit_form_alter() if the field is locked.

---
 token.module | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.module b/token.module
index 3c19879..29ce6b0 100644
--- a/token.module
+++ b/token.module
@@ -743,7 +743,7 @@ function token_element_validate_token_context(&$element, &$form_state) {
  * Implements hook_form_FORM_ID_alter().
  */
 function token_form_field_ui_field_edit_form_alter(&$form, $form_state) {
-  if (!isset($form['instance'])) {
+  if (!isset($form['instance']) || !empty($form['#field']['locked'])) {
     return;
   }
 
-- 
1.9.3 (Apple Git-50)


From 77328403d88ce897784ed05156106a4c47d04f4a Mon Sep 17 00:00:00 2001
From: ianmthomasuk <ianmthomasuk@1877338.no-reply.drupal.org>
Date: Sat, 23 Feb 2013 17:31:20 -0600
Subject: [PATCH 028/230] Issue #1863910: Do not override the token types if
 specified in the block title field.

---
 token.module | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.module b/token.module
index 29ce6b0..9a3a9f5 100644
--- a/token.module
+++ b/token.module
@@ -266,7 +266,7 @@ function token_form_block_admin_configure_alter(&$form, $form_state) {
   $form['settings']['title']['#description'] .= ' ' . t('This field supports tokens.');
   // @todo Figure out why this token validation does not seem to be working here.
   $form['settings']['title']['#element_validate'][] = 'token_element_validate';
-  $form['settings']['title']['#token_types'] = array();
+  $form['settings']['title'] += array('#token_types' => array());
 }
 
 /**
-- 
1.9.3 (Apple Git-50)


From 72f3d1723fb5b2071a54d24fccad1f333c86c4fa Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Sat, 23 Feb 2013 17:54:21 -0600
Subject: [PATCH 029/230] Return a flipped array when
 token_get_entity_mapping('token') without a $value parameter.

---
 token.module | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.module b/token.module
index 9a3a9f5..88bcc60 100644
--- a/token.module
+++ b/token.module
@@ -390,7 +390,7 @@ function token_get_entity_mapping($value_type = 'token', $value = NULL, $fallbac
   }
 
   if (!isset($value)) {
-    return $mapping;
+    return $value_type == 'token' ? array_flip($mapping) : $mapping;
   }
   elseif ($value_type == 'token') {
     $return = array_search($value, $mapping);
-- 
1.9.3 (Apple Git-50)


From 379cb7d28e14087eea49a7c972137cce3b9935ac Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Mon, 27 Jan 2014 13:12:10 -0600
Subject: [PATCH 030/230] Issue #2150879 by DamienMcKenna, Dave Reid: Fixed
 token_entity_info_alter() should add view modes to all fieldable entity
 types, not just entity types with existing view modes.

---
 token.module | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/token.module b/token.module
index 88bcc60..926db6d 100644
--- a/token.module
+++ b/token.module
@@ -412,12 +412,18 @@ function token_get_entity_mapping($value_type = 'token', $value = NULL, $fallbac
  */
 function token_entity_info_alter(&$info) {
   foreach (array_keys($info) as $entity_type) {
-    // Add a token view mode if it does not already exist.
-    if (!empty($info[$entity_type]['view modes']) && !isset($info[$entity_type]['view modes']['token'])) {
-      $info[$entity_type]['view modes']['token'] = array(
-        'label' => t('Tokens'),
-        'custom settings' => FALSE,
-      );
+    // Add a token view mode if it does not already exist. Only work with
+    // fieldable entities.
+    if (!empty($info[$entity_type]['fieldable'])) {
+      if (!isset($info[$entity_type])) {
+        $info[$entity_type]['view modes'] = array();
+      }
+      if (!isset($info[$entity_type]['view modes']['token'])) {
+        $info[$entity_type]['view modes']['token'] = array(
+          'label' => t('Tokens'),
+          'custom settings' => FALSE,
+        );
+      }
     }
 
     if (!empty($info[$entity_type]['token type'])) {
-- 
1.9.3 (Apple Git-50)


From 64a80fb94c7ea3fcc64fe611bff84310c6416689 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Thu, 13 Feb 2014 14:45:55 +1000
Subject: [PATCH 031/230] Issue #1962358 by larowlan: Info file to yaml

---
 token.info     | 4 ----
 token.info.yml | 3 +++
 2 files changed, 3 insertions(+), 4 deletions(-)
 delete mode 100644 token.info
 create mode 100644 token.info.yml

diff --git a/token.info b/token.info
deleted file mode 100644
index 7a18eae..0000000
--- a/token.info
+++ /dev/null
@@ -1,4 +0,0 @@
-name = Token
-description = Provides a user interface for the Token API and some missing core tokens.
-core = 8.x
-files[] = token.test
diff --git a/token.info.yml b/token.info.yml
new file mode 100644
index 0000000..b91290f
--- /dev/null
+++ b/token.info.yml
@@ -0,0 +1,3 @@
+name: Token
+description: Provides a user interface for the Token API and some missing core tokens.
+core: 8.x
-- 
1.9.3 (Apple Git-50)


From b51e7b9f69964b349db7dd7e7473a4f19349d737 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Thu, 13 Feb 2014 15:03:32 +1000
Subject: [PATCH 032/230] Issue #1962358 by larowlan: Tests to psr-0

---
 lib/Drupal/token/Tests/TokenArrayTestCase.php      |   69 ++
 lib/Drupal/token/Tests/TokenBlockTestCase.php      |   45 +
 lib/Drupal/token/Tests/TokenCommentTestCase.php    |   71 ++
 .../token/Tests/TokenCurrentPageTestCase.php       |   65 ++
 lib/Drupal/token/Tests/TokenDateTestCase.php       |   29 +
 lib/Drupal/token/Tests/TokenEntityTestCase.php     |   89 ++
 lib/Drupal/token/Tests/TokenFileTestCase.php       |   48 +
 lib/Drupal/token/Tests/TokenMenuTestCase.php       |  113 ++
 lib/Drupal/token/Tests/TokenNodeTestCase.php       |   70 ++
 lib/Drupal/token/Tests/TokenRandomTestCase.php     |   36 +
 lib/Drupal/token/Tests/TokenTaxonomyTestCase.php   |  115 +++
 lib/Drupal/token/Tests/TokenTestBase.php           |  121 +++
 lib/Drupal/token/Tests/TokenURLTestCase.php        |   47 +
 lib/Drupal/token/Tests/TokenUnitTestCase.php       |   94 ++
 lib/Drupal/token/Tests/TokenUserTestCase.php       |   92 ++
 token.test                                         | 1087 --------------------
 16 files changed, 1104 insertions(+), 1087 deletions(-)
 create mode 100644 lib/Drupal/token/Tests/TokenArrayTestCase.php
 create mode 100644 lib/Drupal/token/Tests/TokenBlockTestCase.php
 create mode 100644 lib/Drupal/token/Tests/TokenCommentTestCase.php
 create mode 100644 lib/Drupal/token/Tests/TokenCurrentPageTestCase.php
 create mode 100644 lib/Drupal/token/Tests/TokenDateTestCase.php
 create mode 100644 lib/Drupal/token/Tests/TokenEntityTestCase.php
 create mode 100644 lib/Drupal/token/Tests/TokenFileTestCase.php
 create mode 100644 lib/Drupal/token/Tests/TokenMenuTestCase.php
 create mode 100644 lib/Drupal/token/Tests/TokenNodeTestCase.php
 create mode 100644 lib/Drupal/token/Tests/TokenRandomTestCase.php
 create mode 100644 lib/Drupal/token/Tests/TokenTaxonomyTestCase.php
 create mode 100644 lib/Drupal/token/Tests/TokenTestBase.php
 create mode 100644 lib/Drupal/token/Tests/TokenURLTestCase.php
 create mode 100644 lib/Drupal/token/Tests/TokenUnitTestCase.php
 create mode 100644 lib/Drupal/token/Tests/TokenUserTestCase.php
 delete mode 100644 token.test

diff --git a/lib/Drupal/token/Tests/TokenArrayTestCase.php b/lib/Drupal/token/Tests/TokenArrayTestCase.php
new file mode 100644
index 0000000..ebc627f
--- /dev/null
+++ b/lib/Drupal/token/Tests/TokenArrayTestCase.php
@@ -0,0 +1,69 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Tests\TokenArrayTestCase
+ */
+namespace Drupal\token\Tests;
+
+/**
+ * Tests array tokens.
+ */
+class TokenArrayTestCase extends TokenTestBase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Array token tests',
+      'description' => 'Test the array tokens.',
+      'group' => 'Token',
+    );
+  }
+
+  function testArrayTokens() {
+    // Test a simple array.
+    $array = array(0 => 'a', 1 => 'b', 2 => 'c', 4 => 'd');
+    $tokens = array(
+      'first' => 'a',
+      'last' => 'd',
+      'value:0' => 'a',
+      'value:2' => 'c',
+      'count' => 4,
+      'keys' => '0, 1, 2, 4',
+      'keys:value:3' => '4',
+      'keys:join' => '0124',
+      'reversed' => 'd, c, b, a',
+      'reversed:keys' => '4, 2, 1, 0',
+      'join:/' => 'a/b/c/d',
+      'join' => 'abcd',
+      'join:, ' => 'a, b, c, d',
+      'join: ' => 'a b c d',
+    );
+    $this->assertTokens('array', array('array' => $array), $tokens);
+
+    // Test a mixed simple and render array.
+    // 2 => c, 0 => a, 4 => d, 1 => b
+    $array = array(
+      '#property' => 'value',
+      0 => 'a',
+      1 => array('#markup' => 'b', '#weight' => 0.01),
+      2 => array('#markup' => 'c', '#weight' => -10),
+      4 => array('#markup' => 'd', '#weight' => 0),
+    );
+    $tokens = array(
+      'first' => 'c',
+      'last' => 'b',
+      'value:0' => 'a',
+      'value:2' => 'c',
+      'count' => 4,
+      'keys' => '2, 0, 4, 1',
+      'keys:value:3' => '1',
+      'keys:join' => '2041',
+      'reversed' => 'b, d, a, c',
+      'reversed:keys' => '1, 4, 0, 2',
+      'join:/' => 'c/a/d/b',
+      'join' => 'cadb',
+      'join:, ' => 'c, a, d, b',
+      'join: ' => 'c a d b',
+    );
+    $this->assertTokens('array', array('array' => $array), $tokens);
+  }
+}
diff --git a/lib/Drupal/token/Tests/TokenBlockTestCase.php b/lib/Drupal/token/Tests/TokenBlockTestCase.php
new file mode 100644
index 0000000..e34c2f4
--- /dev/null
+++ b/lib/Drupal/token/Tests/TokenBlockTestCase.php
@@ -0,0 +1,45 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Tests\TokenBlockTestCase.
+ */
+namespace Drupal\token\Tests;
+
+/**
+ * Tests block tokens.
+ */
+class TokenBlockTestCase extends TokenTestBase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Block token tests',
+      'description' => 'Test the block title token replacement.',
+      'group' => 'Token',
+    );
+  }
+
+  public function setUp($modules = array()) {
+    $modules[] = 'block';
+    parent::setUp($modules);
+
+    $this->admin_user = $this->drupalCreateUser(array('access content', 'administer blocks'));
+    $this->drupalLogin($this->admin_user);
+  }
+
+  public function testBlockTitleTokens() {
+    $edit['title'] = '[current-page:title] block title';
+    $edit['info'] = 'Test token title block';
+    $edit['body[value]'] = 'This is the test token title block.';
+    $edit['regions[bartik]'] = 'sidebar_first';
+    $this->drupalPost('admin/structure/block/add', $edit, 'Save block');
+
+    $this->drupalGet('node');
+    $this->assertText('Welcome to ' . variable_get('site_name', 'Drupal') . ' block title');
+
+    // Ensure that tokens are not double-escaped when output as a block title.
+    $node = $this->drupalCreateNode(array('title' => "Site's first node"));
+    $this->drupalGet('node/' . $node->nid);
+    // The apostraphe should only be escaped once via check_plain().
+    $this->assertRaw("Site&#039;s first node block title");
+  }
+}
diff --git a/lib/Drupal/token/Tests/TokenCommentTestCase.php b/lib/Drupal/token/Tests/TokenCommentTestCase.php
new file mode 100644
index 0000000..e4dbec0
--- /dev/null
+++ b/lib/Drupal/token/Tests/TokenCommentTestCase.php
@@ -0,0 +1,71 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Tests\TokenCommentTestCase.
+ */
+namespace Drupal\token\Tests;
+
+/**
+ * Tests comment tokens.
+ */
+class TokenCommentTestCase extends TokenTestBase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Comment token tests',
+      'description' => 'Test the comment tokens.',
+      'group' => 'Token',
+    );
+  }
+
+  public function setUp($modules = array()) {
+    $modules[] = 'comment';
+    parent::setUp($modules);
+  }
+
+  function testCommentTokens() {
+    $node = $this->drupalCreateNode(array('comment' => COMMENT_NODE_OPEN));
+
+    $parent_comment = new stdClass;
+    $parent_comment->nid = $node->nid;
+    $parent_comment->pid = 0;
+    $parent_comment->cid = NULL;
+    $parent_comment->uid = 0;
+    $parent_comment->name = 'anonymous user';
+    $parent_comment->mail = 'anonymous@example.com';
+    $parent_comment->subject = $this->randomName();
+    $parent_comment->timestamp = mt_rand($node->created, REQUEST_TIME);
+    $parent_comment->language = LANGUAGE_NOT_SPECIFIED;
+    $parent_comment->body[LANGUAGE_NOT_SPECIFIED][0] = $this->randomName();
+    comment_save($parent_comment);
+
+    $tokens = array(
+      'url' => url('comment/' . $parent_comment->cid, array('fragment' => 'comment-' . $parent_comment->cid, 'absolute' => TRUE)),
+      'url:absolute' => url('comment/' . $parent_comment->cid, array('fragment' => 'comment-' . $parent_comment->cid, 'absolute' => TRUE)),
+      'url:relative' => url('comment/' . $parent_comment->cid, array('fragment' => 'comment-' . $parent_comment->cid, 'absolute' => FALSE)),
+      'url:path' => 'comment/' . $parent_comment->cid,
+      'parent:url:absolute' => NULL,
+    );
+    $this->assertTokens('comment', array('comment' => $parent_comment), $tokens);
+
+    $comment = new stdClass();
+    $comment->nid = $node->nid;
+    $comment->pid = $parent_comment->cid;
+    $comment->cid = NULL;
+    $comment->uid = 1;
+    $comment->subject = $this->randomName();
+    $comment->timestamp = mt_rand($parent_comment->created, REQUEST_TIME);
+    $comment->language = LANGUAGE_NOT_SPECIFIED;
+    $comment->body[LANGUAGE_NOT_SPECIFIED][0] = $this->randomName();
+    comment_save($comment);
+
+    $tokens = array(
+      'url' => url('comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid, 'absolute' => TRUE)),
+      'url:absolute' => url('comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid, 'absolute' => TRUE)),
+      'url:relative' => url('comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid, 'absolute' => FALSE)),
+      'url:path' => 'comment/' . $comment->cid,
+      'parent:url:absolute' => url('comment/' . $parent_comment->cid, array('fragment' => 'comment-' . $parent_comment->cid, 'absolute' => TRUE)),
+    );
+    $this->assertTokens('comment', array('comment' => $comment), $tokens);
+  }
+}
diff --git a/lib/Drupal/token/Tests/TokenCurrentPageTestCase.php b/lib/Drupal/token/Tests/TokenCurrentPageTestCase.php
new file mode 100644
index 0000000..578ddc7
--- /dev/null
+++ b/lib/Drupal/token/Tests/TokenCurrentPageTestCase.php
@@ -0,0 +1,65 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Tests\TokenCurrentPageTestCase.
+ */
+namespace Drupal\token\Tests;
+
+/**
+ * Tests current page tokens.
+ */
+class TokenCurrentPageTestCase extends TokenTestBase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Current page token tests',
+      'description' => 'Test the [current-page:*] tokens.',
+      'group' => 'Token',
+    );
+  }
+
+  function testCurrentPageTokens() {
+    $tokens = array(
+      '[current-page:title]' => t('Welcome to @site-name', array('@site-name' => variable_get('site_name', 'Drupal'))),
+      '[current-page:url]' => url('node', array('absolute' => TRUE)),
+      '[current-page:url:absolute]' => url('node', array('absolute' => TRUE)),
+      '[current-page:url:relative]' => url('node', array('absolute' => FALSE)),
+      '[current-page:url:path]' => 'node',
+      '[current-page:url:args:value:0]' => 'node',
+      '[current-page:url:args:value:1]' => NULL,
+      '[current-page:url:unaliased]' => url('node', array('absolute' => TRUE, 'alias' => TRUE)),
+      '[current-page:page-number]' => 1,
+      '[current-page:query:foo]' => NULL,
+      '[current-page:query:bar]' => NULL,
+      '[current-page:query:q]' => 'node',
+      // Deprecated tokens
+      '[current-page:arg:0]' => 'node',
+      '[current-page:arg:1]' => NULL,
+    );
+    $this->assertPageTokens('', $tokens);
+
+    $node = $this->drupalCreateNode(array('title' => 'Node title', 'path' => array('alias' => 'node-alias')));
+    $tokens = array(
+      '[current-page:title]' => 'Node title',
+      '[current-page:url]' => url("node/{$node->nid}", array('absolute' => TRUE)),
+      '[current-page:url:absolute]' => url("node/{$node->nid}", array('absolute' => TRUE)),
+      '[current-page:url:relative]' => url("node/{$node->nid}", array('absolute' => FALSE)),
+      '[current-page:url:alias]' => 'node-alias',
+      '[current-page:url:args:value:0]' => 'node-alias',
+      '[current-page:url:args:value:1]' => NULL,
+      '[current-page:url:unaliased]' => url("node/{$node->nid}", array('absolute' => TRUE, 'alias' => TRUE)),
+      '[current-page:url:unaliased:args:value:0]' => 'node',
+      '[current-page:url:unaliased:args:value:1]' => $node->nid,
+      '[current-page:url:unaliased:args:value:2]' => NULL,
+      '[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,
+      '[current-page:arg:2]' => NULL,
+    );
+    $this->assertPageTokens("node/{$node->nid}", $tokens, array(), array('url_options' => array('query' => array('foo' => 'bar'))));
+  }
+}
diff --git a/lib/Drupal/token/Tests/TokenDateTestCase.php b/lib/Drupal/token/Tests/TokenDateTestCase.php
new file mode 100644
index 0000000..675c0df
--- /dev/null
+++ b/lib/Drupal/token/Tests/TokenDateTestCase.php
@@ -0,0 +1,29 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Tests\TokenDateTestCase.
+ */
+namespace Drupal\token\Tests;
+
+/**
+ * Tests date tokens.
+ */
+class TokenDateTestCase extends TokenTestBase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Date token tests',
+      'description' => 'Test the date tokens.',
+      'group' => 'Token',
+    );
+  }
+
+  function testDateTokens() {
+    $tokens = array(
+      'token_test' => '1984',
+      'invalid_format' => NULL,
+    );
+
+    $this->assertTokens('date', array('date' => 453859200), $tokens);
+  }
+}
diff --git a/lib/Drupal/token/Tests/TokenEntityTestCase.php b/lib/Drupal/token/Tests/TokenEntityTestCase.php
new file mode 100644
index 0000000..11a3353
--- /dev/null
+++ b/lib/Drupal/token/Tests/TokenEntityTestCase.php
@@ -0,0 +1,89 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Tests\TokenEntityTestCase.
+ */
+namespace Drupal\token\Tests;
+
+/**
+ * Tests entity tokens.
+ */
+class TokenEntityTestCase extends TokenTestBase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Entity token tests',
+      'description' => 'Test the entity tokens.',
+      'group' => 'Token',
+    );
+  }
+
+  public function setUp($modules = array()) {
+    $modules[] = 'taxonomy';
+    parent::setUp($modules);
+
+    // Create the default tags vocabulary.
+    $vocabulary = entity_create('taxonomy_vocabulary', array(
+      'name' => 'Tags',
+      'machine_name' => 'tags',
+    ));
+    taxonomy_vocabulary_save($vocabulary);
+    $this->vocab = $vocabulary;
+  }
+
+  function testEntityMapping() {
+    $this->assertIdentical(token_get_entity_mapping('token', 'node'), 'node');
+    $this->assertIdentical(token_get_entity_mapping('token', 'term'), 'taxonomy_term');
+    $this->assertIdentical(token_get_entity_mapping('token', 'vocabulary'), 'taxonomy_vocabulary');
+    $this->assertIdentical(token_get_entity_mapping('token', 'invalid'), FALSE);
+    $this->assertIdentical(token_get_entity_mapping('entity', 'node'), 'node');
+    $this->assertIdentical(token_get_entity_mapping('entity', 'taxonomy_term'), 'term');
+    $this->assertIdentical(token_get_entity_mapping('entity', 'taxonomy_vocabulary'), 'vocabulary');
+    $this->assertIdentical(token_get_entity_mapping('entity', 'invalid'), FALSE);
+
+    // Test that when we send the mis-matched entity type into token_replace()
+    // that we still get the tokens replaced.
+    $vocabulary = taxonomy_vocabulary_machine_name_load('tags');
+    $term = $this->addTerm($vocabulary);
+    $this->assertIdentical(token_replace('[vocabulary:name]', array('taxonomy_vocabulary' => $vocabulary)), $vocabulary->name);
+    $this->assertIdentical(token_replace('[term:name][term:vocabulary:name]', array('taxonomy_term' => $term)), $term->name . $vocabulary->name);
+  }
+
+  function addTerm(TaxonomyVocabulary $vocabulary, array $term = array()) {
+    $term += array(
+      'name' => drupal_strtolower($this->randomName(5)),
+      'vid' => $vocabulary->vid,
+    );
+    $term = entity_create('taxonomy_term', $term);
+    taxonomy_term_save($term);
+    return $term;
+  }
+
+  /**
+   * Test the [entity:original:*] tokens.
+   */
+  function testEntityOriginal() {
+    $node = $this->drupalCreateNode(array('title' => 'Original title'));
+
+    $tokens = array(
+      'nid' => $node->nid,
+      'title' => 'Original title',
+      'original' => NULL,
+      'original:nid' => NULL,
+    );
+    $this->assertTokens('node', array('node' => $node), $tokens);
+
+    // Emulate the original entity property that would be available from
+    // node_save() and change the title for the node.
+    $node->original = entity_load_unchanged('node', $node->nid);
+    $node->title = 'New title';
+
+    $tokens = array(
+      'nid' => $node->nid,
+      'title' => 'New title',
+      'original' => 'Original title',
+      'original:nid' => $node->nid,
+    );
+    $this->assertTokens('node', array('node' => $node), $tokens);
+  }
+}
diff --git a/lib/Drupal/token/Tests/TokenFileTestCase.php b/lib/Drupal/token/Tests/TokenFileTestCase.php
new file mode 100644
index 0000000..65656dc
--- /dev/null
+++ b/lib/Drupal/token/Tests/TokenFileTestCase.php
@@ -0,0 +1,48 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Tests\TokenFileTestCase.
+ */
+namespace Drupal\token\Tests;
+
+/**
+ * Tests file tokens.
+ */
+class TokenFileTestCase extends TokenTestBase {
+  public static function getInfo() {
+    return array(
+      'name' => 'File token tests',
+      'description' => 'Test the file tokens.',
+      'group' => 'Token',
+    );
+  }
+
+  function testFileTokens() {
+    // Create a test file object.
+    $file = new stdClass();
+    $file->fid = 1;
+    $file->filename = 'test.png';
+    $file->filesize = 100;
+    $file->uri = 'public://images/test.png';
+    $file->filemime = 'image/png';
+
+    $tokens = array(
+      'basename' => 'test.png',
+      'extension' => 'png',
+      'size-raw' => 100,
+    );
+    $this->assertTokens('file', array('file' => $file), $tokens);
+
+    // Test a file with no extension and a fake name.
+    $file->filename = 'Test PNG image';
+    $file->uri = 'public://images/test';
+
+    $tokens = array(
+      'basename' => 'test',
+      'extension' => '',
+      'size-raw' => 100,
+    );
+    $this->assertTokens('file', array('file' => $file), $tokens);
+  }
+}
diff --git a/lib/Drupal/token/Tests/TokenMenuTestCase.php b/lib/Drupal/token/Tests/TokenMenuTestCase.php
new file mode 100644
index 0000000..05a75ee
--- /dev/null
+++ b/lib/Drupal/token/Tests/TokenMenuTestCase.php
@@ -0,0 +1,113 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Tests\TokenMenuTestCase.
+ */
+namespace Drupal\token\Tests;
+
+/**
+ * Tests menu tokens.
+ */
+class TokenMenuTestCase extends TokenTestBase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Menu link and menu token tests',
+      'description' => 'Test the menu tokens.',
+      'group' => 'Token',
+    );
+  }
+
+  public function setUp($modules = array()) {
+    $modules[] = 'menu';
+    parent::setUp($modules);
+  }
+
+  function testMenuTokens() {
+    // Add a root link.
+    $root_link = array(
+      'link_path' => 'root',
+      'link_title' => 'Root link',
+      'menu_name' => 'main-menu',
+    );
+    menu_link_save($root_link);
+
+    // Add another link with the root link as the parent
+    $parent_link = array(
+      'link_path' => 'root/parent',
+      'link_title' => 'Parent link',
+      'menu_name' => 'main-menu',
+      'plid' => $root_link['mlid'],
+    );
+    menu_link_save($parent_link);
+
+    // Test menu link tokens.
+    $tokens = array(
+      'mlid' => $parent_link['mlid'],
+      'title' => 'Parent link',
+      'menu' => 'Main menu',
+      'menu:name' => 'Main menu',
+      'menu:machine-name' => 'main-menu',
+      'menu:description' => 'The <em>Main</em> menu is used on many sites to show the major sections of the site, often in a top navigation bar.',
+      'menu:menu-link-count' => 2,
+      'menu:edit-url' => url("admin/structure/menu/manage/main-menu", array('absolute' => TRUE)),
+      'url' => url('root/parent', array('absolute' => TRUE)),
+      'url:absolute' => url('root/parent', array('absolute' => TRUE)),
+      'url:relative' => url('root/parent', array('absolute' => FALSE)),
+      'url:path' => 'root/parent',
+      'url:alias' => 'root/parent',
+      'edit-url' => url("admin/structure/menu/item/{$parent_link['mlid']}/edit", array('absolute' => TRUE)),
+      'parent' => 'Root link',
+      'parent:mlid' => $root_link['mlid'],
+      'parent:title' => 'Root link',
+      'parent:menu' => 'Main menu',
+      'parent:parent' => NULL,
+      'parents' => 'Root link',
+      'parents:count' => 1,
+      'parents:keys' => $root_link['mlid'],
+      'root' => 'Root link',
+      'root:mlid' => $root_link['mlid'],
+      'root:parent' => NULL,
+      'root:root' => NULL,
+    );
+    $this->assertTokens('menu-link', array('menu-link' => $parent_link), $tokens);
+
+    // Add a node menu link
+    $node_link = array(
+      'enabled' => TRUE,
+      'link_title' => 'Node link',
+      'plid' => $parent_link['mlid'],
+      'customized' => 0,
+      'description' => '',
+    );
+    $node = $this->drupalCreateNode(array('menu' => $node_link));
+
+    // Test [node:menu] tokens.
+    $tokens = array(
+      'menu-link' => 'Node link',
+      'menu-link:mlid' => $node->menu['mlid'],
+      'menu-link:title' => 'Node link',
+      'menu-link:menu' => 'Main menu',
+      'menu-link:url' => url('node/' . $node->nid, array('absolute' => TRUE)),
+      'menu-link:url:path' => 'node/' . $node->nid,
+      'menu-link:edit-url' => url("admin/structure/menu/item/{$node->menu['mlid']}/edit", array('absolute' => TRUE)),
+      'menu-link:parent' => 'Parent link',
+      'menu-link:parent:mlid' => $node->menu['plid'],
+      'menu-link:parent:mlid' => $parent_link['mlid'],
+      'menu-link:parents' => 'Root link, Parent link',
+      'menu-link:parents:count' => 2,
+      'menu-link:parents:keys' => $root_link['mlid'] . ', ' . $parent_link['mlid'],
+      'menu-link:root' => 'Root link',
+      'menu-link:root:mlid' => $root_link['mlid'],
+    );
+    $this->assertTokens('node', array('node' => $node), $tokens);
+
+    // Reload the node which will not have $node->menu defined and re-test.
+    $loaded_node = node_load($node->nid);
+    $this->assertTokens('node', array('node' => $loaded_node), $tokens);
+
+    // Regression test for http://drupal.org/node/1317926 to ensure the
+    // original node object is not changed when calling menu_node_prepare().
+    $this->assertTrue(!isset($loaded_node->menu), t('The $node->menu property was not modified during token replacement.'), 'Regression');
+  }
+}
diff --git a/lib/Drupal/token/Tests/TokenNodeTestCase.php b/lib/Drupal/token/Tests/TokenNodeTestCase.php
new file mode 100644
index 0000000..a4b03bb
--- /dev/null
+++ b/lib/Drupal/token/Tests/TokenNodeTestCase.php
@@ -0,0 +1,70 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Tests\TokenNodeTestCase.
+ */
+namespace Drupal\token\Tests;
+
+/**
+ * Tests node tokens.
+ */
+class TokenNodeTestCase extends TokenTestBase {
+  protected $profile = 'standard';
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Node and content type token tests',
+      'description' => 'Test the node and content type tokens.',
+      'group' => 'Token',
+    );
+  }
+
+  function testNodeTokens() {
+    $source_node = $this->drupalCreateNode(array('log' => $this->randomName(), 'path' => array('alias' => 'content/source-node')));
+    $tokens = array(
+      'source' => NULL,
+      'source:nid' => NULL,
+      'log' => $source_node->log,
+      'url:path' => 'content/source-node',
+      'url:absolute' => url("node/{$source_node->nid}", array('absolute' => TRUE)),
+      'url:relative' => url("node/{$source_node->nid}", array('absolute' => FALSE)),
+      'url:unaliased:path' => "node/{$source_node->nid}",
+      'content-type' => 'Basic page',
+      'content-type:name' => 'Basic page',
+      'content-type:machine-name' => 'page',
+      'content-type:description' => "Use <em>basic pages</em> for your static content, such as an 'About us' page.",
+      'content-type:node-count' => 1,
+      'content-type:edit-url' => url('admin/structure/types/manage/page', array('absolute' => TRUE)),
+      // Deprecated tokens.
+      'tnid' => 0,
+      'type' => 'page',
+      'type-name' => 'Basic page',
+      'url:alias' => 'content/source-node',
+    );
+    $this->assertTokens('node', array('node' => $source_node), $tokens);
+
+    $translated_node = $this->drupalCreateNode(array('tnid' => $source_node->nid, 'type' => 'article'));
+    $tokens = array(
+      'source' => $source_node->title,
+      'source:nid' => $source_node->nid,
+      'log' => '',
+      'url:path' => "node/{$translated_node->nid}",
+      'url:absolute' => url("node/{$translated_node->nid}", array('absolute' => TRUE)),
+      'url:relative' => url("node/{$translated_node->nid}", array('absolute' => FALSE)),
+      'url:unaliased:path' => "node/{$translated_node->nid}",
+      'content-type' => 'Article',
+      'content-type:name' => 'Article',
+      'content-type:machine-name' => 'article',
+      'content-type:description' => "Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.",
+      'content-type:node-count' => 1,
+      'content-type:edit-url' => url('admin/structure/types/manage/article', array('absolute' => TRUE)),
+      // Deprecated tokens.
+      'type' => 'article',
+      'type-name' => 'Article',
+      'tnid' => $source_node->nid,
+      'url:alias' => "node/{$translated_node->nid}",
+    );
+    $this->assertTokens('node', array('node' => $translated_node), $tokens);
+  }
+}
diff --git a/lib/Drupal/token/Tests/TokenRandomTestCase.php b/lib/Drupal/token/Tests/TokenRandomTestCase.php
new file mode 100644
index 0000000..e214a13
--- /dev/null
+++ b/lib/Drupal/token/Tests/TokenRandomTestCase.php
@@ -0,0 +1,36 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Tests\TokenRandomTestCase.
+ */
+namespace Drupal\token\Tests;
+
+/**
+ * Tests random tokens.
+ */
+class TokenRandomTestCase extends TokenTestBase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Random token tests',
+      'description' => 'Test the random tokens.',
+      'group' => 'Token',
+    );
+  }
+
+  function testRandomTokens() {
+    $tokens = array(
+      'number' => '[0-9]{1,}',
+      'hash:md5' => '[0-9a-f]{32}',
+      'hash:sha1' => '[0-9a-f]{40}',
+      'hash:sha256' => '[0-9a-f]{64}',
+      'hash:invalid-algo' => NULL,
+    );
+
+    $first_set = $this->assertTokens('random', array(), $tokens, array('regex' => TRUE));
+    $second_set = $this->assertTokens('random', array(), $tokens, array('regex' => TRUE));
+    foreach ($first_set as $token => $value) {
+      $this->assertNotIdentical($first_set[$token], $second_set[$token]);
+    }
+  }
+}
diff --git a/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php b/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php
new file mode 100644
index 0000000..9fec241
--- /dev/null
+++ b/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php
@@ -0,0 +1,115 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Tests\TokenTaxonomyTestCase.
+ */
+namespace Drupal\token\Tests;
+
+/**
+ * Tests taxonomy tokens.
+ */
+class TokenTaxonomyTestCase extends TokenTestBase {
+  protected $vocab;
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Taxonomy and vocabulary token tests',
+      'description' => 'Test the taxonomy tokens.',
+      'group' => 'Token',
+    );
+  }
+
+  public function setUp($modules = array()) {
+    $modules[] = 'taxonomy';
+    parent::setUp($modules);
+
+    // Create the default tags vocabulary.
+    $vocabulary = entity_create('taxonomy_vocabulary', array(
+      'name' => 'Tags',
+      'machine_name' => 'tags',
+    ));
+    taxonomy_vocabulary_save($vocabulary);
+    $this->vocab = $vocabulary;
+  }
+
+  /**
+   * Test the additional taxonomy term tokens.
+   */
+  function testTaxonomyTokens() {
+    $root_term = $this->addTerm($this->vocab, array('name' => 'Root term', 'path' => array('alias' => 'root-term')));
+    $tokens = array(
+      'url' => url("taxonomy/term/{$root_term->tid}", array('absolute' => TRUE)),
+      'url:absolute' => url("taxonomy/term/{$root_term->tid}", array('absolute' => TRUE)),
+      'url:relative' => url("taxonomy/term/{$root_term->tid}", array('absolute' => FALSE)),
+      'url:path' => 'root-term',
+      'url:unaliased:path' => "taxonomy/term/{$root_term->tid}",
+      'edit-url' => url("taxonomy/term/{$root_term->tid}/edit", array('absolute' => TRUE)),
+      'parents' => NULL,
+      'parents:count' => NULL,
+      'parents:keys' => NULL,
+      'root' => NULL,
+      // Deprecated tokens
+      'url:alias' => 'root-term',
+    );
+    $this->assertTokens('term', array('term' => $root_term), $tokens);
+
+    $parent_term = $this->addTerm($this->vocab, array('name' => 'Parent term', 'parent' => $root_term->tid));
+    $tokens = array(
+      'url' => url("taxonomy/term/{$parent_term->tid}", array('absolute' => TRUE)),
+      'url:absolute' => url("taxonomy/term/{$parent_term->tid}", array('absolute' => TRUE)),
+      'url:relative' => url("taxonomy/term/{$parent_term->tid}", array('absolute' => FALSE)),
+      'url:path' => "taxonomy/term/{$parent_term->tid}",
+      'url:unaliased:path' => "taxonomy/term/{$parent_term->tid}",
+      'edit-url' => url("taxonomy/term/{$parent_term->tid}/edit", array('absolute' => TRUE)),
+      'parents' => 'Root term',
+      'parents:count' => 1,
+      'parents:keys' => $root_term->tid,
+      'root' => check_plain($root_term->name),
+      'root:tid' => $root_term->tid,
+      // Deprecated tokens
+      'url:alias' => "taxonomy/term/{$parent_term->tid}",
+    );
+    $this->assertTokens('term', array('term' => $parent_term), $tokens);
+
+    $term = $this->addTerm($this->vocab, array('name' => 'Test term', 'parent' => $parent_term->tid));
+    $tokens = array(
+      'parents' => 'Root term, Parent term',
+      'parents:count' => 2,
+      'parents:keys' => implode(', ', array($root_term->tid, $parent_term->tid)),
+    );
+    $this->assertTokens('term', array('term' => $term), $tokens);
+  }
+
+  /**
+   * Test the additional vocabulary tokens.
+   */
+  function testVocabularyTokens() {
+    $vocabulary = $this->vocab;
+    $tokens = array(
+      'machine-name' => 'tags',
+      'edit-url' => url("admin/structure/taxonomy/{$vocabulary->machine_name}/edit", array('absolute' => TRUE)),
+    );
+    $this->assertTokens('vocabulary', array('vocabulary' => $vocabulary), $tokens);
+  }
+
+  function addVocabulary(array $vocabulary = array()) {
+    $vocabulary += array(
+      'name' => drupal_strtolower($this->randomName(5)),
+      'nodes' => array('article' => 'article'),
+    );
+    $vocabulary = entity_create('taxonomy_vocabulary', $vocabulary);
+    taxonomy_vocabulary_save($vocabulary);
+    return $vocabulary;
+  }
+
+  function addTerm(stdClass $vocabulary, array $term = array()) {
+    $term += array(
+      'name' => drupal_strtolower($this->randomName(5)),
+      'vid' => $vocabulary->vid,
+    );
+    $term = entity_create('taxonomy_term', $term);
+    taxonomy_term_save($term);
+    return $term;
+  }
+}
diff --git a/lib/Drupal/token/Tests/TokenTestBase.php b/lib/Drupal/token/Tests/TokenTestBase.php
new file mode 100644
index 0000000..c2e2b45
--- /dev/null
+++ b/lib/Drupal/token/Tests/TokenTestBase.php
@@ -0,0 +1,121 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Tests\TokenTestBase.
+ */
+namespace Drupal\token\Tests;
+
+use Drupal\simpletest\WebTestBase;
+
+/**
+ * Helper test class with some added functions for testing.
+ */
+class TokenTestBase extends WebTestBase {
+  protected $profile = 'testing';
+
+  public function setUp($modules = array()) {
+    $modules[] = 'path';
+    $modules[] = 'token';
+    $modules[] = 'token_test';
+    parent::setUp($modules);
+
+    variable_set('clean_url', 1);
+  }
+
+  function assertToken($type, array $data, $token, $expected, array $options = array()) {
+    return $this->assertTokens($type, $data, array($token => $expected), $options);
+  }
+
+  function assertTokens($type, array $data, array $tokens, array $options = array()) {
+    $input = $this->mapTokenNames($type, array_keys($tokens));
+    $replacements = token_generate($type, $input, $data, $options);
+    foreach ($tokens as $name => $expected) {
+      $token = $input[$name];
+      if (!isset($expected)) {
+        $this->assertTrue(!isset($values[$token]), t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token)));
+      }
+      elseif (!isset($replacements[$token])) {
+        $this->fail(t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token)));
+      }
+      elseif (!empty($options['regex'])) {
+        $this->assertTrue(preg_match('/^' . $expected . '$/', $replacements[$token]), t("Token value for @token was '@actual', matching regular expression pattern '@expected'.", array('@type' => $type, '@token' => $token, '@actual' => $replacements[$token], '@expected' => $expected)));
+      }
+      else {
+        $this->assertIdentical($replacements[$token], $expected, t("Token value for @token was '@actual', expected value '@expected'.", array('@type' => $type, '@token' => $token, '@actual' => $replacements[$token], '@expected' => $expected)));
+      }
+    }
+
+    return $replacements;
+  }
+
+  function mapTokenNames($type, array $tokens = array()) {
+    $return = array();
+    foreach ($tokens as $token) {
+      $return[$token] = "[$type:$token]";
+    }
+    return $return;
+  }
+
+  function assertNoTokens($type, array $data, array $tokens, array $options = array()) {
+    $input = $this->mapTokenNames($type, $tokens);
+    $replacements = token_generate($type, $input, $data, $options);
+    foreach ($tokens as $name) {
+      $token = $input[$name];
+      $this->assertTrue(!isset($replacements[$token]), t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token)));
+    }
+    return $values;
+  }
+
+  function saveAlias($source, $alias, $language = LANGUAGE_NOT_SPECIFIED) {
+    $alias = array(
+      'source' => $source,
+      'alias' => $alias,
+      'language' => $language,
+    );
+    path_save($alias);
+    return $alias;
+  }
+
+  function saveEntityAlias($entity_type, $entity, $alias, $language = LANGUAGE_NOT_SPECIFIED) {
+    $uri = entity_uri($entity_type, $entity);
+    return $this->saveAlias($uri['path'], $alias, $language);
+  }
+
+  /**
+   * Make a page request and test for token generation.
+   */
+  function assertPageTokens($url, array $tokens, array $data = array(), array $options = array()) {
+    if (empty($tokens)) {
+      return TRUE;
+    }
+
+    $token_page_tokens = array(
+      'tokens' => $tokens,
+      'data' => $data,
+      'options' => $options,
+    );
+    variable_set('token_page_tokens', $token_page_tokens);
+
+    $options += array('url_options' => array());
+    $this->drupalGet($url, $options['url_options']);
+    $this->refreshVariables();
+    $result = variable_get('token_page_tokens', array());
+
+    if (!isset($result['values']) || !is_array($result['values'])) {
+      return $this->fail('Failed to generate tokens.');
+    }
+
+    foreach ($tokens as $token => $expected) {
+      if (!isset($expected)) {
+        $this->assertTrue(!isset($result['values'][$token]) || $result['values'][$token] === $token, t("Token value for @token was not generated.", array('@token' => $token)));
+      }
+      elseif (!isset($result['values'][$token])) {
+        $this->fail(t('Failed to generate token @token.', array('@token' => $token)));
+      }
+      else {
+        $this->assertIdentical($result['values'][$token], (string) $expected, t("Token value for @token was '@actual', expected value '@expected'.", array('@token' => $token, '@actual' => $result['values'][$token], '@expected' => $expected)));
+      }
+    }
+  }
+}
diff --git a/lib/Drupal/token/Tests/TokenURLTestCase.php b/lib/Drupal/token/Tests/TokenURLTestCase.php
new file mode 100644
index 0000000..e2f37b1
--- /dev/null
+++ b/lib/Drupal/token/Tests/TokenURLTestCase.php
@@ -0,0 +1,47 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Tests\TokenURLTestCase.
+ */
+namespace Drupal\token\Tests;
+
+/**
+ * Tests url tokens.
+ */
+class TokenURLTestCase extends TokenTestBase {
+  public static function getInfo() {
+    return array(
+      'name' => 'URL token tests',
+      'description' => 'Test the URL tokens.',
+      'group' => 'Token',
+    );
+  }
+
+  public function setUp($modules = array()) {
+    parent::setUp($modules);
+    $this->saveAlias('node/1', 'first-node');
+  }
+
+  function testURLTokens() {
+    $tokens = array(
+      'absolute' => 'http://example.com/first-node',
+      'relative' => base_path() . 'first-node',
+      'path' => 'first-node',
+      'brief' => 'example.com/first-node',
+      'args:value:0' => 'first-node',
+      'args:value:1' => NULL,
+      'args:value:N' => NULL,
+      'unaliased' => 'http://example.com/node/1',
+      'unaliased:relative' => base_path() . 'node/1',
+      'unaliased:path' => 'node/1',
+      'unaliased:brief' => 'example.com/node/1',
+      'unaliased:args:value:0' => 'node',
+      'unaliased:args:value:1' => '1',
+      'unaliased:args:value:2' => NULL,
+      // Deprecated tokens.
+      'alias' => 'first-node',
+    );
+    $this->assertTokens('url', array('path' => 'node/1', 'options' => array('base_url' => 'http://example.com')), $tokens);
+  }
+}
diff --git a/lib/Drupal/token/Tests/TokenUnitTestCase.php b/lib/Drupal/token/Tests/TokenUnitTestCase.php
new file mode 100644
index 0000000..96d09ee
--- /dev/null
+++ b/lib/Drupal/token/Tests/TokenUnitTestCase.php
@@ -0,0 +1,94 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Tests\TokenUnitTestCase.
+ */
+namespace Drupal\token\Tests;
+
+/**
+ * Token unit tests.
+ */
+class TokenUnitTestCase extends TokenTestBase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Token unit tests',
+      'description' => 'Test basic, low-level token functions.',
+      'group' => 'Token',
+    );
+  }
+
+  /**
+   * Test token_get_invalid_tokens() and token_get_invalid_tokens_by_context().
+   */
+  public function testGetInvalidTokens() {
+    $tests = array();
+    $tests[] = array(
+      'valid tokens' => array(
+        '[node:title]',
+        '[node:created:short]',
+        '[node:created:custom:invalid]',
+        '[node:created:custom:mm-YYYY]',
+        '[site:name]',
+        '[site:slogan]',
+        '[current-date:short]',
+        '[current-user:uid]',
+        '[current-user:ip-address]',
+      ),
+      'invalid tokens' => array(
+        '[node:title:invalid]',
+        '[node:created:invalid]',
+        '[node:created:short:invalid]',
+        '[invalid:title]',
+        '[site:invalid]',
+        '[user:ip-address]',
+        '[user:uid]',
+        '[comment:cid]',
+        // Deprecated tokens
+        '[node:tnid]',
+        '[node:type]',
+        '[node:type-name]',
+        '[date:short]',
+      ),
+      'types' => array('node'),
+    );
+    $tests[] = array(
+      'valid tokens' => array(
+        '[node:title]',
+        '[node:created:short]',
+        '[node:created:custom:invalid]',
+        '[node:created:custom:mm-YYYY]',
+        '[site:name]',
+        '[site:slogan]',
+        '[user:uid]',
+        '[current-date:short]',
+        '[current-user:uid]',
+      ),
+      'invalid tokens' => array(
+        '[node:title:invalid]',
+        '[node:created:invalid]',
+        '[node:created:short:invalid]',
+        '[invalid:title]',
+        '[site:invalid]',
+        '[user:ip-address]',
+        '[comment:cid]',
+        // Deprecated tokens
+        '[node:tnid]',
+        '[node:type]',
+        '[node:type-name]',
+      ),
+      'types' => array('all'),
+    );
+
+    foreach ($tests as $test) {
+      $tokens = array_merge($test['valid tokens'], $test['invalid tokens']);
+      shuffle($tokens);
+
+      $invalid_tokens = token_get_invalid_tokens_by_context(implode(' ', $tokens), $test['types']);
+
+      sort($invalid_tokens);
+      sort($test['invalid tokens']);
+      $this->assertEqual($invalid_tokens, $test['invalid tokens'], 'Invalid tokens detected properly: ' . implode(', ', $invalid_tokens));
+    }
+  }
+}
diff --git a/lib/Drupal/token/Tests/TokenUserTestCase.php b/lib/Drupal/token/Tests/TokenUserTestCase.php
new file mode 100644
index 0000000..b348050
--- /dev/null
+++ b/lib/Drupal/token/Tests/TokenUserTestCase.php
@@ -0,0 +1,92 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Tests\TokenUserTestCase.
+ */
+namespace Drupal\token\Tests;
+
+/**
+ * Tests user tokens.
+ */
+class TokenUserTestCase extends TokenTestBase {
+  protected $account = NULL;
+
+  public static function getInfo() {
+    return array(
+      'name' => 'User token tests',
+      'description' => 'Test the user tokens.',
+      'group' => 'Token',
+    );
+  }
+
+  public function setUp($modules = array()) {
+    parent::setUp($modules);
+
+    // Enable user pictures.
+    variable_set('user_pictures', 1);
+    variable_set('user_picture_file_size', '');
+
+    // Set up the pictures directory.
+    $picture_path = file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures');
+    if (!file_prepare_directory($picture_path, FILE_CREATE_DIRECTORY)) {
+      $this->fail('Could not create directory ' . $picture_path . '.');
+    }
+
+    $this->account = $this->drupalCreateUser(array('administer users'));
+    $this->drupalLogin($this->account);
+  }
+
+  function testUserTokens() {
+    // Add a user picture to the account.
+    $image = current($this->drupalGetTestFiles('image'));
+    $edit = array('files[picture_upload]' => drupal_realpath($image->uri));
+    $this->drupalPost('user/' . $this->account->uid . '/edit', $edit, t('Save'));
+
+    // Load actual user data from database.
+    $this->account = user_load($this->account->uid, TRUE);
+    $this->assertTrue(!empty($this->account->picture->fid), 'User picture uploaded.');
+
+    $user_tokens = array(
+      'picture' => theme('user_picture', array('account' => $this->account)),
+      'picture:fid' => $this->account->picture->fid,
+      'picture:size-raw' => 125,
+      'ip-address' => NULL,
+      'roles' => implode(', ', $this->account->roles),
+      'roles:keys' => implode(', ', array_keys($this->account->roles)),
+    );
+    $this->assertTokens('user', array('user' => $this->account), $user_tokens);
+
+    $edit = array('user_pictures' => FALSE);
+    $this->drupalPost('admin/config/people/accounts', $edit, 'Save configuration');
+    $this->assertText('The configuration options have been saved.');
+
+    // Remove the simpletest-created user role.
+    user_role_delete(end($this->account->roles));
+    $this->account = user_load($this->account->uid, TRUE);
+
+    $user_tokens = array(
+      'picture' => NULL,
+      'picture:fid' => NULL,
+      'ip-address' => NULL,
+      'roles' => 'authenticated user',
+      'roles:keys' => (string) DRUPAL_AUTHENTICATED_RID,
+    );
+    $this->assertTokens('user', array('user' => $this->account), $user_tokens);
+
+    // The ip address token should work for the current user token type.
+    $tokens = array(
+      'ip-address' => ip_address(),
+    );
+    $this->assertTokens('current-user', array(), $tokens);
+
+    $anonymous = drupal_anonymous_user();
+    // Mess with the role array to ensure we still get consistent output.
+    $anonymous->roles[DRUPAL_ANONYMOUS_RID] = DRUPAL_ANONYMOUS_RID;
+    $tokens = array(
+      'roles' => 'anonymous user',
+      'roles:keys' => (string) DRUPAL_ANONYMOUS_RID,
+    );
+    $this->assertTokens('user', array('user' => $anonymous), $tokens);
+  }
+}
diff --git a/token.test b/token.test
deleted file mode 100644
index 830e12a..0000000
--- a/token.test
+++ /dev/null
@@ -1,1087 +0,0 @@
-<?php
-
-/**
- * @file
- * Test integration for the token module.
- */
-
-/**
- * Helper test class with some added functions for testing.
- */
-class TokenTestHelper extends DrupalWebTestCase {
-  protected $profile = 'testing';
-
-  public function setUp($modules = array()) {
-    $modules[] = 'path';
-    $modules[] = 'token';
-    $modules[] = 'token_test';
-    parent::setUp($modules);
-
-    variable_set('clean_url', 1);
-  }
-
-  function assertToken($type, array $data, $token, $expected, array $options = array()) {
-    return $this->assertTokens($type, $data, array($token => $expected), $options);
-  }
-
-  function assertTokens($type, array $data, array $tokens, array $options = array()) {
-    $input = $this->mapTokenNames($type, array_keys($tokens));
-    $replacements = token_generate($type, $input, $data, $options);
-    foreach ($tokens as $name => $expected) {
-      $token = $input[$name];
-      if (!isset($expected)) {
-        $this->assertTrue(!isset($values[$token]), t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token)));
-      }
-      elseif (!isset($replacements[$token])) {
-        $this->fail(t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token)));
-      }
-      elseif (!empty($options['regex'])) {
-        $this->assertTrue(preg_match('/^' . $expected . '$/', $replacements[$token]), t("Token value for @token was '@actual', matching regular expression pattern '@expected'.", array('@type' => $type, '@token' => $token, '@actual' => $replacements[$token], '@expected' => $expected)));
-      }
-      else {
-        $this->assertIdentical($replacements[$token], $expected, t("Token value for @token was '@actual', expected value '@expected'.", array('@type' => $type, '@token' => $token, '@actual' => $replacements[$token], '@expected' => $expected)));
-      }
-    }
-
-    return $replacements;
-  }
-
-  function mapTokenNames($type, array $tokens = array()) {
-    $return = array();
-    foreach ($tokens as $token) {
-      $return[$token] = "[$type:$token]";
-    }
-    return $return;
-  }
-
-  function assertNoTokens($type, array $data, array $tokens, array $options = array()) {
-    $input = $this->mapTokenNames($type, $tokens);
-    $replacements = token_generate($type, $input, $data, $options);
-    foreach ($tokens as $name) {
-      $token = $input[$name];
-      $this->assertTrue(!isset($replacements[$token]), t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token)));
-    }
-    return $values;
-  }
-
-  function saveAlias($source, $alias, $language = LANGUAGE_NOT_SPECIFIED) {
-    $alias = array(
-      'source' => $source,
-      'alias' => $alias,
-      'language' => $language,
-    );
-    path_save($alias);
-    return $alias;
-  }
-
-  function saveEntityAlias($entity_type, $entity, $alias, $language = LANGUAGE_NOT_SPECIFIED) {
-    $uri = entity_uri($entity_type, $entity);
-    return $this->saveAlias($uri['path'], $alias, $language);
-  }
-
-  /**
-   * Make a page request and test for token generation.
-   */
-  function assertPageTokens($url, array $tokens, array $data = array(), array $options = array()) {
-    if (empty($tokens)) {
-      return TRUE;
-    }
-
-    $token_page_tokens = array(
-      'tokens' => $tokens,
-      'data' => $data,
-      'options' => $options,
-    );
-    variable_set('token_page_tokens', $token_page_tokens);
-
-    $options += array('url_options' => array());
-    $this->drupalGet($url, $options['url_options']);
-    $this->refreshVariables();
-    $result = variable_get('token_page_tokens', array());
-
-    if (!isset($result['values']) || !is_array($result['values'])) {
-      return $this->fail('Failed to generate tokens.');
-    }
-
-    foreach ($tokens as $token => $expected) {
-      if (!isset($expected)) {
-        $this->assertTrue(!isset($result['values'][$token]) || $result['values'][$token] === $token, t("Token value for @token was not generated.", array('@token' => $token)));
-      }
-      elseif (!isset($result['values'][$token])) {
-        $this->fail(t('Failed to generate token @token.', array('@token' => $token)));
-      }
-      else {
-        $this->assertIdentical($result['values'][$token], (string) $expected, t("Token value for @token was '@actual', expected value '@expected'.", array('@token' => $token, '@actual' => $result['values'][$token], '@expected' => $expected)));
-      }
-    }
-  }
-}
-
-class TokenUnitTestCase extends TokenTestHelper {
-  public static function getInfo() {
-    return array(
-      'name' => 'Token unit tests',
-      'description' => 'Test basic, low-level token functions.',
-      'group' => 'Token',
-    );
-  }
-
-  /**
-   * Test token_get_invalid_tokens() and token_get_invalid_tokens_by_context().
-   */
-  public function testGetInvalidTokens() {
-    $tests = array();
-    $tests[] = array(
-      'valid tokens' => array(
-        '[node:title]',
-        '[node:created:short]',
-        '[node:created:custom:invalid]',
-        '[node:created:custom:mm-YYYY]',
-        '[site:name]',
-        '[site:slogan]',
-        '[current-date:short]',
-        '[current-user:uid]',
-        '[current-user:ip-address]',
-      ),
-      'invalid tokens' => array(
-        '[node:title:invalid]',
-        '[node:created:invalid]',
-        '[node:created:short:invalid]',
-        '[invalid:title]',
-        '[site:invalid]',
-        '[user:ip-address]',
-        '[user:uid]',
-        '[comment:cid]',
-        // Deprecated tokens
-        '[node:tnid]',
-        '[node:type]',
-        '[node:type-name]',
-        '[date:short]',
-      ),
-      'types' => array('node'),
-    );
-    $tests[] = array(
-      'valid tokens' => array(
-        '[node:title]',
-        '[node:created:short]',
-        '[node:created:custom:invalid]',
-        '[node:created:custom:mm-YYYY]',
-        '[site:name]',
-        '[site:slogan]',
-        '[user:uid]',
-        '[current-date:short]',
-        '[current-user:uid]',
-      ),
-      'invalid tokens' => array(
-        '[node:title:invalid]',
-        '[node:created:invalid]',
-        '[node:created:short:invalid]',
-        '[invalid:title]',
-        '[site:invalid]',
-        '[user:ip-address]',
-        '[comment:cid]',
-        // Deprecated tokens
-        '[node:tnid]',
-        '[node:type]',
-        '[node:type-name]',
-      ),
-      'types' => array('all'),
-    );
-
-    foreach ($tests as $test) {
-      $tokens = array_merge($test['valid tokens'], $test['invalid tokens']);
-      shuffle($tokens);
-
-      $invalid_tokens = token_get_invalid_tokens_by_context(implode(' ', $tokens), $test['types']);
-
-      sort($invalid_tokens);
-      sort($test['invalid tokens']);
-      $this->assertEqual($invalid_tokens, $test['invalid tokens'], 'Invalid tokens detected properly: ' . implode(', ', $invalid_tokens));
-    }
-  }
-}
-
-class TokenURLTestCase extends TokenTestHelper {
-  public static function getInfo() {
-    return array(
-      'name' => 'URL token tests',
-      'description' => 'Test the URL tokens.',
-      'group' => 'Token',
-    );
-  }
-
-  public function setUp($modules = array()) {
-    parent::setUp($modules);
-    $this->saveAlias('node/1', 'first-node');
-  }
-
-  function testURLTokens() {
-    $tokens = array(
-      'absolute' => 'http://example.com/first-node',
-      'relative' => base_path() . 'first-node',
-      'path' => 'first-node',
-      'brief' => 'example.com/first-node',
-      'args:value:0' => 'first-node',
-      'args:value:1' => NULL,
-      'args:value:N' => NULL,
-      'unaliased' => 'http://example.com/node/1',
-      'unaliased:relative' => base_path() . 'node/1',
-      'unaliased:path' => 'node/1',
-      'unaliased:brief' => 'example.com/node/1',
-      'unaliased:args:value:0' => 'node',
-      'unaliased:args:value:1' => '1',
-      'unaliased:args:value:2' => NULL,
-      // Deprecated tokens.
-      'alias' => 'first-node',
-    );
-    $this->assertTokens('url', array('path' => 'node/1', 'options' => array('base_url' => 'http://example.com')), $tokens);
-  }
-}
-
-class TokenCommentTestCase extends TokenTestHelper {
-  public static function getInfo() {
-    return array(
-      'name' => 'Comment token tests',
-      'description' => 'Test the comment tokens.',
-      'group' => 'Token',
-    );
-  }
-
-  public function setUp($modules = array()) {
-    $modules[] = 'comment';
-    parent::setUp($modules);
-  }
-
-  function testCommentTokens() {
-    $node = $this->drupalCreateNode(array('comment' => COMMENT_NODE_OPEN));
-
-    $parent_comment = new stdClass;
-    $parent_comment->nid = $node->nid;
-    $parent_comment->pid = 0;
-    $parent_comment->cid = NULL;
-    $parent_comment->uid = 0;
-    $parent_comment->name = 'anonymous user';
-    $parent_comment->mail = 'anonymous@example.com';
-    $parent_comment->subject = $this->randomName();
-    $parent_comment->timestamp = mt_rand($node->created, REQUEST_TIME);
-    $parent_comment->language = LANGUAGE_NOT_SPECIFIED;
-    $parent_comment->body[LANGUAGE_NOT_SPECIFIED][0] = $this->randomName();
-    comment_save($parent_comment);
-
-    $tokens = array(
-      'url' => url('comment/' . $parent_comment->cid, array('fragment' => 'comment-' . $parent_comment->cid, 'absolute' => TRUE)),
-      'url:absolute' => url('comment/' . $parent_comment->cid, array('fragment' => 'comment-' . $parent_comment->cid, 'absolute' => TRUE)),
-      'url:relative' => url('comment/' . $parent_comment->cid, array('fragment' => 'comment-' . $parent_comment->cid, 'absolute' => FALSE)),
-      'url:path' => 'comment/' . $parent_comment->cid,
-      'parent:url:absolute' => NULL,
-    );
-    $this->assertTokens('comment', array('comment' => $parent_comment), $tokens);
-
-    $comment = new stdClass();
-    $comment->nid = $node->nid;
-    $comment->pid = $parent_comment->cid;
-    $comment->cid = NULL;
-    $comment->uid = 1;
-    $comment->subject = $this->randomName();
-    $comment->timestamp = mt_rand($parent_comment->created, REQUEST_TIME);
-    $comment->language = LANGUAGE_NOT_SPECIFIED;
-    $comment->body[LANGUAGE_NOT_SPECIFIED][0] = $this->randomName();
-    comment_save($comment);
-
-    $tokens = array(
-      'url' => url('comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid, 'absolute' => TRUE)),
-      'url:absolute' => url('comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid, 'absolute' => TRUE)),
-      'url:relative' => url('comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid, 'absolute' => FALSE)),
-      'url:path' => 'comment/' . $comment->cid,
-      'parent:url:absolute' => url('comment/' . $parent_comment->cid, array('fragment' => 'comment-' . $parent_comment->cid, 'absolute' => TRUE)),
-    );
-    $this->assertTokens('comment', array('comment' => $comment), $tokens);
-  }
-}
-
-class TokenNodeTestCase extends TokenTestHelper {
-  protected $profile = 'standard';
-
-  public static function getInfo() {
-    return array(
-      'name' => 'Node and content type token tests',
-      'description' => 'Test the node and content type tokens.',
-      'group' => 'Token',
-    );
-  }
-
-  function testNodeTokens() {
-    $source_node = $this->drupalCreateNode(array('log' => $this->randomName(), 'path' => array('alias' => 'content/source-node')));
-    $tokens = array(
-      'source' => NULL,
-      'source:nid' => NULL,
-      'log' => $source_node->log,
-      'url:path' => 'content/source-node',
-      'url:absolute' => url("node/{$source_node->nid}", array('absolute' => TRUE)),
-      'url:relative' => url("node/{$source_node->nid}", array('absolute' => FALSE)),
-      'url:unaliased:path' => "node/{$source_node->nid}",
-      'content-type' => 'Basic page',
-      'content-type:name' => 'Basic page',
-      'content-type:machine-name' => 'page',
-      'content-type:description' => "Use <em>basic pages</em> for your static content, such as an 'About us' page.",
-      'content-type:node-count' => 1,
-      'content-type:edit-url' => url('admin/structure/types/manage/page', array('absolute' => TRUE)),
-      // Deprecated tokens.
-      'tnid' => 0,
-      'type' => 'page',
-      'type-name' => 'Basic page',
-      'url:alias' => 'content/source-node',
-    );
-    $this->assertTokens('node', array('node' => $source_node), $tokens);
-
-    $translated_node = $this->drupalCreateNode(array('tnid' => $source_node->nid, 'type' => 'article'));
-    $tokens = array(
-      'source' => $source_node->title,
-      'source:nid' => $source_node->nid,
-      'log' => '',
-      'url:path' => "node/{$translated_node->nid}",
-      'url:absolute' => url("node/{$translated_node->nid}", array('absolute' => TRUE)),
-      'url:relative' => url("node/{$translated_node->nid}", array('absolute' => FALSE)),
-      'url:unaliased:path' => "node/{$translated_node->nid}",
-      'content-type' => 'Article',
-      'content-type:name' => 'Article',
-      'content-type:machine-name' => 'article',
-      'content-type:description' => "Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.",
-      'content-type:node-count' => 1,
-      'content-type:edit-url' => url('admin/structure/types/manage/article', array('absolute' => TRUE)),
-      // Deprecated tokens.
-      'type' => 'article',
-      'type-name' => 'Article',
-      'tnid' => $source_node->nid,
-      'url:alias' => "node/{$translated_node->nid}",
-    );
-    $this->assertTokens('node', array('node' => $translated_node), $tokens);
-  }
-}
-
-class TokenMenuTestCase extends TokenTestHelper {
-  public static function getInfo() {
-    return array(
-      'name' => 'Menu link and menu token tests',
-      'description' => 'Test the menu tokens.',
-      'group' => 'Token',
-    );
-  }
-
-  public function setUp($modules = array()) {
-    $modules[] = 'menu';
-    parent::setUp($modules);
-  }
-
-  function testMenuTokens() {
-    // Add a root link.
-    $root_link = array(
-      'link_path' => 'root',
-      'link_title' => 'Root link',
-      'menu_name' => 'main-menu',
-    );
-    menu_link_save($root_link);
-
-    // Add another link with the root link as the parent
-    $parent_link = array(
-      'link_path' => 'root/parent',
-      'link_title' => 'Parent link',
-      'menu_name' => 'main-menu',
-      'plid' => $root_link['mlid'],
-    );
-    menu_link_save($parent_link);
-
-    // Test menu link tokens.
-    $tokens = array(
-      'mlid' => $parent_link['mlid'],
-      'title' => 'Parent link',
-      'menu' => 'Main menu',
-      'menu:name' => 'Main menu',
-      'menu:machine-name' => 'main-menu',
-      'menu:description' => 'The <em>Main</em> menu is used on many sites to show the major sections of the site, often in a top navigation bar.',
-      'menu:menu-link-count' => 2,
-      'menu:edit-url' => url("admin/structure/menu/manage/main-menu", array('absolute' => TRUE)),
-      'url' => url('root/parent', array('absolute' => TRUE)),
-      'url:absolute' => url('root/parent', array('absolute' => TRUE)),
-      'url:relative' => url('root/parent', array('absolute' => FALSE)),
-      'url:path' => 'root/parent',
-      'url:alias' => 'root/parent',
-      'edit-url' => url("admin/structure/menu/item/{$parent_link['mlid']}/edit", array('absolute' => TRUE)),
-      'parent' => 'Root link',
-      'parent:mlid' => $root_link['mlid'],
-      'parent:title' => 'Root link',
-      'parent:menu' => 'Main menu',
-      'parent:parent' => NULL,
-      'parents' => 'Root link',
-      'parents:count' => 1,
-      'parents:keys' => $root_link['mlid'],
-      'root' => 'Root link',
-      'root:mlid' => $root_link['mlid'],
-      'root:parent' => NULL,
-      'root:root' => NULL,
-    );
-    $this->assertTokens('menu-link', array('menu-link' => $parent_link), $tokens);
-
-    // Add a node menu link
-    $node_link = array(
-      'enabled' => TRUE,
-      'link_title' => 'Node link',
-      'plid' => $parent_link['mlid'],
-      'customized' => 0,
-      'description' => '',
-    );
-    $node = $this->drupalCreateNode(array('menu' => $node_link));
-
-    // Test [node:menu] tokens.
-    $tokens = array(
-      'menu-link' => 'Node link',
-      'menu-link:mlid' => $node->menu['mlid'],
-      'menu-link:title' => 'Node link',
-      'menu-link:menu' => 'Main menu',
-      'menu-link:url' => url('node/' . $node->nid, array('absolute' => TRUE)),
-      'menu-link:url:path' => 'node/' . $node->nid,
-      'menu-link:edit-url' => url("admin/structure/menu/item/{$node->menu['mlid']}/edit", array('absolute' => TRUE)),
-      'menu-link:parent' => 'Parent link',
-      'menu-link:parent:mlid' => $node->menu['plid'],
-      'menu-link:parent:mlid' => $parent_link['mlid'],
-      'menu-link:parents' => 'Root link, Parent link',
-      'menu-link:parents:count' => 2,
-      'menu-link:parents:keys' => $root_link['mlid'] . ', ' . $parent_link['mlid'],
-      'menu-link:root' => 'Root link',
-      'menu-link:root:mlid' => $root_link['mlid'],
-    );
-    $this->assertTokens('node', array('node' => $node), $tokens);
-
-    // Reload the node which will not have $node->menu defined and re-test.
-    $loaded_node = node_load($node->nid);
-    $this->assertTokens('node', array('node' => $loaded_node), $tokens);
-
-    // Regression test for http://drupal.org/node/1317926 to ensure the
-    // original node object is not changed when calling menu_node_prepare().
-    $this->assertTrue(!isset($loaded_node->menu), t('The $node->menu property was not modified during token replacement.'), 'Regression');
-  }
-}
-
-class TokenTaxonomyTestCase extends TokenTestHelper {
-  protected $vocab;
-
-  public static function getInfo() {
-    return array(
-      'name' => 'Taxonomy and vocabulary token tests',
-      'description' => 'Test the taxonomy tokens.',
-      'group' => 'Token',
-    );
-  }
-
-  public function setUp($modules = array()) {
-    $modules[] = 'taxonomy';
-    parent::setUp($modules);
-
-    // Create the default tags vocabulary.
-    $vocabulary = entity_create('taxonomy_vocabulary', array(
-      'name' => 'Tags',
-      'machine_name' => 'tags',
-    ));
-    taxonomy_vocabulary_save($vocabulary);
-    $this->vocab = $vocabulary;
-  }
-
-  /**
-   * Test the additional taxonomy term tokens.
-   */
-  function testTaxonomyTokens() {
-    $root_term = $this->addTerm($this->vocab, array('name' => 'Root term', 'path' => array('alias' => 'root-term')));
-    $tokens = array(
-      'url' => url("taxonomy/term/{$root_term->tid}", array('absolute' => TRUE)),
-      'url:absolute' => url("taxonomy/term/{$root_term->tid}", array('absolute' => TRUE)),
-      'url:relative' => url("taxonomy/term/{$root_term->tid}", array('absolute' => FALSE)),
-      'url:path' => 'root-term',
-      'url:unaliased:path' => "taxonomy/term/{$root_term->tid}",
-      'edit-url' => url("taxonomy/term/{$root_term->tid}/edit", array('absolute' => TRUE)),
-      'parents' => NULL,
-      'parents:count' => NULL,
-      'parents:keys' => NULL,
-      'root' => NULL,
-      // Deprecated tokens
-      'url:alias' => 'root-term',
-    );
-    $this->assertTokens('term', array('term' => $root_term), $tokens);
-
-    $parent_term = $this->addTerm($this->vocab, array('name' => 'Parent term', 'parent' => $root_term->tid));
-    $tokens = array(
-      'url' => url("taxonomy/term/{$parent_term->tid}", array('absolute' => TRUE)),
-      'url:absolute' => url("taxonomy/term/{$parent_term->tid}", array('absolute' => TRUE)),
-      'url:relative' => url("taxonomy/term/{$parent_term->tid}", array('absolute' => FALSE)),
-      'url:path' => "taxonomy/term/{$parent_term->tid}",
-      'url:unaliased:path' => "taxonomy/term/{$parent_term->tid}",
-      'edit-url' => url("taxonomy/term/{$parent_term->tid}/edit", array('absolute' => TRUE)),
-      'parents' => 'Root term',
-      'parents:count' => 1,
-      'parents:keys' => $root_term->tid,
-      'root' => check_plain($root_term->name),
-      'root:tid' => $root_term->tid,
-      // Deprecated tokens
-      'url:alias' => "taxonomy/term/{$parent_term->tid}",
-    );
-    $this->assertTokens('term', array('term' => $parent_term), $tokens);
-
-    $term = $this->addTerm($this->vocab, array('name' => 'Test term', 'parent' => $parent_term->tid));
-    $tokens = array(
-      'parents' => 'Root term, Parent term',
-      'parents:count' => 2,
-      'parents:keys' => implode(', ', array($root_term->tid, $parent_term->tid)),
-    );
-    $this->assertTokens('term', array('term' => $term), $tokens);
-  }
-
-  /**
-   * Test the additional vocabulary tokens.
-   */
-  function testVocabularyTokens() {
-    $vocabulary = $this->vocab;
-    $tokens = array(
-      'machine-name' => 'tags',
-      'edit-url' => url("admin/structure/taxonomy/{$vocabulary->machine_name}/edit", array('absolute' => TRUE)),
-    );
-    $this->assertTokens('vocabulary', array('vocabulary' => $vocabulary), $tokens);
-  }
-
-  function addVocabulary(array $vocabulary = array()) {
-    $vocabulary += array(
-      'name' => drupal_strtolower($this->randomName(5)),
-      'nodes' => array('article' => 'article'),
-    );
-    $vocabulary = entity_create('taxonomy_vocabulary', $vocabulary);
-    taxonomy_vocabulary_save($vocabulary);
-    return $vocabulary;
-  }
-
-  function addTerm(stdClass $vocabulary, array $term = array()) {
-    $term += array(
-      'name' => drupal_strtolower($this->randomName(5)),
-      'vid' => $vocabulary->vid,
-    );
-    $term = entity_create('taxonomy_term', $term);
-    taxonomy_term_save($term);
-    return $term;
-  }
-}
-
-class TokenUserTestCase extends TokenTestHelper {
-  protected $account = NULL;
-
-  public static function getInfo() {
-    return array(
-      'name' => 'User token tests',
-      'description' => 'Test the user tokens.',
-      'group' => 'Token',
-    );
-  }
-
-  public function setUp($modules = array()) {
-    parent::setUp($modules);
-
-    // Enable user pictures.
-    variable_set('user_pictures', 1);
-    variable_set('user_picture_file_size', '');
-
-    // Set up the pictures directory.
-    $picture_path = file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures');
-    if (!file_prepare_directory($picture_path, FILE_CREATE_DIRECTORY)) {
-      $this->fail('Could not create directory ' . $picture_path . '.');
-    }
-
-    $this->account = $this->drupalCreateUser(array('administer users'));
-    $this->drupalLogin($this->account);
-  }
-
-  function testUserTokens() {
-    // Add a user picture to the account.
-    $image = current($this->drupalGetTestFiles('image'));
-    $edit = array('files[picture_upload]' => drupal_realpath($image->uri));
-    $this->drupalPost('user/' . $this->account->uid . '/edit', $edit, t('Save'));
-
-    // Load actual user data from database.
-    $this->account = user_load($this->account->uid, TRUE);
-    $this->assertTrue(!empty($this->account->picture->fid), 'User picture uploaded.');
-
-    $user_tokens = array(
-      'picture' => theme('user_picture', array('account' => $this->account)),
-      'picture:fid' => $this->account->picture->fid,
-      'picture:size-raw' => 125,
-      'ip-address' => NULL,
-      'roles' => implode(', ', $this->account->roles),
-      'roles:keys' => implode(', ', array_keys($this->account->roles)),
-    );
-    $this->assertTokens('user', array('user' => $this->account), $user_tokens);
-
-    $edit = array('user_pictures' => FALSE);
-    $this->drupalPost('admin/config/people/accounts', $edit, 'Save configuration');
-    $this->assertText('The configuration options have been saved.');
-
-    // Remove the simpletest-created user role.
-    user_role_delete(end($this->account->roles));
-    $this->account = user_load($this->account->uid, TRUE);
-
-    $user_tokens = array(
-      'picture' => NULL,
-      'picture:fid' => NULL,
-      'ip-address' => NULL,
-      'roles' => 'authenticated user',
-      'roles:keys' => (string) DRUPAL_AUTHENTICATED_RID,
-    );
-    $this->assertTokens('user', array('user' => $this->account), $user_tokens);
-
-    // The ip address token should work for the current user token type.
-    $tokens = array(
-      'ip-address' => ip_address(),
-    );
-    $this->assertTokens('current-user', array(), $tokens);
-
-    $anonymous = drupal_anonymous_user();
-    // Mess with the role array to ensure we still get consistent output.
-    $anonymous->roles[DRUPAL_ANONYMOUS_RID] = DRUPAL_ANONYMOUS_RID;
-    $tokens = array(
-      'roles' => 'anonymous user',
-      'roles:keys' => (string) DRUPAL_ANONYMOUS_RID,
-    );
-    $this->assertTokens('user', array('user' => $anonymous), $tokens);
-  }
-}
-
-class TokenEntityTestCase extends TokenTestHelper {
-  public static function getInfo() {
-    return array(
-      'name' => 'Entity token tests',
-      'description' => 'Test the entity tokens.',
-      'group' => 'Token',
-    );
-  }
-
-  public function setUp($modules = array()) {
-    $modules[] = 'taxonomy';
-    parent::setUp($modules);
-
-    // Create the default tags vocabulary.
-    $vocabulary = entity_create('taxonomy_vocabulary', array(
-      'name' => 'Tags',
-      'machine_name' => 'tags',
-    ));
-    taxonomy_vocabulary_save($vocabulary);
-    $this->vocab = $vocabulary;
-  }
-
-  function testEntityMapping() {
-    $this->assertIdentical(token_get_entity_mapping('token', 'node'), 'node');
-    $this->assertIdentical(token_get_entity_mapping('token', 'term'), 'taxonomy_term');
-    $this->assertIdentical(token_get_entity_mapping('token', 'vocabulary'), 'taxonomy_vocabulary');
-    $this->assertIdentical(token_get_entity_mapping('token', 'invalid'), FALSE);
-    $this->assertIdentical(token_get_entity_mapping('entity', 'node'), 'node');
-    $this->assertIdentical(token_get_entity_mapping('entity', 'taxonomy_term'), 'term');
-    $this->assertIdentical(token_get_entity_mapping('entity', 'taxonomy_vocabulary'), 'vocabulary');
-    $this->assertIdentical(token_get_entity_mapping('entity', 'invalid'), FALSE);
-
-    // Test that when we send the mis-matched entity type into token_replace()
-    // that we still get the tokens replaced.
-    $vocabulary = taxonomy_vocabulary_machine_name_load('tags');
-    $term = $this->addTerm($vocabulary);
-    $this->assertIdentical(token_replace('[vocabulary:name]', array('taxonomy_vocabulary' => $vocabulary)), $vocabulary->name);
-    $this->assertIdentical(token_replace('[term:name][term:vocabulary:name]', array('taxonomy_term' => $term)), $term->name . $vocabulary->name);
-  }
-
-  function addTerm(TaxonomyVocabulary $vocabulary, array $term = array()) {
-    $term += array(
-      'name' => drupal_strtolower($this->randomName(5)),
-      'vid' => $vocabulary->vid,
-    );
-    $term = entity_create('taxonomy_term', $term);
-    taxonomy_term_save($term);
-    return $term;
-  }
-
-  /**
-   * Test the [entity:original:*] tokens.
-   */
-  function testEntityOriginal() {
-    $node = $this->drupalCreateNode(array('title' => 'Original title'));
-
-    $tokens = array(
-      'nid' => $node->nid,
-      'title' => 'Original title',
-      'original' => NULL,
-      'original:nid' => NULL,
-    );
-    $this->assertTokens('node', array('node' => $node), $tokens);
-
-    // Emulate the original entity property that would be available from
-    // node_save() and change the title for the node.
-    $node->original = entity_load_unchanged('node', $node->nid);
-    $node->title = 'New title';
-
-    $tokens = array(
-      'nid' => $node->nid,
-      'title' => 'New title',
-      'original' => 'Original title',
-      'original:nid' => $node->nid,
-    );
-    $this->assertTokens('node', array('node' => $node), $tokens);
-  }
-}
-
-/**
- * Test the profile tokens.
- */
-class TokenProfileTestCase extends TokenTestHelper {
-  private $account;
-
-  public static function getInfo() {
-    return array(
-      'name' => 'Profile token tests',
-      'description' => 'Test the profile tokens.',
-      'group' => 'Token',
-    );
-  }
-
-  public function setUp($modules = array()) {
-    $modules[] = 'profile';
-    parent::setUp($modules);
-    $this->account = $this->drupalCreateUser(array('administer users'));
-    $this->drupalLogin($this->account);
-  }
-
-  /**
-   * Test the profile tokens.
-   */
-  function testProfileTokens() {
-    $field_types = _profile_field_types();
-    foreach (array_keys($field_types) as $field_type) {
-      $field = array();
-      switch ($field_type) {
-        case 'checkbox':
-          $field['title'] = 'This is a checkbox';
-          break;
-        case 'selection':
-          $field['options'] = implode("\n", array('Red', 'Blue', 'Green'));
-          break;
-      }
-      $this->addProfileField($field_type, $field);
-    }
-
-    // Submit the profile fields for the user.
-    $edit = array(
-      'profile_textfield' => 'This is a text field',
-      'profile_textarea' => "First paragraph.\n\nSecond paragraph.",
-      'profile_checkbox' => TRUE,
-      'profile_selection' => 'Red',
-      'profile_list' => ' Drupal ,  Joomla ',
-      'profile_url' => 'http://www.example.com/',
-      'profile_date[month]' => 5,
-      'profile_date[day]' => 20,
-      'profile_date[year]' => 1984,
-    );
-    $this->drupalPost("user/{$this->account->uid}/edit/SimpleTest", $edit, 'Save');
-    $account = user_load($this->account->uid, TRUE);
-
-    // Test the profile token values.
-    $tokens = array(
-      'profile-textfield' => 'This is a text field',
-      'profile-textarea' => "<p>First paragraph.</p>\n<p>Second paragraph.</p>\n",
-      'profile-checkbox' => 'This is a checkbox',
-      'profile-selection' => 'Red',
-      'profile-list' => 'Drupal, Joomla',
-      'profile-url' => 'http://www.example.com/',
-      'profile-date' => format_date(453859200, 'medium', '', NULL),
-      'profile-date:raw' => '453859200',
-      'profile-date:custom:Y' => '1984',
-    );
-    $this->assertTokens('user', array('user' => $account), $tokens);
-
-    // 'Un-select' the checkbox and select profile fields.
-    $edit = array(
-      'profile_checkbox' => FALSE,
-      'profile_selection' => '0',
-    );
-    $this->drupalPost("user/{$this->account->uid}/edit/SimpleTest", $edit, 'Save');
-    $account = user_load($this->account->uid, TRUE);
-
-    // The checkbox and select profile tokens should no longer return a value.
-    $tokens = array(
-      'profile-checkbox' => NULL,
-      'profile-selection' => NULL,
-    );
-    $this->assertTokens('user', array('user' => $account), $tokens);
-  }
-
-  /**
-   * Add a profile field.
-   *
-   * @param $type
-   *   The profile field type.
-   * @param $field
-   *   (optional) An array of the profile field properties.
-   *
-   * @return
-   *   The saved profile field record object.
-   *
-   * @see drupal_form_submit()
-   */
-  function addProfileField($type, array $field = array()) {
-    $field += array(
-      'type' => $type,
-      'category' => 'SimpleTest',
-      'title' => $this->randomName(8),
-      'name' => 'profile_' . $type,
-      'explanation' => $this->randomName(50),
-      'autocomplete' => 0,
-      'required' => 0,
-      'register' => 0,
-    );
-    drupal_write_record('profile_field', $field);
-
-    // Verify the profile field was created successfully.
-    $saved_field = db_query("SELECT * FROM {profile_field} WHERE type = :type AND name = :name", array(':type' => $type, ':name' => $field['name']))->fetchObject();
-    if (empty($saved_field)) {
-      $this->fail(t('Failed to create profile field @name.', array('@name' => $saved_field->name)));
-    }
-
-    return $saved_field;
-  }
-}
-
-/**
- * Test the current page tokens.
- */
-class TokenCurrentPageTestCase extends TokenTestHelper {
-  public static function getInfo() {
-    return array(
-      'name' => 'Current page token tests',
-      'description' => 'Test the [current-page:*] tokens.',
-      'group' => 'Token',
-    );
-  }
-
-  function testCurrentPageTokens() {
-    $tokens = array(
-      '[current-page:title]' => t('Welcome to @site-name', array('@site-name' => variable_get('site_name', 'Drupal'))),
-      '[current-page:url]' => url('node', array('absolute' => TRUE)),
-      '[current-page:url:absolute]' => url('node', array('absolute' => TRUE)),
-      '[current-page:url:relative]' => url('node', array('absolute' => FALSE)),
-      '[current-page:url:path]' => 'node',
-      '[current-page:url:args:value:0]' => 'node',
-      '[current-page:url:args:value:1]' => NULL,
-      '[current-page:url:unaliased]' => url('node', array('absolute' => TRUE, 'alias' => TRUE)),
-      '[current-page:page-number]' => 1,
-      '[current-page:query:foo]' => NULL,
-      '[current-page:query:bar]' => NULL,
-      '[current-page:query:q]' => 'node',
-      // Deprecated tokens
-      '[current-page:arg:0]' => 'node',
-      '[current-page:arg:1]' => NULL,
-    );
-    $this->assertPageTokens('', $tokens);
-
-    $node = $this->drupalCreateNode(array('title' => 'Node title', 'path' => array('alias' => 'node-alias')));
-    $tokens = array(
-      '[current-page:title]' => 'Node title',
-      '[current-page:url]' => url("node/{$node->nid}", array('absolute' => TRUE)),
-      '[current-page:url:absolute]' => url("node/{$node->nid}", array('absolute' => TRUE)),
-      '[current-page:url:relative]' => url("node/{$node->nid}", array('absolute' => FALSE)),
-      '[current-page:url:alias]' => 'node-alias',
-      '[current-page:url:args:value:0]' => 'node-alias',
-      '[current-page:url:args:value:1]' => NULL,
-      '[current-page:url:unaliased]' => url("node/{$node->nid}", array('absolute' => TRUE, 'alias' => TRUE)),
-      '[current-page:url:unaliased:args:value:0]' => 'node',
-      '[current-page:url:unaliased:args:value:1]' => $node->nid,
-      '[current-page:url:unaliased:args:value:2]' => NULL,
-      '[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,
-      '[current-page:arg:2]' => NULL,
-    );
-    $this->assertPageTokens("node/{$node->nid}", $tokens, array(), array('url_options' => array('query' => array('foo' => 'bar'))));
-  }
-}
-
-class TokenArrayTestCase extends TokenTestHelper {
-  public static function getInfo() {
-    return array(
-      'name' => 'Array token tests',
-      'description' => 'Test the array tokens.',
-      'group' => 'Token',
-    );
-  }
-
-  function testArrayTokens() {
-    // Test a simple array.
-    $array = array(0 => 'a', 1 => 'b', 2 => 'c', 4 => 'd');
-    $tokens = array(
-      'first' => 'a',
-      'last' => 'd',
-      'value:0' => 'a',
-      'value:2' => 'c',
-      'count' => 4,
-      'keys' => '0, 1, 2, 4',
-      'keys:value:3' => '4',
-      'keys:join' => '0124',
-      'reversed' => 'd, c, b, a',
-      'reversed:keys' => '4, 2, 1, 0',
-      'join:/' => 'a/b/c/d',
-      'join' => 'abcd',
-      'join:, ' => 'a, b, c, d',
-      'join: ' => 'a b c d',
-    );
-    $this->assertTokens('array', array('array' => $array), $tokens);
-
-    // Test a mixed simple and render array.
-    // 2 => c, 0 => a, 4 => d, 1 => b
-    $array = array(
-      '#property' => 'value',
-      0 => 'a',
-      1 => array('#markup' => 'b', '#weight' => 0.01),
-      2 => array('#markup' => 'c', '#weight' => -10),
-      4 => array('#markup' => 'd', '#weight' => 0),
-    );
-    $tokens = array(
-      'first' => 'c',
-      'last' => 'b',
-      'value:0' => 'a',
-      'value:2' => 'c',
-      'count' => 4,
-      'keys' => '2, 0, 4, 1',
-      'keys:value:3' => '1',
-      'keys:join' => '2041',
-      'reversed' => 'b, d, a, c',
-      'reversed:keys' => '1, 4, 0, 2',
-      'join:/' => 'c/a/d/b',
-      'join' => 'cadb',
-      'join:, ' => 'c, a, d, b',
-      'join: ' => 'c a d b',
-    );
-    $this->assertTokens('array', array('array' => $array), $tokens);
-  }
-}
-
-class TokenRandomTestCase extends TokenTestHelper {
-  public static function getInfo() {
-    return array(
-      'name' => 'Random token tests',
-      'description' => 'Test the random tokens.',
-      'group' => 'Token',
-    );
-  }
-
-  function testRandomTokens() {
-    $tokens = array(
-      'number' => '[0-9]{1,}',
-      'hash:md5' => '[0-9a-f]{32}',
-      'hash:sha1' => '[0-9a-f]{40}',
-      'hash:sha256' => '[0-9a-f]{64}',
-      'hash:invalid-algo' => NULL,
-    );
-
-    $first_set = $this->assertTokens('random', array(), $tokens, array('regex' => TRUE));
-    $second_set = $this->assertTokens('random', array(), $tokens, array('regex' => TRUE));
-    foreach ($first_set as $token => $value) {
-      $this->assertNotIdentical($first_set[$token], $second_set[$token]);
-    }
-  }
-}
-
-/**
- * @todo Remove when http://drupal.org/node/1173706 is fixed.
- */
-class TokenDateTestCase extends TokenTestHelper {
-  public static function getInfo() {
-    return array(
-      'name' => 'Date token tests',
-      'description' => 'Test the date tokens.',
-      'group' => 'Token',
-    );
-  }
-
-  function testDateTokens() {
-    $tokens = array(
-      'token_test' => '1984',
-      'invalid_format' => NULL,
-    );
-
-    $this->assertTokens('date', array('date' => 453859200), $tokens);
-  }
-}
-
-class TokenFileTestCase extends TokenTestHelper {
-  public static function getInfo() {
-    return array(
-      'name' => 'File token tests',
-      'description' => 'Test the file tokens.',
-      'group' => 'Token',
-    );
-  }
-
-  function testFileTokens() {
-    // Create a test file object.
-    $file = new stdClass();
-    $file->fid = 1;
-    $file->filename = 'test.png';
-    $file->filesize = 100;
-    $file->uri = 'public://images/test.png';
-    $file->filemime = 'image/png';
-
-    $tokens = array(
-      'basename' => 'test.png',
-      'extension' => 'png',
-      'size-raw' => 100,
-    );
-    $this->assertTokens('file', array('file' => $file), $tokens);
-
-    // Test a file with no extension and a fake name.
-    $file->filename = 'Test PNG image';
-    $file->uri = 'public://images/test';
-
-    $tokens = array(
-      'basename' => 'test',
-      'extension' => '',
-      'size-raw' => 100,
-    );
-    $this->assertTokens('file', array('file' => $file), $tokens);
-  }
-}
-
-class TokenBlockTestCase extends TokenTestHelper {
-  public static function getInfo() {
-    return array(
-      'name' => 'Block token tests',
-      'description' => 'Test the block title token replacement.',
-      'group' => 'Token',
-    );
-  }
-
-  public function setUp($modules = array()) {
-    $modules[] = 'block';
-    parent::setUp($modules);
-
-    $this->admin_user = $this->drupalCreateUser(array('access content', 'administer blocks'));
-    $this->drupalLogin($this->admin_user);
-  }
-
-  public function testBlockTitleTokens() {
-    $edit['title'] = '[current-page:title] block title';
-    $edit['info'] = 'Test token title block';
-    $edit['body[value]'] = 'This is the test token title block.';
-    $edit['regions[bartik]'] = 'sidebar_first';
-    $this->drupalPost('admin/structure/block/add', $edit, 'Save block');
-
-    $this->drupalGet('node');
-    $this->assertText('Welcome to ' . variable_get('site_name', 'Drupal') . ' block title');
-
-    // Ensure that tokens are not double-escaped when output as a block title.
-    $node = $this->drupalCreateNode(array('title' => "Site's first node"));
-    $this->drupalGet('node/' . $node->nid);
-    // The apostraphe should only be escaped once via check_plain().
-    $this->assertRaw("Site&#039;s first node block title");
-  }
-}
-- 
1.9.3 (Apple Git-50)


From 1df37f292248851ed98dbac75e12d13aacd4b953 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Thu, 13 Feb 2014 15:04:17 +1000
Subject: [PATCH 033/230] Issue #1962358 by larowlan: token_test info file to
 yml

---
 tests/token_test.info     | 5 -----
 tests/token_test.info.yml | 5 +++++
 2 files changed, 5 insertions(+), 5 deletions(-)
 delete mode 100644 tests/token_test.info
 create mode 100644 tests/token_test.info.yml

diff --git a/tests/token_test.info b/tests/token_test.info
deleted file mode 100644
index 20dd2e2..0000000
--- a/tests/token_test.info
+++ /dev/null
@@ -1,5 +0,0 @@
-name = Token Test
-description = Testing module for token functionality.
-package = Testing
-core = 8.x
-hidden = TRUE
diff --git a/tests/token_test.info.yml b/tests/token_test.info.yml
new file mode 100644
index 0000000..dac6abb
--- /dev/null
+++ b/tests/token_test.info.yml
@@ -0,0 +1,5 @@
+name: Token Test
+description: Testing module for token functionality.
+package: Testing
+core: 8.x
+hidden: TRUE
-- 
1.9.3 (Apple Git-50)


From ae54a3ad0eaeb940c348ddc1de99cd9719832663 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Thu, 13 Feb 2014 17:40:42 +1000
Subject: [PATCH 034/230] Issue #1962358 by larowlan: Add type 'module' to info
 files

---
 jquery.treeTable.css => css/jquery.treeTable.css | 4 ++--
 token.css => css/token.css                       | 0
 jquery.treeTable.js => js/jquery.treeTable.js    | 0
 token.js => js/token.js                          | 0
 tests/token_test.info.yml                        | 1 +
 token.info.yml                                   | 1 +
 6 files changed, 4 insertions(+), 2 deletions(-)
 rename jquery.treeTable.css => css/jquery.treeTable.css (93%)
 rename token.css => css/token.css (100%)
 rename jquery.treeTable.js => js/jquery.treeTable.js (100%)
 rename token.js => js/token.js (100%)

diff --git a/jquery.treeTable.css b/css/jquery.treeTable.css
similarity index 93%
rename from jquery.treeTable.css
rename to css/jquery.treeTable.css
index bec225a..db2149b 100644
--- a/jquery.treeTable.css
+++ b/css/jquery.treeTable.css
@@ -16,11 +16,11 @@
 }
 
 .treeTable tr.collapsed td .expander {
-  background-image: url(arrow-right.png);
+  background-image: url(../arrow-right.png);
 }
 
 .treeTable tr.expanded td .expander {
-  background-image: url(arrow-down.png);
+  background-image: url(../arrow-down.png);
 }
 
 /* jquery.treeTable.sortable
diff --git a/token.css b/css/token.css
similarity index 100%
rename from token.css
rename to css/token.css
diff --git a/jquery.treeTable.js b/js/jquery.treeTable.js
similarity index 100%
rename from jquery.treeTable.js
rename to js/jquery.treeTable.js
diff --git a/token.js b/js/token.js
similarity index 100%
rename from token.js
rename to js/token.js
diff --git a/tests/token_test.info.yml b/tests/token_test.info.yml
index dac6abb..0068679 100644
--- a/tests/token_test.info.yml
+++ b/tests/token_test.info.yml
@@ -1,3 +1,4 @@
+type: module
 name: Token Test
 description: Testing module for token functionality.
 package: Testing
diff --git a/token.info.yml b/token.info.yml
index b91290f..cccc5b8 100644
--- a/token.info.yml
+++ b/token.info.yml
@@ -1,3 +1,4 @@
+type: module
 name: Token
 description: Provides a user interface for the Token API and some missing core tokens.
 core: 8.x
-- 
1.9.3 (Apple Git-50)


From 4a765de408f755a052dbf968676544a5247bd677 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 08:14:27 +1000
Subject: [PATCH 035/230] Issue #1962358 by larowlan: Use t() instead of
 get_t()

---
 token.install | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/token.install b/token.install
index c2b57fd..d1f52d8 100644
--- a/token.install
+++ b/token.install
@@ -10,7 +10,6 @@
  */
 function token_requirements($phase = 'runtime') {
   $requirements = array();
-  $t = get_t();
 
   if ($phase == 'runtime') {
     // Check for various token definition problems.
@@ -28,10 +27,10 @@ function token_requirements($phase = 'runtime') {
     }
     if (!empty($token_problems)) {
       $requirements['token_problems'] = array(
-        'title' => $t('Tokens'),
-        'value' => $t('Problems detected'),
+        'title' => t('Tokens'),
+        'value' => t('Problems detected'),
         'severity' => REQUIREMENT_WARNING,
-        'description' => '<p>' . implode('</p><p>', $token_problems) . '</p>', //theme('item_list', array('items' => $token_problems)),
+        'description' => '<p>' . implode('</p><p>', $token_problems) . '</p>',
       );
     }
   }
-- 
1.9.3 (Apple Git-50)


From e1402609f0d58b0333ff9f9f621bbcbe191deac8 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 08:15:10 +1000
Subject: [PATCH 036/230] Issue #1962358 by larowlan: Remove 7x update hooks

---
 token.install | 37 -------------------------------------
 1 file changed, 37 deletions(-)

diff --git a/token.install b/token.install
index d1f52d8..0a635d7 100644
--- a/token.install
+++ b/token.install
@@ -48,43 +48,6 @@ function token_schema() {
 }
 
 /**
- * Add the cache_token table.
- */
-function token_update_7000() {
-  if (!db_table_exists('cache_token')) {
-    $schema = drupal_get_schema_unprocessed('system', 'cache');
-    $schema['description'] = 'Cache table for token information.';
-    db_create_table('cache_token', $schema);
-  }
-}
-
-/**
- * Deprecate and disable the token_actions module.
- */
-function token_update_7001() {
-  module_disable(array('token_actions'));
-  return 'The Token actions module has been deprecated by the updated system module actions that support tokens.';
-}
-
-/**
- * Migrate old token_actions module actions to system actions.
- */
-//function token_update_700X() {
-//  $actions = db_query("SELECT aid, type, callback, parameters, label FROM {actions} WHERE type = 'system' AND callback IN ('token_actions_message_action', 'token_actions_send_email_action', 'token_actions_goto_action')")->fetchAll();
-//  foreach ($actions as $action) {
-//    $action->parameters = unserialize($action->parameters);
-//    foreach ($action->parameters as $key => $value) {
-//      if (is_string($value)) {
-//        $action->parameters[$key] = token_update_token_text($value);
-//      }
-//    }
-//    $action->callback = str_replace('token_actions_', '', $action->callback);
-//    actions_save($action->callback, $action->type, $action->parameters, $action->label, $action->aid);
-//  }
-//  return 'Token actions module actions migrated to system module actions. You may still want to verify that the actions were upgraded correctly.';
-//}
-
-/**
  * Build a list of Drupal 6 tokens and their Drupal 7 token names.
  */
 function _token_upgrade_token_list() {
-- 
1.9.3 (Apple Git-50)


From 24540e6a03d6f635c9a862a62dec3c27ab148110 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 08:30:49 +1000
Subject: [PATCH 037/230] Issue #1962358 by larowlan: Cache service

---
 token.install      | 9 ---------
 token.services.yml | 8 ++++++++
 2 files changed, 8 insertions(+), 9 deletions(-)
 create mode 100644 token.services.yml

diff --git a/token.install b/token.install
index 0a635d7..5a8e5df 100644
--- a/token.install
+++ b/token.install
@@ -39,15 +39,6 @@ function token_requirements($phase = 'runtime') {
 }
 
 /**
- * Implements hook_schema().
- */
-function token_schema() {
-  $schema['cache_token'] = drupal_get_schema_unprocessed('system', 'cache');
-  $schema['cache_token']['description'] = 'Cache table for token information.';
-  return $schema;
-}
-
-/**
  * Build a list of Drupal 6 tokens and their Drupal 7 token names.
  */
 function _token_upgrade_token_list() {
diff --git a/token.services.yml b/token.services.yml
new file mode 100644
index 0000000..7c5938d
--- /dev/null
+++ b/token.services.yml
@@ -0,0 +1,8 @@
+services:
+  cache.token:
+    class: Drupal\Core\Cache\CacheBackendInterface
+    tags:
+      - { name: cache.bin }
+    factory_method: get
+    factory_service: cache_factory
+    arguments: [token]
-- 
1.9.3 (Apple Git-50)


From 1fe9a2ed98e1d2c0552ac8f72a4bdfe647025809 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <grom358@gmail.com>
Date: Fri, 14 Feb 2014 12:11:10 +1300
Subject: [PATCH 038/230] Issue #1962358 by grom358: Replaced deprecated
 function calls

---
 token.module     | 26 ++++++++++----------
 token.pages.inc  |  2 +-
 token.tokens.inc | 72 ++++++++++++++++++++++++++++----------------------------
 3 files changed, 50 insertions(+), 50 deletions(-)

diff --git a/token.module b/token.module
index 1b19d20..b7a9d6c 100644
--- a/token.module
+++ b/token.module
@@ -74,7 +74,7 @@ function token_menu() {
   );*/
 
   // Devel token pages.
-  if (module_exists('devel')) {
+  if (\Drupal::moduleHandler()->module_exists('devel')) {
     $items['node/%node/devel/token'] = array(
       'title' => 'Tokens',
       'page callback' => 'token_devel_token_object',
@@ -132,7 +132,7 @@ function token_admin_menu_output_alter(&$content) {
     '#title' => t('Token registry'),
     '#href' => 'token/flush-cache',
     '#options' => array(
-      'query' => drupal_get_destination() + array('token' => drupal_get_token('token/flush-cache')),
+      'query' => drupal_get_destination() + array('token' => \Drupal::csrfToken()->get('token/flush-cache')),
     ),
   );
 }
@@ -339,7 +339,7 @@ function token_get_entity_mapping($value_type = 'token', $value = NULL) {
   $mapping = &drupal_static(__FUNCTION__, array());
 
   if (empty($mapping)) {
-    foreach (entity_get_info() as $entity_type => $info) {
+    foreach (\Drupal::entityManager()->getDefinitions() as $entity_type => $info) {
       $mapping[$entity_type] = !empty($info['token type']) ? $info['token type'] : $entity_type;
     }
   }
@@ -402,7 +402,7 @@ function token_entity_info_alter(&$info) {
 function token_module_implements_alter(&$implementations, $hook) {
   if ($hook == 'tokens' || $hook == 'token_info') {
     foreach (_token_core_supported_modules() as $module) {
-      if (module_exists($module)) {
+      if (\Drupal::moduleHandler()->moduleExists($module)) {
         $implementations[$module] = TRUE;
       }
     }
@@ -662,22 +662,22 @@ function token_element_validate(&$element, &$form_state) {
   // Validate if an element must have a minimum number of tokens.
   if (isset($element['#min_tokens']) && count($tokens) < $element['#min_tokens']) {
     // @todo Change this error message to include the minimum number.
-    $error = format_plural($element['#min_tokens'], 'The %element-title cannot contain fewer than one token.', 'The %element-title must contain at least @count tokens.', array('%element-title' => $title));
-    form_error($element, $error);
+    $error = \Drupal::translation()->formatPlural($element['#min_tokens'], 'The %element-title cannot contain fewer than one token.', 'The %element-title must contain at least @count tokens.', array('%element-title' => $title));
+    \Drupal::formBuilder()->setError($element, $error);
   }
 
   // Validate if an element must have a maximum number of tokens.
   if (isset($element['#max_tokens']) && count($tokens) > $element['#max_tokens']) {
     // @todo Change this error message to include the maximum number.
-    $error = format_plural($element['#max_tokens'], 'The %element-title must contain as most one token.', 'The %element-title must contain at most @count tokens.', array('%element-title' => $title));
-    form_error($element, $error);
+    $error = \Drupal::translation()->formatPlural($element['#max_tokens'], 'The %element-title must contain as most one token.', 'The %element-title must contain at most @count tokens.', array('%element-title' => $title));
+    \Drupal::formBuilder()->setError($element, $error);
   }
 
   // Check if the field defines specific token types.
   if (!empty($element['#token_types'])) {
     $invalid_tokens = token_get_invalid_tokens_by_context($tokens, $element['#token_types']);
     if ($invalid_tokens) {
-      form_error($element, t('The %element-title is using the following invalid tokens: @invalid-tokens.', array('%element-title' => $title, '@invalid-tokens' => implode(', ', $invalid_tokens))));
+      \Drupal::formBuilder()->setError($element, t('The %element-title is using the following invalid tokens: @invalid-tokens.', array('%element-title' => $title, '@invalid-tokens' => implode(', ', $invalid_tokens))));
     }
   }
 
@@ -743,7 +743,7 @@ function token_form_system_actions_configure_alter(&$form, $form_state) {
 function token_form_user_admin_settings_alter(&$form, &$form_state) {
   $email_token_help = t('Available variables are: [site:name], [site:url], [user:name], [user:mail], [site:login-url], [site:url-brief], [user:edit-url], [user:one-time-login-url], [user:cancel-url].');
 
-  foreach (element_children($form) as $key) {
+  foreach (Element::children($form) as $key) {
     $element = &$form[$key];
 
     // Remove the crummy default token help text.
@@ -770,7 +770,7 @@ function token_form_user_admin_settings_alter(&$form, &$form_state) {
         continue 2;
     }
 
-    foreach (element_children($element) as $sub_key) {
+    foreach (Element::children($element) as $sub_key) {
       if (!isset($element[$sub_key]['#type'])) {
         continue;
       }
@@ -1058,7 +1058,7 @@ function _token_menu_link_translate(&$item) {
   // options array. For performance reasons we only invoke this hook if the link
   // has the 'alter' flag set in the options array.
   if (!empty($item['options']['alter'])) {
-    drupal_alter('translated_menu_link', $item, $map);
+    \Drupal::moduleHandler()->alter('translated_menu_link', $item, $map);
   }
 
   return $map;
@@ -1107,7 +1107,7 @@ function token_render_array(array $array, array $options = array()) {
 function token_render_array_value($value, array $options = array()) {
   $rendered = is_array($value) ? render($value) : (string) $value;
   if (!empty($options['sanitize'])) {
-    $rendered = check_plain($rendered);
+    $rendered = String::checkPlain($rendered);
   }
   return $rendered;
 }
diff --git a/token.pages.inc b/token.pages.inc
index d2f06e9..77ee7c8 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -215,7 +215,7 @@ function token_devel_token_object($entity_type, $entity) {
  * Page callback to clear the token registry caches.
  */
 function token_flush_cache_callback() {
-  if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], current_path())) {
+  if (!isset($_GET['token']) || !\Drupal::csrfToken()->validate($_GET['token'], current_path())) {
     return MENU_NOT_FOUND;
   }
 
diff --git a/token.tokens.inc b/token.tokens.inc
index 4ed44b8..8a3e2e5 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -31,17 +31,17 @@ function token_token_info_alter(&$info) {
   unset($info['tokens']['node']['type-name']);
 
   // Support 'url' type tokens for core tokens.
-  if (isset($info['tokens']['comment']['url']) && module_exists('comment')) {
+  if (isset($info['tokens']['comment']['url']) && \Drupal::moduleHandler()->moduleExists('comment')) {
     $info['tokens']['comment']['url']['type'] = 'url';
   }
   $info['tokens']['node']['url']['type'] = 'url';
-  if (isset($info['tokens']['term']['url']) && module_exists('taxonomy')) {
+  if (isset($info['tokens']['term']['url']) && \Drupal::moduleHandler()->moduleExists('taxonomy')) {
     $info['tokens']['term']['url']['type'] = 'url';
   }
   $info['tokens']['user']['url']['type'] = 'url';
 
   // Add [token:url] tokens for any URI-able entities.
-  $entities = entity_get_info();
+  $entities = \Drupal::entityManager()->getDefinitions();
   foreach ($entities as $entity => $entity_info) {
     if (!isset($entity_info['token type'])) {
       continue;
@@ -137,7 +137,7 @@ function token_token_info() {
   );
 
   // Taxonomy term and vocabulary tokens.
-  if (module_exists('taxonomy')) {
+  if (\Drupal::moduleHandler()->moduleExists('taxonomy')) {
     $info['tokens']['term']['edit-url'] = array(
       'name' => t('Edit URL'),
       'description' => t("The URL of the taxonomy term's edit page."),
@@ -424,7 +424,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           break;
         case 'content-type':
           $type_name = node_type_get_name($node);
-          $replacements[$original] = $sanitize ? check_plain($type_name) : $type_name;
+          $replacements[$original] = $sanitize ? String::checkPlain($type_name) : $type_name;
           break;
       }
     }
@@ -448,7 +448,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'name':
-          $replacements[$original] = $sanitize ? check_plain($node_type->name) : $node_type->name;
+          $replacements[$original] = $sanitize ? String::checkPlain($node_type->name) : $node_type->name;
           break;
         case 'machine-name':
           // This is a machine name so does not ever need to be sanitized.
@@ -491,7 +491,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           $parents = taxonomy_get_parents_all($term->tid);
           $root_term = end($parents);
           if ($root_term->tid != $term->tid) {
-            $replacements[$original] = $sanitize ? check_plain($root_term->name) : $root_term->name;
+            $replacements[$original] = $sanitize ? String::checkPlain($root_term->name) : $root_term->name;
           }
           break;
       }
@@ -541,11 +541,11 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       switch ($name) {
         case 'basename':
           $basename = pathinfo($file->uri, PATHINFO_BASENAME);
-          $replacements[$original] = $sanitize ? check_plain($basename) : $basename;
+          $replacements[$original] = $sanitize ? String::checkPlain($basename) : $basename;
           break;
         case 'extension':
           $extension = pathinfo($file->uri, PATHINFO_EXTENSION);
-          $replacements[$original] = $sanitize ? check_plain($extension) : $extension;
+          $replacements[$original] = $sanitize ? String::checkPlain($extension) : $extension;
           break;
         case 'size-raw':
           $replacements[$original] = (int) $file->filesize;
@@ -597,7 +597,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       switch ($name) {
         case 'ip-address':
           $ip = ip_address();
-          $replacements[$original] = $sanitize ? check_plain($ip) : $ip;
+          $replacements[$original] = $sanitize ? String::checkPlain($ip) : $ip;
           break;
       }
     }
@@ -618,14 +618,14 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           $replacements[$original] = $link['mlid'];
           break;
         case 'title':
-          $replacements[$original] = $sanitize ? check_plain($link['title']) : $link['title'];
+          $replacements[$original] = $sanitize ? String::checkPlain($link['title']) : $link['title'];
           break;
         case 'url':
           $replacements[$original] = url($link['href'], $url_options);
           break;
         case 'parent':
           if (!empty($link['plid']) && $parent = token_menu_link_load($link['plid'])) {
-            $replacements[$original] = $sanitize ? check_plain($parent['title']) : $parent['title'];
+            $replacements[$original] = $sanitize ? String::checkPlain($parent['title']) : $parent['title'];
           }
           break;
         case 'parents':
@@ -635,7 +635,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           break;
         case 'root';
           if (!empty($link['p1']) && $link['p1'] != $link['mlid'] && $root = token_menu_link_load($link['p1'])) {
-            $replacements[$original] = $sanitize ? check_plain($root['title']) : $root['title'];
+            $replacements[$original] = $sanitize ? String::checkPlain($root['title']) : $root['title'];
           }
           break;
       }
@@ -688,7 +688,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     if ($arg_tokens = token_find_with_prefix($tokens, 'arg')) {
       foreach ($arg_tokens as $name => $original) {
         if (is_numeric($name) && ($arg = arg($name)) && isset($arg)) {
-          $replacements[$original] = $sanitize ? check_plain($arg) : $arg;
+          $replacements[$original] = $sanitize ? String::checkPlain($arg) : $arg;
         }
       }
     }
@@ -698,7 +698,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       foreach ($query_tokens as $name => $original) {
         // @todo Should this use filter_input()?
         if (isset($_GET[$name])) {
-          $replacements[$original] = $sanitize ? check_plain($_GET[$name]) : $_GET[$name];
+          $replacements[$original] = $sanitize ? String::checkPlain($_GET[$name]) : $_GET[$name];
         }
       }
     }
@@ -722,12 +722,12 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       switch ($name) {
         case 'path':
           $value = empty($url_options['alias']) ? drupal_get_path_alias($path, $language_code) : $path;
-          $replacements[$original] = $sanitize ? check_plain($value) : $value;
+          $replacements[$original] = $sanitize ? String::checkPlain($value) : $value;
           break;
         case 'alias':
           // @deprecated
           $alias = drupal_get_path_alias($path, $language_code);
-          $replacements[$original] = $sanitize ? check_plain($alias) : $alias;
+          $replacements[$original] = $sanitize ? String::checkPlain($alias) : $alias;
           break;
         case 'absolute':
           $replacements[$original] = url($path, $url_options);
@@ -784,7 +784,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
         case 'original':
           if (_token_module($type, 'original') == 'token' && !empty($entity->original)) {
             $label = entity_label($entity_type, $entity->original);
-            $replacements[$original] = $sanitize ? check_plain($label) : $label;
+            $replacements[$original] = $sanitize ? String::checkPlain($label) : $label;
           }
           break;
       }
@@ -822,12 +822,12 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
         case 'first':
           $value = $array[$keys[0]];
           $value = is_array($value) ? render($value) : (string) $value;
-          $replacements[$original] = $sanitize ? check_plain($value) : $value;
+          $replacements[$original] = $sanitize ? String::checkPlain($value) : $value;
           break;
         case 'last':
           $value = $array[$keys[count($keys) - 1]];
           $value = is_array($value) ? render($value) : (string) $value;
-          $replacements[$original] = $sanitize ? check_plain($value) : $value;
+          $replacements[$original] = $sanitize ? String::checkPlain($value) : $value;
           break;
         case 'count':
           $replacements[$original] = count($keys);
@@ -944,7 +944,7 @@ function token_tokens_alter(array &$replacements, array $context) {
             $account->name = $comment->name;
           }
           $name = format_username($account);
-          $replacements[$original] = $sanitize ? check_plain($name) : $name;
+          $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
           break;
       }
     }
@@ -961,7 +961,7 @@ function token_tokens_alter(array &$replacements, array $context) {
           if (version_compare(VERSION, '7.9', '<')) {
             $account = user_load($node->uid);
             $name = format_username($account);
-            $replacements[$original] = $sanitize ? check_plain($name) : $name;
+            $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
           }
           break;
       }
@@ -979,7 +979,7 @@ function token_tokens_alter(array &$replacements, array $context) {
           if (version_compare(VERSION, '7.7', '<')) {
             $account = user_load($file->uid);
             $name = format_username($account);
-            $replacements[$original] = $sanitize ? check_plain($name) : $name;
+            $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
           }
           break;
       }
@@ -1016,7 +1016,7 @@ function book_tokens($type, $tokens, array $data = array(), array $options = arr
       foreach ($tokens as $name => $original) {
         switch ($name) {
           case 'book':
-            $replacements[$original] = $sanitize ? check_plain($link['title']) : $link['title'];
+            $replacements[$original] = $sanitize ? String::checkPlain($link['title']) : $link['title'];
             break;
         }
       }
@@ -1105,7 +1105,7 @@ function menu_tokens($type, $tokens, array $data = array(), array $options = arr
       switch ($name) {
         case 'menu-link':
           if ($link = token_node_menu_link_load($node)) {
-            $replacements[$original] = $sanitize ? check_plain($link['title']) : $link['title'];
+            $replacements[$original] = $sanitize ? String::checkPlain($link['title']) : $link['title'];
           }
           break;
       }
@@ -1127,7 +1127,7 @@ function menu_tokens($type, $tokens, array $data = array(), array $options = arr
       switch ($name) {
         case 'menu':
           if ($menu = menu_load($link['menu_name'])) {
-            $replacements[$original] = $sanitize ? check_plain($menu['title']) : $menu['title'];
+            $replacements[$original] = $sanitize ? String::checkPlain($menu['title']) : $menu['title'];
           }
           break;
         case 'edit-url':
@@ -1149,7 +1149,7 @@ function menu_tokens($type, $tokens, array $data = array(), array $options = arr
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'name':
-          $replacements[$original] = $sanitize ? check_plain($menu['title']) : $menu['title'];
+          $replacements[$original] = $sanitize ? String::checkPlain($menu['title']) : $menu['title'];
           break;
         case 'machine-name':
           // This is a machine name so does not ever need to be sanitized.
@@ -1183,7 +1183,7 @@ function profile_token_info() {
 
   foreach (_token_profile_fields() as $field) {
     $info['tokens']['user'][$field->token_name] = array(
-      'name' => check_plain($field->title),
+      'name' => String::checkPlain($field->title),
       'description' => t('@category @type field.', array('@category' => drupal_ucfirst($field->category), '@type' => $field->type)),
     );
 
@@ -1234,7 +1234,7 @@ function profile_tokens($type, $tokens, array $data = array(), array $options =
             break;
           case 'checkbox':
             // Checkbox field if checked should return the text.
-            $replacements[$original] = $sanitize ? check_plain($profile_fields[$name]->title) : $profile_fields[$name]->title;
+            $replacements[$original] = $sanitize ? String::checkPlain($profile_fields[$name]->title) : $profile_fields[$name]->title;
             break;
           case 'list':
             $value = preg_split("/[,\n\r]/", $value);
@@ -1242,7 +1242,7 @@ function profile_tokens($type, $tokens, array $data = array(), array $options =
             $value = implode(', ', $value);
             // Intentionally fall through to the default condition.
           default:
-            $replacements[$original] = $sanitize ? check_plain($value) : $value;
+            $replacements[$original] = $sanitize ? String::checkPlain($value) : $value;
             break;
         }
       }
@@ -1292,9 +1292,9 @@ function _token_field_info($field_name = NULL) {
       $info = array();
 
       $fields = field_info_fields();
-      $instances = field_info_instances();
+      $instances = Field::fieldInfo()->getInstances();
       $type_info = field_info_field_types();
-      $entity_info = entity_get_info();
+      $entity_info = \Drupal::entityManager()->getDefinitions();
 
       foreach ($fields as $field) {
         $key = $field['field_name'];
@@ -1328,7 +1328,7 @@ function _token_field_info($field_name = NULL) {
         if (isset($info[$key])) {
           $labels = array_count_values($info[$key]['labels']);
           arsort($labels);
-          $info[$key]['label'] = check_plain(key($labels));
+          $info[$key]['label'] = String::checkPlain(key($labels));
 
           // Generate a description for the token.
           $info[$key]['description'] = t('@type field.', array('@type' => $type_info[$field['type']]['label']));
@@ -1338,7 +1338,7 @@ function _token_field_info($field_name = NULL) {
         }
       }
 
-      drupal_alter('token_field_info', $info);
+      \Drupal::moduleHandler()->alter('token_field_info', $info);
       cache('cache_token')->set('field:info', $info);
     }
   }
@@ -1407,7 +1407,7 @@ function field_tokens($type, $tokens, array $data = array(), array $options = ar
     unset($entity->_field_view_prepared);
 
     list(, , $bundle) = entity_extract_ids($entity_type, $entity);
-    $fields = field_info_instances($entity_type, $bundle);
+    $fields = Field::fieldInfo()->getBundleInstances($entity_type, $bundle);
 
     foreach (array_keys($fields) as $field_name) {
       // Do not continue if the field is empty.
@@ -1450,7 +1450,7 @@ function token_pre_render_field_token(&$elements) {
 
   // Prevent multi-value fields from appearing smooshed together by appending
   // a join suffix to all but the last value.
-  $deltas = element_get_visible_children($elements);
+  $deltas = Element::getVisibleChildren($elements);
   $count = count($deltas);
   if ($count > 1) {
     $join = isset($elements['#token_options']['join']) ? $elements['#token_options']['join'] : ", ";
-- 
1.9.3 (Apple Git-50)


From 86b2a5f0dc761b773b1ff3fe1439ac39de6c99dd Mon Sep 17 00:00:00 2001
From: Cameron Zemek <grom358@gmail.com>
Date: Fri, 14 Feb 2014 12:21:51 +1300
Subject: [PATCH 039/230] Issue #1962358 by grom358: Replaced use of  with
 Request object

---
 token.pages.inc  | 2 +-
 token.tokens.inc | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/token.pages.inc b/token.pages.inc
index 77ee7c8..ac71c9f 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -215,7 +215,7 @@ function token_devel_token_object($entity_type, $entity) {
  * Page callback to clear the token registry caches.
  */
 function token_flush_cache_callback() {
-  if (!isset($_GET['token']) || !\Drupal::csrfToken()->validate($_GET['token'], current_path())) {
+  if (!\Drupal::request()->query->has('token') || !\Drupal::csrfToken()->validate(\Drupal::request()->query->get('token'), current_path())) {
     return MENU_NOT_FOUND;
   }
 
diff --git a/token.tokens.inc b/token.tokens.inc
index 8a3e2e5..6494ebf 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -697,8 +697,9 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     if ($query_tokens = token_find_with_prefix($tokens, 'query')) {
       foreach ($query_tokens as $name => $original) {
         // @todo Should this use filter_input()?
-        if (isset($_GET[$name])) {
-          $replacements[$original] = $sanitize ? String::checkPlain($_GET[$name]) : $_GET[$name];
+        if (\Drupal::request()->query->has($name)) {
+          $value = \Drupal::request()->query->get($name);
+          $replacements[$original] = $sanitize ? String::checkPlain($value) : $value;
         }
       }
     }
-- 
1.9.3 (Apple Git-50)


From 526d21068d88e92f5863ecf5ca1d67e6bc244dd7 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <grom358@gmail.com>
Date: Fri, 14 Feb 2014 12:34:38 +1300
Subject: [PATCH 040/230] Issue #1962358 by grom358: Replaced use of  with
 Request object

---
 token.module | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/token.module b/token.module
index b7a9d6c..1f9f515 100644
--- a/token.module
+++ b/token.module
@@ -1138,14 +1138,14 @@ function token_render_cache_get($elements) {
  */
 function token_render_cache_set(&$markup, $elements) {
   // This should only run of drupal_render_cache_set() did not.
-  if (in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD'))) {
+  if (in_array(\Drupal::request()->server->get('REQUEST_METHOD'), array('GET', 'HEAD'))) {
     return FALSE;
   }
 
-  $original_method = $_SERVER['REQUEST_METHOD'];
-  $_SERVER['REQUEST_METHOD'] = 'GET';
+  $original_method = \Drupal::request()->server->get('REQUEST_METHOD');
+  \Drupal::request()->server->set('REQUEST_METHOD', 'GET');
   drupal_render_cache_set($markup, $elements);
-  $_SERVER['REQUEST_METHOD'] = $original_method;
+  \Drupal::request()->server->set('REQUEST_METHOD', $original_method);
 }
 
 function token_menu_link_load_all_parents($mlid) {
-- 
1.9.3 (Apple Git-50)


From 567c84075dd527d15e4a223d0e5d6d10124ad5aa Mon Sep 17 00:00:00 2001
From: Cameron Zemek <grom358@gmail.com>
Date: Fri, 14 Feb 2014 13:08:15 +1300
Subject: [PATCH 041/230] Issue #1962358 by grom358: Fixed typo with call to
 moduleExists and replaced a deprecated call to module_exists

---
 token.module | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/token.module b/token.module
index 1f9f515..88b2603 100644
--- a/token.module
+++ b/token.module
@@ -74,7 +74,7 @@ function token_menu() {
   );*/
 
   // Devel token pages.
-  if (\Drupal::moduleHandler()->module_exists('devel')) {
+  if (\Drupal::moduleHandler()->moduleExists('devel')) {
     $items['node/%node/devel/token'] = array(
       'title' => 'Tokens',
       'page callback' => 'token_devel_token_object',
@@ -695,7 +695,7 @@ function token_element_validate_token_context(&$element, &$form_state) {
  * Implements hook_form_FORM_ID_alter().
  */
 function token_form_field_ui_field_edit_form_alter(&$form, $form_state) {
-  if (($form['#field']['type'] == 'file' || $form['#field']['type'] == 'image') && isset($form['instance']['settings']['file_directory']) && !module_exists('filefield_paths')) {
+  if (($form['#field']['type'] == 'file' || $form['#field']['type'] == 'image') && isset($form['instance']['settings']['file_directory']) && !\Drupal::moduleHandler()->moduleExists('filefield_paths')) {
     // GAH! We can only support global tokens in the upload file directory path.
     $form['instance']['settings']['file_directory']['#element_validate'][] = 'token_element_validate';
     $form['instance']['settings']['file_directory']['#token_types'] = array();
-- 
1.9.3 (Apple Git-50)


From 130a7512bc84611bf6713aae797d9b25d3efaa21 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <grom358@gmail.com>
Date: Fri, 14 Feb 2014 13:27:33 +1300
Subject: [PATCH 042/230] Issue #1962358 by grom358: Added missing use of
 Element

---
 token.module | 1 +
 1 file changed, 1 insertion(+)

diff --git a/token.module b/token.module
index 88b2603..7ba6cc5 100644
--- a/token.module
+++ b/token.module
@@ -4,6 +4,7 @@
  * @file
  * Enhances the token API in core: adds a browseable UI, missing tokens, etc.
  */
+use Drupal\Core\Render\Element;
 
 /**
  * The maximum depth for token tree recursion.
-- 
1.9.3 (Apple Git-50)


From 24a7e7a6bd0b6747496103e68d139ff78ae5eb7d Mon Sep 17 00:00:00 2001
From: Cameron Zemek <grom358@gmail.com>
Date: Fri, 14 Feb 2014 13:29:58 +1300
Subject: [PATCH 043/230] Issue #1962358 by grom358: Added missing use for
 String

---
 token.module | 1 +
 1 file changed, 1 insertion(+)

diff --git a/token.module b/token.module
index 7ba6cc5..fff400b 100644
--- a/token.module
+++ b/token.module
@@ -4,6 +4,7 @@
  * @file
  * Enhances the token API in core: adds a browseable UI, missing tokens, etc.
  */
+use Drupal\Component\Utility\String;
 use Drupal\Core\Render\Element;
 
 /**
-- 
1.9.3 (Apple Git-50)


From fa4a22f6af4ec9c825040f315f6d90ef959eb4db Mon Sep 17 00:00:00 2001
From: Cameron Zemek <grom358@gmail.com>
Date: Fri, 14 Feb 2014 13:32:16 +1300
Subject: [PATCH 044/230] Issue #1962358 by grom358: Added missing use imports

---
 token.tokens.inc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/token.tokens.inc b/token.tokens.inc
index 6494ebf..b6d743d 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -4,6 +4,8 @@
  * @file
  * Token callbacks for the token module.
  */
+use Drupal\Component\Utility\String;
+use Drupal\Core\Render\Element;
 
 /**
  * Implements hook_token_info_alter().
-- 
1.9.3 (Apple Git-50)


From 9dc2cdf9f49b1c0cdb88de4a071c5694060de61f Mon Sep 17 00:00:00 2001
From: Cameron Zemek <grom358@gmail.com>
Date: Fri, 14 Feb 2014 13:52:05 +1300
Subject: [PATCH 045/230] Issue #1962358 by grom358: Replaced calls to
 token_info etc to the Token service

---
 token.module     |  14 +++----
 token.pages.inc  |   4 +-
 token.tokens.inc | 114 +++++++++++++++++++++++++++----------------------------
 3 files changed, 66 insertions(+), 66 deletions(-)

diff --git a/token.module b/token.module
index fff400b..00f804a 100644
--- a/token.module
+++ b/token.module
@@ -210,7 +210,7 @@ function token_block_view_alter(&$data, $block) {
   if (!empty($block->title) && $block->title != '<none>') {
     // Perform unsanitized token replacement since _block_render_blocks() will
     // call check_plain() on $block->title.
-    $block->title = token_replace($block->title, array(), array('sanitize' => FALSE));
+    $block->title = \Drupal::token()->replace($block->title, array(), array('sanitize' => FALSE));
   }
 }
 
@@ -236,7 +236,7 @@ function token_form_block_admin_configure_alter(&$form, $form_state) {
  */
 function token_field_widget_form_alter(&$element, &$form_state, $context) {
   if (!empty($element['#description']) && is_string($element['#description'])) {
-    $element['#description'] = token_replace($element['#description']);
+    $element['#description'] = \Drupal::token()->replace($element['#description']);
   }
 }
 
@@ -458,7 +458,7 @@ function token_get_info($token_type = NULL, $token = NULL) {
       $token_info = $cache->data;
     }
     else {
-      $token_info = token_info();
+      $token_info = \Drupal::token()->getInfo();
 
       foreach (array_keys($token_info['types']) as $type_key) {
         if (isset($token_info['types'][$type_key]['type'])) {
@@ -569,7 +569,7 @@ function token_get_invalid_tokens_by_context($value, $valid_types = array()) {
   }
 
   $invalid_tokens = array();
-  $value_tokens = is_string($value) ? token_scan($value) : $value;
+  $value_tokens = is_string($value) ? \Drupal::token()->scan($value) : $value;
 
   foreach ($value_tokens as $type => $tokens) {
     if (!in_array($type, $valid_types)) {
@@ -620,7 +620,7 @@ function token_get_invalid_tokens($type, $tokens) {
       }
       else {
         // Resursively check the chained tokens.
-        $sub_tokens = token_find_with_prefix(array($token => $full_token), $parts[0]);
+        $sub_tokens = \Drupal::token()->findWithPrefix(array($token => $full_token), $parts[0]);
         $invalid_tokens = array_merge($invalid_tokens, token_get_invalid_tokens($sub_token_info['type'], $sub_tokens));
       }
     }
@@ -657,7 +657,7 @@ function token_element_validate(&$element, &$form_state) {
     return $element;
   }
 
-  $tokens = token_scan($value);
+  $tokens = \Drupal::token()->scan($value);
   $title = empty($element['#title']) ? $element['#parents'][0] : $element['#title'];
   // @todo Find old Drupal 6 style tokens and add them to invalid tokens.
 
@@ -870,7 +870,7 @@ function token_build_tree($token_type, array $options = array()) {
       }
     }
     if (!empty($token_values)) {
-      $token_values = token_generate($token_type, $token_values, $options['data']);
+      $token_values = \Drupal::token()->generate($token_type, $token_values, $options['data']);
       foreach ($token_values as $token => $replacement) {
         $tree[$token]['value'] = $replacement;
       }
diff --git a/token.pages.inc b/token.pages.inc
index ac71c9f..ef47d03 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -228,7 +228,7 @@ function token_autocomplete() {
   $args = func_get_args();
   $string = implode('/', $args);
 
-  $token_info = token_info();
+  $token_info = \Drupal::token()->getInfo();
 
   preg_match_all('/\[([^\s\]:]*):?([^\s\]]*)?\]?/', $string, $matches);
   $types = $matches[1];
@@ -246,7 +246,7 @@ function token_autocomplete() {
 }
 
 function token_autocomplete_type($string = '') {
-  $token_info = token_info();
+  $token_info = \Drupal::token()->getInfo();
   $types = $token_info['types'];
   $matches = array();
 
diff --git a/token.tokens.inc b/token.tokens.inc
index b6d743d..8285f10 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -396,7 +396,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
   // Current date tokens.
   // @todo Remove when http://drupal.org/node/943028 is fixed.
   if ($type == 'current-date') {
-    $replacements += token_generate('date', $tokens, array('date' => REQUEST_TIME), $options);
+    $replacements += \Drupal::token()->generate('date', $tokens, array('date' => REQUEST_TIME), $options);
   }
 
   // Comment tokens.
@@ -404,8 +404,8 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     $comment = $data['comment'];
 
     // Chained token relationships.
-    if (($url_tokens = token_find_with_prefix($tokens, 'url'))) {
-      $replacements += token_generate('url', $url_tokens, entity_uri('comment', $comment), $options);
+    if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
+      $replacements += \Drupal::token()->generate('url', $url_tokens, entity_uri('comment', $comment), $options);
     }
   }
 
@@ -432,14 +432,14 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // Chained token relationships.
-    if (!empty($node->tnid) && ($source_tokens = token_find_with_prefix($tokens, 'source')) && $source_node = node_load($node->tnid)) {
-      $replacements += token_generate('node', $source_tokens, array('node' => $source_node), $options);
+    if (!empty($node->tnid) && ($source_tokens = \Drupal::token()->findWithPrefix($tokens, 'source')) && $source_node = node_load($node->tnid)) {
+      $replacements += \Drupal::token()->generate('node', $source_tokens, array('node' => $source_node), $options);
     }
-    if (($node_type_tokens = token_find_with_prefix($tokens, 'content-type')) && $node_type = node_type_load($node->type)) {
-      $replacements += token_generate('content-type', $node_type_tokens, array('node_type' => $node_type), $options);
+    if (($node_type_tokens = \Drupal::token()->findWithPrefix($tokens, 'content-type')) && $node_type = node_type_load($node->type)) {
+      $replacements += \Drupal::token()->generate('content-type', $node_type_tokens, array('node_type' => $node_type), $options);
     }
-    if (($url_tokens = token_find_with_prefix($tokens, 'url'))) {
-      $replacements += token_generate('url', $url_tokens, entity_uri('node', $node), $options);
+    if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
+      $replacements += \Drupal::token()->generate('url', $url_tokens, entity_uri('node', $node), $options);
     }
   }
 
@@ -500,20 +500,20 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // Chained token relationships.
-    if (($url_tokens = token_find_with_prefix($tokens, 'url'))) {
-      $replacements += token_generate('url', $url_tokens, entity_uri('taxonomy_term', $term), $options);
+    if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
+      $replacements += \Drupal::token()->generate('url', $url_tokens, entity_uri('taxonomy_term', $term), $options);
     }
     // [term:parents:*] chained tokens.
-    if ($parents_tokens = token_find_with_prefix($tokens, 'parents')) {
+    if ($parents_tokens = \Drupal::token()->findWithPrefix($tokens, 'parents')) {
       if ($parents = token_taxonomy_term_load_all_parents($term->tid)) {
-        $replacements += token_generate('array', $parents_tokens, array('array' => $parents), $options);
+        $replacements += \Drupal::token()->generate('array', $parents_tokens, array('array' => $parents), $options);
       }
     }
-    if ($root_tokens = token_find_with_prefix($tokens, 'root')) {
+    if ($root_tokens = \Drupal::token()->findWithPrefix($tokens, 'root')) {
       $parents = taxonomy_get_parents_all($term->tid);
       $root_term = end($parents);
       if ($root_term->tid != $term->tid) {
-        $replacements += token_generate('term', $root_tokens, array('term' => $root_term), $options);
+        $replacements += \Drupal::token()->generate('term', $root_tokens, array('term' => $root_term), $options);
       }
     }
   }
@@ -577,19 +577,19 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // Chained token relationships.
-    if (variable_get('user_pictures', 0) && !empty($account->picture) && ($picture_tokens = token_find_with_prefix($tokens, 'picture'))) {
+    if (variable_get('user_pictures', 0) && !empty($account->picture) && ($picture_tokens = \Drupal::token()->findWithPrefix($tokens, 'picture'))) {
       // @todo Remove when core bug http://drupal.org/node/978028 is fixed.
       $account->picture->description = '';
-      $replacements += token_generate('file', $picture_tokens, array('file' => $account->picture), $options);
+      $replacements += \Drupal::token()->generate('file', $picture_tokens, array('file' => $account->picture), $options);
     }
-    if ($url_tokens = token_find_with_prefix($tokens, 'url')) {
-      $replacements += token_generate('url', $url_tokens, entity_uri('user', $account), $options);
+    if ($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) {
+      $replacements += \Drupal::token()->generate('url', $url_tokens, entity_uri('user', $account), $options);
     }
-    if ($role_tokens = token_find_with_prefix($tokens, 'roles')) {
+    if ($role_tokens = \Drupal::token()->findWithPrefix($tokens, 'roles')) {
       // The roles array may be set from checkbox values so ensure it always
       // has 'proper' data with the role names.
       $roles = array_intersect_key(user_roles(), $account->roles);
-      $replacements += token_generate('array', $role_tokens, array('array' => $roles), $options);
+      $replacements += \Drupal::token()->generate('array', $role_tokens, array('array' => $roles), $options);
     }
   }
 
@@ -644,20 +644,20 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // Chained token relationships.
-    if (!empty($link['plid']) && ($source_tokens = token_find_with_prefix($tokens, 'parent')) && $parent = token_menu_link_load($link['plid'])) {
-      $replacements += token_generate('menu-link', $source_tokens, array('menu-link' => $parent), $options);
+    if (!empty($link['plid']) && ($source_tokens = \Drupal::token()->findWithPrefix($tokens, 'parent')) && $parent = token_menu_link_load($link['plid'])) {
+      $replacements += \Drupal::token()->generate('menu-link', $source_tokens, array('menu-link' => $parent), $options);
     }
     // [menu-link:parents:*] chained tokens.
-    if ($parents_tokens = token_find_with_prefix($tokens, 'parents')) {
+    if ($parents_tokens = \Drupal::token()->findWithPrefix($tokens, 'parents')) {
       if ($parents = token_menu_link_load_all_parents($link['mlid'])) {
-        $replacements += token_generate('array', $parents_tokens, array('array' => $parents), $options);
+        $replacements += \Drupal::token()->generate('array', $parents_tokens, array('array' => $parents), $options);
       }
     }
-    if (!empty($link['p1']) && $link['p1'] != $link['mlid'] && ($root_tokens = token_find_with_prefix($tokens, 'root')) && $root = token_menu_link_load($link['p1'])) {
-      $replacements += token_generate('menu-link', $root_tokens, array('menu-link' => $root), $options);
+    if (!empty($link['p1']) && $link['p1'] != $link['mlid'] && ($root_tokens = \Drupal::token()->findWithPrefix($tokens, 'root')) && $root = token_menu_link_load($link['p1'])) {
+      $replacements += \Drupal::token()->generate('menu-link', $root_tokens, array('menu-link' => $root), $options);
     }
-    if ($url_tokens = token_find_with_prefix($tokens, 'url')) {
-      $replacements += token_generate('url', $url_tokens, array('path' => $link['href']), $options);
+    if ($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) {
+      $replacements += \Drupal::token()->generate('url', $url_tokens, array('path' => $link['href']), $options);
     }
   }
 
@@ -687,7 +687,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
     // @deprecated
     // [current-page:arg] dynamic tokens.
-    if ($arg_tokens = token_find_with_prefix($tokens, 'arg')) {
+    if ($arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'arg')) {
       foreach ($arg_tokens as $name => $original) {
         if (is_numeric($name) && ($arg = arg($name)) && isset($arg)) {
           $replacements[$original] = $sanitize ? String::checkPlain($arg) : $arg;
@@ -696,7 +696,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // [current-page:query] dynamic tokens.
-    if ($query_tokens = token_find_with_prefix($tokens, 'query')) {
+    if ($query_tokens = \Drupal::token()->findWithPrefix($tokens, 'query')) {
       foreach ($query_tokens as $name => $original) {
         // @todo Should this use filter_input()?
         if (\Drupal::request()->query->has($name)) {
@@ -707,8 +707,8 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // Chained token relationships.
-    if ($url_tokens = token_find_with_prefix($tokens, 'url')) {
-      $replacements += token_generate('url', $url_tokens, array('path' => $current_path), $options);
+    if ($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) {
+      $replacements += \Drupal::token()->generate('url', $url_tokens, array('path' => $current_path), $options);
     }
   }
 
@@ -752,17 +752,17 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // [url:arg:*] chained tokens.
-    if ($arg_tokens = token_find_with_prefix($tokens, 'args')) {
+    if ($arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'args')) {
       $value = empty($url_options['alias']) ? drupal_get_path_alias($path, $language_code) : $path;
-      $replacements += token_generate('array', $arg_tokens, array('array' => arg(NULL, $value)), $options);
+      $replacements += \Drupal::token()->generate('array', $arg_tokens, array('array' => arg(NULL, $value)), $options);
     }
 
     // [url:unaliased:*] chained tokens.
-    if ($unaliased_tokens = token_find_with_prefix($tokens, 'unaliased')) {
+    if ($unaliased_tokens = \Drupal::token()->findWithPrefix($tokens, 'unaliased')) {
       $unaliased_token_data['path'] = $path;
       $unaliased_token_data['options'] = isset($data['options']) ? $data['options'] : array();
       $unaliased_token_data['options']['alias'] = TRUE;
-      $replacements += token_generate('url', $unaliased_tokens, $unaliased_token_data, $options);
+      $replacements += \Drupal::token()->generate('url', $unaliased_tokens, $unaliased_token_data, $options);
     }
   }
 
@@ -794,13 +794,13 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // [entity:url:*] chained tokens.
-    if (($url_tokens = token_find_with_prefix($tokens, 'url')) && _token_module($type, 'url') == 'token') {
-      $replacements += token_generate('url', $url_tokens, entity_uri($entity_type, $entity), $options);
+    if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) && _token_module($type, 'url') == 'token') {
+      $replacements += \Drupal::token()->generate('url', $url_tokens, entity_uri($entity_type, $entity), $options);
     }
 
     // [entity:original:*] chained tokens.
-    if (($original_tokens = token_find_with_prefix($tokens, 'original')) && _token_module($type, 'original') == 'token' && !empty($entity->original)) {
-      $replacements += token_generate($type, $original_tokens, array($type => $entity->original), $options);
+    if (($original_tokens = \Drupal::token()->findWithPrefix($tokens, 'original')) && _token_module($type, 'original') == 'token' && !empty($entity->original)) {
+      $replacements += \Drupal::token()->generate($type, $original_tokens, array($type => $entity->original), $options);
     }
 
     // Pass through to an generic 'entity' token type generation.
@@ -810,7 +810,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       'token_type' => $type,
     );
     // @todo Investigate passing through more data like everything from entity_extract_ids().
-    $replacements += token_generate('entity', $tokens, $entity_data, $options);
+    $replacements += \Drupal::token()->generate('entity', $tokens, $entity_data, $options);
   }
 
   // Array tokens.
@@ -849,7 +849,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // [array:value:*] dynamic tokens.
-    if ($value_tokens = token_find_with_prefix($tokens, 'value')) {
+    if ($value_tokens = \Drupal::token()->findWithPrefix($tokens, 'value')) {
       foreach ($value_tokens as $key => $original) {
         if ($key[0] !== '#' && isset($array[$key])) {
           $replacements[$original] = token_render_array_value($array[$key], $options);
@@ -858,20 +858,20 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // [array:join:*] dynamic tokens.
-    if ($join_tokens = token_find_with_prefix($tokens, 'join')) {
+    if ($join_tokens = \Drupal::token()->findWithPrefix($tokens, 'join')) {
       foreach ($join_tokens as $join => $original) {
         $replacements[$original] = token_render_array($array, array('join' => $join) + $options);
       }
     }
 
     // [array:keys:*] chained tokens.
-    if ($key_tokens = token_find_with_prefix($tokens, 'keys')) {
-      $replacements += token_generate('array', $key_tokens, array('array' => $keys), $options);
+    if ($key_tokens = \Drupal::token()->findWithPrefix($tokens, 'keys')) {
+      $replacements += \Drupal::token()->generate('array', $key_tokens, array('array' => $keys), $options);
     }
 
     // [array:reversed:*] chained tokens.
-    if ($reversed_tokens = token_find_with_prefix($tokens, 'reversed')) {
-      $replacements += token_generate('array', $reversed_tokens, array('array' => array_reverse($array, TRUE)), array('array sort' => FALSE) + $options);
+    if ($reversed_tokens = \Drupal::token()->findWithPrefix($tokens, 'reversed')) {
+      $replacements += \Drupal::token()->generate('array', $reversed_tokens, array('array' => array_reverse($array, TRUE)), array('array sort' => FALSE) + $options);
     }
 
     // @todo Handle if the array values are not strings and could be chained.
@@ -888,7 +888,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // [custom:hash:*] dynamic token.
-    if ($hash_tokens = token_find_with_prefix($tokens, 'hash')) {
+    if ($hash_tokens = \Drupal::token()->findWithPrefix($tokens, 'hash')) {
       $algos = hash_algos();
       foreach ($hash_tokens as $name => $original) {
         if (in_array($name, $algos)) {
@@ -1025,8 +1025,8 @@ function book_tokens($type, $tokens, array $data = array(), array $options = arr
       }
 
       // Chained token relationships.
-      if ($book_tokens = token_find_with_prefix($tokens, 'book')) {
-        $replacements += token_generate('menu-link', $book_tokens, array('menu-link' => $link), $options);
+      if ($book_tokens = \Drupal::token()->findWithPrefix($tokens, 'book')) {
+        $replacements += \Drupal::token()->generate('menu-link', $book_tokens, array('menu-link' => $link), $options);
       }
     }
   }
@@ -1114,9 +1114,9 @@ function menu_tokens($type, $tokens, array $data = array(), array $options = arr
       }
 
       // Chained token relationships.
-      if ($menu_tokens = token_find_with_prefix($tokens, 'menu-link')) {
+      if ($menu_tokens = \Drupal::token()->findWithPrefix($tokens, 'menu-link')) {
         if ($link = token_node_menu_link_load($node)) {
-          $replacements += token_generate('menu-link', $menu_tokens, array('menu-link' => $link), $options);
+          $replacements += \Drupal::token()->generate('menu-link', $menu_tokens, array('menu-link' => $link), $options);
         }
       }
     }
@@ -1140,8 +1140,8 @@ function menu_tokens($type, $tokens, array $data = array(), array $options = arr
     }
 
     // Chained token relationships.
-    if (($menu_tokens = token_find_with_prefix($tokens, 'menu')) && $menu = menu_load($link['menu_name'])) {
-      $replacements += token_generate('menu', $menu_tokens, array('menu' => $menu), $options);
+    if (($menu_tokens = \Drupal::token()->findWithPrefix($tokens, 'menu')) && $menu = menu_load($link['menu_name'])) {
+      $replacements += \Drupal::token()->generate('menu', $menu_tokens, array('menu' => $menu), $options);
     }
   }
 
@@ -1253,9 +1253,9 @@ function profile_tokens($type, $tokens, array $data = array(), array $options =
 
     // Chained token relationships.
     foreach ($profile_fields as $field) {
-      if ($field->type == 'date' && isset($account->{$field->name}) && $field_tokens = token_find_with_prefix($tokens, $field->token_name)) {
+      if ($field->type == 'date' && isset($account->{$field->name}) && $field_tokens = \Drupal::token()->findWithPrefix($tokens, $field->token_name)) {
         $date = $account->{$field->name};
-        $replacements += token_generate('date', $field_tokens, array('date' => gmmktime(0, 0, 0, $date['month'], $date['day'], $date['year'])), $options);
+        $replacements += \Drupal::token()->generate('date', $field_tokens, array('date' => gmmktime(0, 0, 0, $date['month'], $date['day'], $date['year'])), $options);
       }
     }
   }
-- 
1.9.3 (Apple Git-50)


From 185360853c82789f43ec64e0489d5da71d06e097 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <grom358@gmail.com>
Date: Fri, 14 Feb 2014 13:54:29 +1300
Subject: [PATCH 046/230] Issue #1962358 by grom358: Added missing import of
 Field

---
 token.tokens.inc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/token.tokens.inc b/token.tokens.inc
index 8285f10..52a896d 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -6,6 +6,7 @@
  */
 use Drupal\Component\Utility\String;
 use Drupal\Core\Render\Element;
+use Drupal\field\Field;
 
 /**
  * Implements hook_token_info_alter().
-- 
1.9.3 (Apple Git-50)


From 8684a4fd424ea448eeb18329a23295342e4dd312 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 10:50:36 +1000
Subject: [PATCH 047/230] Issue #1962358 by larowlan: Create token view modes
 on install

---
 token.install | 25 +++++++++++++++++++++++++
 token.module  | 19 ++++++++-----------
 2 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/token.install b/token.install
index 5a8e5df..5b0286f 100644
--- a/token.install
+++ b/token.install
@@ -39,6 +39,31 @@ function token_requirements($phase = 'runtime') {
 }
 
 /**
+ * Implements hook_install().
+ */
+function token_install() {
+  // Create a token view mode for each entity type.
+  $info = \Drupal::entityManager()->getDefinitions();
+  foreach ($info as $entity_type => $entity_type_info) {
+    // We're only interested in entity types with a view builder.
+    if (!$entity_type_info->getViewBuilderClass()) {
+      continue;
+    }
+    // Try to find a token view mode for that entity type.
+    $storage_controller = \Drupal::entityManager()->getStorageController('view_mode');
+    // Add a token view mode if it does not already exist.
+    if (!$storage_controller->load("$entity_type.token")) {
+      $storage_controller->create(array(
+        'targetEntityType' => $entity_type,
+        'id' => "$entity_type.token",
+        'status' => TRUE,
+        'label' => t('Token'),
+      ))->save();
+    }
+  }
+}
+
+/**
  * Build a list of Drupal 6 tokens and their Drupal 7 token names.
  */
 function _token_upgrade_token_list() {
diff --git a/token.module b/token.module
index 00f804a..1b1cc14 100644
--- a/token.module
+++ b/token.module
@@ -368,15 +368,7 @@ function token_get_entity_mapping($value_type = 'token', $value = NULL) {
  */
 function token_entity_info_alter(&$info) {
   foreach (array_keys($info) as $entity_type) {
-    // Add a token view mode if it does not already exist.
-    if (!empty($info[$entity_type]['view modes']) && !isset($info[$entity_type]['view modes']['token'])) {
-      $info[$entity_type]['view modes']['token'] = array(
-        'label' => t('Tokens'),
-        'custom settings' => FALSE,
-      );
-    }
-
-    if (!empty($info[$entity_type]['token type'])) {
+    if ($info[$entity_type]->get('token type')) {
       // If the entity's token type is already defined, great!
       continue;
     }
@@ -386,17 +378,22 @@ function token_entity_info_alter(&$info) {
       case 'taxonomy_term':
       case 'taxonomy_vocabulary':
         // Stupid taxonomy token types...
-        $info[$entity_type]['token type'] = str_replace('taxonomy_', '', $entity_type);
+        $info[$entity_type]->set('token type', str_replace('taxonomy_', '', $entity_type));
         break;
+
       default:
         // By default the token type is the same as the entity type.
-        $info[$entity_type]['token type'] = $entity_type;
+        $info[$entity_type]->set('token type', $entity_type);
         break;
     }
   }
 }
 
 /**
+ * Implements hook_entity_view_modes_info().
+ */
+
+/**
  * Implements hook_module_implements_alter().
  *
  * Adds missing token support for core modules.
-- 
1.9.3 (Apple Git-50)


From 731404c89524455acc278447814594ca778f7b2c Mon Sep 17 00:00:00 2001
From: Cameron Zemek <grom358@gmail.com>
Date: Fri, 14 Feb 2014 14:10:05 +1300
Subject: [PATCH 048/230] Issue #1962358 by grom358: Replaced call to undefined
 function system_get_date_types()

---
 token.tokens.inc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index 52a896d..1f6bc19 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -79,11 +79,11 @@ function token_token_info_alter(&$info) {
 
   // Add support for custom date formats.
   // @todo Remove when http://drupal.org/node/1173706 is fixed.
-  $date_format_types = system_get_date_types();
+  $date_format_types = \Drupal::entityManager()->getStorageController('date_format')->loadMultiple();
   foreach ($date_format_types as $date_format_type => $date_format_type_info) {
     if (!isset($info['tokens']['date'][$date_format_type])) {
       $info['tokens']['date'][$date_format_type] = array(
-        'name' => $date_format_type_info['title'],
+        'name' => $date_format_type_info->label(),
         'description' => t("A date in '@type' format. (%date)", array('@type' => $date_format_type, '%date' => format_date(REQUEST_TIME, $date_format_type))),
         'module' => 'token',
       );
@@ -386,7 +386,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     $date = !empty($data['date']) ? $data['date'] : REQUEST_TIME;
 
     // @todo Remove when http://drupal.org/node/1173706 is fixed.
-    $date_format_types = system_get_date_types();
+    $date_format_types = \Drupal::entityManager()->getStorageController('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);
-- 
1.9.3 (Apple Git-50)


From 0cffaff5658de65c294ef250a5c8aa9ea7b48edb Mon Sep 17 00:00:00 2001
From: Cameron Zemek <grom358@gmail.com>
Date: Fri, 14 Feb 2014 14:27:11 +1300
Subject: [PATCH 049/230] Issue #1962358 by grom358: Field type and formatter
 types are not plugins

---
 token.module     | 4 ++--
 token.tokens.inc | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/token.module b/token.module
index 1b1cc14..c249e34 100644
--- a/token.module
+++ b/token.module
@@ -275,11 +275,11 @@ function token_field_display_alter(&$display, $context) {
     // If the token view mode fell back to the 'default' view mode, then
     // use the default token formatter.
     if (empty($view_mode_settings[$context['view_mode']]['custom_settings'])) {
-      $field_type_info = field_info_field_types($context['field']['type']);
+      $field_type_info = \Drupal::service('plugin.manager.field.field_type')->getDefinition($context['field']['type']);
       if (!empty($field_type_info['default_token_formatter'])) {
         $display['type'] = $field_type_info['default_token_formatter'];
 
-        $formatter_info = field_info_formatter_types($display['type']);
+        $formatter_info = \Drupal::service('plugin.manager.field.formatter')->getDefinition($display['type']);
         $display['settings'] = isset($formatter_info['settings']) ? $formatter_info['settings'] : array();
         $display['settings']['label'] = 'hidden';
         $display['module'] = $formatter_info['module'];
diff --git a/token.tokens.inc b/token.tokens.inc
index 1f6bc19..9fd6de5 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -1297,7 +1297,7 @@ function _token_field_info($field_name = NULL) {
 
       $fields = field_info_fields();
       $instances = Field::fieldInfo()->getInstances();
-      $type_info = field_info_field_types();
+      $type_info = \Drupal::service('plugin.manager.field.field_type')->getDefinitions();
       $entity_info = \Drupal::entityManager()->getDefinitions();
 
       foreach ($fields as $field) {
-- 
1.9.3 (Apple Git-50)


From af43fc5cf3a0a2601b6eb21c8e9c05923cacf7aa Mon Sep 17 00:00:00 2001
From: Cameron Zemek <grom358@gmail.com>
Date: Fri, 14 Feb 2014 14:28:05 +1300
Subject: [PATCH 050/230] Issue #1962358 by grom358: Fixed typo of __FUNCTION__
 constant

---
 token.module | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.module b/token.module
index c249e34..522e452 100644
--- a/token.module
+++ b/token.module
@@ -1200,7 +1200,7 @@ function token_taxonomy_term_load_all_parents($tid) {
  * @see token_menu_link_load()
  */
 function token_node_menu_link_load($node) {
-  $cache = &drupal_static(__FUNCTIon__, array());
+  $cache = &drupal_static(__FUNCTION__, array());
 
   if (!isset($cache[$node->nid])) {
     $mlid = FALSE;
-- 
1.9.3 (Apple Git-50)


From e62744fe9e61fdab21aed207e9e43e5779169a1d Mon Sep 17 00:00:00 2001
From: Cameron Zemek <grom358@gmail.com>
Date: Fri, 14 Feb 2014 14:48:53 +1300
Subject: [PATCH 051/230] Issue #1962358 by grom358: Replaced use of
 entity_label and entity_uri

---
 token.module     |  2 +-
 token.tokens.inc | 14 +++++++-------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/token.module b/token.module
index 522e452..278836b 100644
--- a/token.module
+++ b/token.module
@@ -1179,7 +1179,7 @@ function token_taxonomy_term_load_all_parents($tid) {
     array_shift($parents); // Remove this term from the array.
     $parents = array_reverse($parents);
     foreach ($parents as $term) {
-      $cache[$tid][$term->tid] = entity_label('taxonomy_term', $term);
+      $cache[$tid][$term->tid] = $term->label();
     }
   }
 
diff --git a/token.tokens.inc b/token.tokens.inc
index 9fd6de5..01a0fe5 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -406,7 +406,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
     // Chained token relationships.
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, entity_uri('comment', $comment), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, $comment->urlInfo(), $options);
     }
   }
 
@@ -440,7 +440,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       $replacements += \Drupal::token()->generate('content-type', $node_type_tokens, array('node_type' => $node_type), $options);
     }
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, entity_uri('node', $node), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, $node->urlInfo(), $options);
     }
   }
 
@@ -502,7 +502,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
     // Chained token relationships.
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, entity_uri('taxonomy_term', $term), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, $term->urlInfo(), $options);
     }
     // [term:parents:*] chained tokens.
     if ($parents_tokens = \Drupal::token()->findWithPrefix($tokens, 'parents')) {
@@ -584,7 +584,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       $replacements += \Drupal::token()->generate('file', $picture_tokens, array('file' => $account->picture), $options);
     }
     if ($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, entity_uri('user', $account), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, $account->urlInfo(), $options);
     }
     if ($role_tokens = \Drupal::token()->findWithPrefix($tokens, 'roles')) {
       // The roles array may be set from checkbox values so ensure it always
@@ -780,14 +780,14 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'url':
-          if (_token_module($type, 'url') == 'token' && $uri = entity_uri($entity_type, $entity)) {
+          if (_token_module($type, 'url') == 'token' && $uri = $entity->urlInfo()) {
             $replacements[$original] = url($uri['path'], $uri['options']);
           }
           break;
 
         case 'original':
           if (_token_module($type, 'original') == 'token' && !empty($entity->original)) {
-            $label = entity_label($entity_type, $entity->original);
+            $label = $entity->original->label();
             $replacements[$original] = $sanitize ? String::checkPlain($label) : $label;
           }
           break;
@@ -796,7 +796,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
     // [entity:url:*] chained tokens.
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) && _token_module($type, 'url') == 'token') {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, entity_uri($entity_type, $entity), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, $entity->urlInfo(), $options);
     }
 
     // [entity:original:*] chained tokens.
-- 
1.9.3 (Apple Git-50)


From 86aebeddb48696670181bb97c09080d3dcde0187 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 11:38:31 +1000
Subject: [PATCH 052/230] Issue #1962358 by larowlan: User picture is a field

---
 token.tokens.inc | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index 01a0fe5..67429ec 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -196,13 +196,11 @@ function token_token_info() {
     'restricted' => TRUE,
     // 'type' => 'url',
   );
-  if (variable_get('user_pictures', 0)) {
-    $info['tokens']['user']['picture'] = array(
-      'name' => t('Picture'),
-      'description' => t('The picture of the user.'),
-      'type' => 'file',
-    );
-  }
+  $info['tokens']['user']['picture'] = array(
+    'name' => t('Picture'),
+    'description' => t('The picture of the user.'),
+    'type' => 'file',
+  );
   $info['tokens']['user']['roles'] = array(
     'name' => t('Roles'),
     'description' => t('The user roles associated with the user account.'),
@@ -564,10 +562,9 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'picture':
-          if (variable_get('user_pictures', 0)) {
-            $replacements[$original] = theme('user_picture', array('account' => $account));
-          }
+          $replacements[$original] = theme('user_picture', array('account' => $account));
           break;
+
         case 'roles':
           // The roles array may be set from checkbox values so ensure it always
           // has 'proper' data with the role names.
@@ -578,10 +575,8 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // Chained token relationships.
-    if (variable_get('user_pictures', 0) && !empty($account->picture) && ($picture_tokens = \Drupal::token()->findWithPrefix($tokens, 'picture'))) {
-      // @todo Remove when core bug http://drupal.org/node/978028 is fixed.
-      $account->picture->description = '';
-      $replacements += \Drupal::token()->generate('file', $picture_tokens, array('file' => $account->picture), $options);
+    if (!empty($account->user_picture) && ($picture_tokens = \Drupal::token()->findWithPrefix($tokens, 'picture'))) {
+      $replacements += \Drupal::token()->generate('file', $picture_tokens, array('file' => $account->user_picture->entity), $options);
     }
     if ($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) {
       $replacements += \Drupal::token()->generate('url', $url_tokens, $account->urlInfo(), $options);
-- 
1.9.3 (Apple Git-50)


From 1bb8cda90340fe41d106d5dcc8a8ed353b3cd2d8 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 11:41:22 +1000
Subject: [PATCH 053/230] Issue #1962358 by larowlan: ip_address() removed

---
 token.tokens.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index 67429ec..c889120 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -594,7 +594,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'ip-address':
-          $ip = ip_address();
+          $ip = \Drupal::request()->getClientIp();
           $replacements[$original] = $sanitize ? String::checkPlain($ip) : $ip;
           break;
       }
-- 
1.9.3 (Apple Git-50)


From cd94727788f527797c7e0c021b04a26170725b6b Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 15:13:15 +1300
Subject: [PATCH 054/230] Issue #1962358 by larowlan:
 taxonomy_get_parents_all() replaced

---
 token.module     | 2 +-
 token.tokens.inc | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/token.module b/token.module
index 278836b..598ea07 100644
--- a/token.module
+++ b/token.module
@@ -1175,7 +1175,7 @@ function token_taxonomy_term_load_all_parents($tid) {
 
   if (!isset($cache[$tid])) {
     $cache[$tid] = array();
-    $parents = taxonomy_get_parents_all($tid);
+    $parents = taxonomy_term_load_parents_all($tid);
     array_shift($parents); // Remove this term from the array.
     $parents = array_reverse($parents);
     foreach ($parents as $term) {
diff --git a/token.tokens.inc b/token.tokens.inc
index c889120..4d333ec 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -489,7 +489,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           break;
 
         case 'root':
-          $parents = taxonomy_get_parents_all($term->tid);
+          $parents = taxonomy_term_load_parents_all($term->tid);
           $root_term = end($parents);
           if ($root_term->tid != $term->tid) {
             $replacements[$original] = $sanitize ? String::checkPlain($root_term->name) : $root_term->name;
@@ -509,7 +509,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       }
     }
     if ($root_tokens = \Drupal::token()->findWithPrefix($tokens, 'root')) {
-      $parents = taxonomy_get_parents_all($term->tid);
+      $parents = taxonomy_term_load_parents_all($term->tid);
       $root_term = end($parents);
       if ($root_term->tid != $term->tid) {
         $replacements += \Drupal::token()->generate('term', $root_tokens, array('term' => $root_term), $options);
-- 
1.9.3 (Apple Git-50)


From db04a01f9eecb79aaaf998dac4c60f2b2a0a3f0b Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 15:53:31 +1300
Subject: [PATCH 055/230] Issue #1962358 by larowlan: drupal_random_bytes()
 removed

---
 token.tokens.inc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index 4d333ec..a71c77f 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -4,6 +4,7 @@
  * @file
  * Token callbacks for the token module.
  */
+use Drupal\Component\Utility\Crypt;
 use Drupal\Component\Utility\String;
 use Drupal\Core\Render\Element;
 use Drupal\field\Field;
@@ -888,7 +889,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       $algos = hash_algos();
       foreach ($hash_tokens as $name => $original) {
         if (in_array($name, $algos)) {
-          $replacements[$original] = hash($name, drupal_random_bytes(55));
+          $replacements[$original] = hash($name, Crypt::randomStringHashed(55));
         }
       }
     }
-- 
1.9.3 (Apple Git-50)


From fab2eb19537919f3260c699734bcd400c01b0b2a Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 15:54:15 +1300
Subject: [PATCH 056/230] Issue #1962358 by larowlan: Use new entity API
 elements

---
 token.tokens.inc | 53 +++++++++++++++++++++++++++--------------------------
 1 file changed, 27 insertions(+), 26 deletions(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index a71c77f..e80b4fc 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -82,6 +82,7 @@ function token_token_info_alter(&$info) {
   // @todo Remove when http://drupal.org/node/1173706 is fixed.
   $date_format_types = \Drupal::entityManager()->getStorageController('date_format')->loadMultiple();
   foreach ($date_format_types as $date_format_type => $date_format_type_info) {
+    /* @var \Drupal\system\Entity\DateFormat $date_format_type_info */
     if (!isset($info['tokens']['date'][$date_format_type])) {
       $info['tokens']['date'][$date_format_type] = array(
         'name' => $date_format_type_info->label(),
@@ -401,6 +402,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
   // Comment tokens.
   if ($type == 'comment' && !empty($data['comment'])) {
+    /* @var \Drupal\comment\CommentInterface $comment */
     $comment = $data['comment'];
 
     // Chained token relationships.
@@ -411,21 +413,22 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
   // Node tokens.
   if ($type == 'node' && !empty($data['node'])) {
+    /* @var \Drupal\node\NodeInterface $node */
     $node = $data['node'];
 
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'source':
           if (!empty($node->tnid) && $source_node = node_load($node->tnid)) {
-            $title = $source_node->title;
+            $title = $source_node->label();
             $replacements[$original] = $sanitize ? filter_xss($title) : $title;
           }
           break;
         case 'log':
-          $replacements[$original] = $sanitize ? filter_xss($node->log) : $node->log;
+          $replacements[$original] = $sanitize ? filter_xss($node->log->value) : $node->log->value;
           break;
         case 'content-type':
-          $type_name = node_type_get_name($node);
+          $type_name = \Drupal::entityManager()->getStorageController('node_type')->load($node->getType())->label();
           $replacements[$original] = $sanitize ? String::checkPlain($type_name) : $type_name;
           break;
       }
@@ -475,24 +478,25 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
   // Taxonomy term tokens.
   if ($type == 'term' && !empty($data['term'])) {
+    /* @var \Drupal\taxonomy\TermInterface $term */
     $term = $data['term'];
 
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'edit-url':
-          $replacements[$original] = url("taxonomy/term/{$term->tid}/edit", $url_options);
+          $replacements[$original] = url("taxonomy/term/{$term->id()}/edit", $url_options);
           break;
 
         case 'parents':
-          if ($parents = token_taxonomy_term_load_all_parents($term->tid)) {
+          if ($parents = token_taxonomy_term_load_all_parents($term->id())) {
             $replacements[$original] = token_render_array($parents, $options);
           }
           break;
 
         case 'root':
-          $parents = taxonomy_term_load_parents_all($term->tid);
+          $parents = taxonomy_term_load_parents_all($term->id());
           $root_term = end($parents);
-          if ($root_term->tid != $term->tid) {
+          if ($root_term->tid != $term->id()) {
             $replacements[$original] = $sanitize ? String::checkPlain($root_term->name) : $root_term->name;
           }
           break;
@@ -505,14 +509,14 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
     // [term:parents:*] chained tokens.
     if ($parents_tokens = \Drupal::token()->findWithPrefix($tokens, 'parents')) {
-      if ($parents = token_taxonomy_term_load_all_parents($term->tid)) {
+      if ($parents = token_taxonomy_term_load_all_parents($term->id())) {
         $replacements += \Drupal::token()->generate('array', $parents_tokens, array('array' => $parents), $options);
       }
     }
     if ($root_tokens = \Drupal::token()->findWithPrefix($tokens, 'root')) {
-      $parents = taxonomy_term_load_parents_all($term->tid);
+      $parents = taxonomy_term_load_parents_all($term->id());
       $root_term = end($parents);
-      if ($root_term->tid != $term->tid) {
+      if ($root_term->tid != $term->id()) {
         $replacements += \Drupal::token()->generate('term', $root_tokens, array('term' => $root_term), $options);
       }
     }
@@ -558,6 +562,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
   // User tokens.
   if ($type == 'user' && !empty($data['user'])) {
+    /* @var \Drupal\user\UserInterface $account */
     $account = $data['user'];
 
     foreach ($tokens as $name => $original) {
@@ -569,7 +574,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
         case 'roles':
           // The roles array may be set from checkbox values so ensure it always
           // has 'proper' data with the role names.
-          $roles = array_intersect_key(user_roles(), $account->roles);
+          $roles = array_intersect_key(user_roles(), $account->getRoles());
           $replacements[$original] = token_render_array($roles, $options);
           break;
       }
@@ -585,7 +590,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     if ($role_tokens = \Drupal::token()->findWithPrefix($tokens, 'roles')) {
       // The roles array may be set from checkbox values so ensure it always
       // has 'proper' data with the role names.
-      $roles = array_intersect_key(user_roles(), $account->roles);
+      $roles = array_intersect_key(user_roles(), $account->getRoles());
       $replacements += \Drupal::token()->generate('array', $role_tokens, array('array' => $roles), $options);
     }
   }
@@ -765,6 +770,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
   // Entity tokens.
   if (!empty($data[$type]) && $entity_type = token_get_entity_mapping('token', $type)) {
+    /* @var \Drupal\Core\Entity\EntityInterface $entity */
     $entity = $data[$type];
 
     // Sometimes taxonomy terms are not properly loaded.
@@ -943,7 +949,7 @@ function token_tokens_alter(array &$replacements, array $context) {
             $account = drupal_anonymous_user();
             $account->name = $comment->name;
           }
-          $name = format_username($account);
+          $name = $account->getUsername();
           $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
           break;
       }
@@ -957,12 +963,9 @@ function token_tokens_alter(array &$replacements, array $context) {
     foreach ($context['tokens'] as $name => $original) {
       switch ($name) {
         case 'author':
-          // http://drupal.org/node/1185842 was fixed in core release 7.9.
-          if (version_compare(VERSION, '7.9', '<')) {
-            $account = user_load($node->uid);
-            $name = format_username($account);
-            $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
-          }
+          $account = user_load($node->uid);
+          $name = $account->getUsername();
+          $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
           break;
       }
     }
@@ -975,12 +978,9 @@ function token_tokens_alter(array &$replacements, array $context) {
     foreach ($context['tokens'] as $name => $original) {
       switch ($name) {
         case 'owner':
-          // http://drupal.org/node/978028 was fixed in core release 7.7.
-          if (version_compare(VERSION, '7.7', '<')) {
-            $account = user_load($file->uid);
-            $name = format_username($account);
-            $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
-          }
+          $account = user_load($file->uid);
+          $name = $account->getUsername();
+          $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
           break;
       }
     }
@@ -1400,13 +1400,14 @@ function field_tokens($type, $tokens, array $data = array(), array $options = ar
     $entity_type = $data['entity_type'];
 
     // The field API does weird stuff to the entity, so let's clone it.
+    /* @var \Drupal\Core\Entity\EntityInterface $entity */
     $entity = clone $data['entity'];
 
     // Reset the prepared view flag in case token generation is called from
     // inside field_attach_view().
     unset($entity->_field_view_prepared);
 
-    list(, , $bundle) = entity_extract_ids($entity_type, $entity);
+    $bundle = $entity->bundle();
     $fields = Field::fieldInfo()->getBundleInstances($entity_type, $bundle);
 
     foreach (array_keys($fields) as $field_name) {
-- 
1.9.3 (Apple Git-50)


From f8ddd79ce60a73d3a9b231831b682911addc1f55 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 15:54:33 +1300
Subject: [PATCH 057/230] Issue #1962358 by larowlan: drupal_get_path_alias()
 removed

---
 token.tokens.inc | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index e80b4fc..6ee71e0 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -726,12 +726,12 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'path':
-          $value = empty($url_options['alias']) ? drupal_get_path_alias($path, $language_code) : $path;
+          $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getPathAlias($path, $language_code) : $path;
           $replacements[$original] = $sanitize ? String::checkPlain($value) : $value;
           break;
         case 'alias':
           // @deprecated
-          $alias = drupal_get_path_alias($path, $language_code);
+          $alias = \Drupal::service('path.alias_manager')->getPathAlias($path, $language_code);
           $replacements[$original] = $sanitize ? String::checkPlain($alias) : $alias;
           break;
         case 'absolute':
@@ -747,7 +747,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           $replacements[$original] = url($path, array('alias' => TRUE) + $url_options);
           break;
         case 'args':
-          $value = empty($url_options['alias']) ? drupal_get_path_alias($path, $language_code) : $path;
+          $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getPathAlias($path, $language_code) : $path;
           $replacements[$original] = token_render_array(arg(NULL, $value), $options);
           break;
       }
@@ -755,7 +755,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
     // [url:arg:*] chained tokens.
     if ($arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'args')) {
-      $value = empty($url_options['alias']) ? drupal_get_path_alias($path, $language_code) : $path;
+      $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getPathAlias($path, $language_code) : $path;
       $replacements += \Drupal::token()->generate('array', $arg_tokens, array('array' => arg(NULL, $value)), $options);
     }
 
-- 
1.9.3 (Apple Git-50)


From 638fe589b15dd9623f6803f65bc428de0aec69d0 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 15:54:47 +1300
Subject: [PATCH 058/230] Issue #1962358 by larowlan: profile removed from core

---
 token.tokens.inc | 103 -------------------------------------------------------
 1 file changed, 103 deletions(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index 6ee71e0..68d5aa8 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -1176,109 +1176,6 @@ function menu_tokens($type, $tokens, array $data = array(), array $options = arr
 }
 
 /**
- * Implements hook_token_info() on behalf of profile.module.
- */
-function profile_token_info() {
-  $info = array();
-
-  foreach (_token_profile_fields() as $field) {
-    $info['tokens']['user'][$field->token_name] = array(
-      'name' => String::checkPlain($field->title),
-      'description' => t('@category @type field.', array('@category' => drupal_ucfirst($field->category), '@type' => $field->type)),
-    );
-
-    switch ($field->type) {
-      case 'date':
-        $info['tokens']['user'][$field->token_name]['type'] = 'date';
-        break;
-    }
-  }
-
-  return $info;
-}
-
-/**
- * Implements hook_tokens() on behalf of profile.module.
- */
-function profile_tokens($type, $tokens, array $data = array(), array $options = array()) {
-  $replacements = array();
-  $sanitize = !empty($options['sanitize']);
-  $language_code = isset($options['language']) ? $options['language']->language : NULL;
-
-  if ($type == 'user' && !empty($data['user'])) {
-    $account = $data['user'];
-
-    // Load profile fields if this is the global user account.
-    // @see http://drupal.org/node/361471
-    // @see http://drupal.org/node/967330
-    if ($account->uid == $GLOBALS['user']->uid && isset($account->timestamp)) {
-      $profile_users = array($account->uid => $account);
-      profile_user_load($profile_users);
-      $account = $profile_users[$account->uid];
-    }
-
-    $profile_fields = _token_profile_fields();
-    foreach ($tokens as $name => $original) {
-      if (isset($profile_fields[$name]) && !empty($account->{$profile_fields[$name]->name})) {
-        $value = $account->{$profile_fields[$name]->name};
-        switch ($profile_fields[$name]->type) {
-          case 'textarea':
-            $replacements[$original] = $sanitize ? check_markup($value, filter_default_format($account), '', TRUE) : $value;
-            break;
-          case 'date':
-            $timestamp = gmmktime(0, 0, 0, $value['month'], $value['day'], $value['year']);
-            $replacements[$original] = format_date($timestamp, 'medium', '', NULL, $language_code);
-            break;
-          case 'url':
-            $replacements[$original] = $sanitize ? check_url($value) : $value;
-            break;
-          case 'checkbox':
-            // Checkbox field if checked should return the text.
-            $replacements[$original] = $sanitize ? String::checkPlain($profile_fields[$name]->title) : $profile_fields[$name]->title;
-            break;
-          case 'list':
-            $value = preg_split("/[,\n\r]/", $value);
-            $value = array_map('trim', $value);
-            $value = implode(', ', $value);
-            // Intentionally fall through to the default condition.
-          default:
-            $replacements[$original] = $sanitize ? String::checkPlain($value) : $value;
-            break;
-        }
-      }
-    }
-
-    // Chained token relationships.
-    foreach ($profile_fields as $field) {
-      if ($field->type == 'date' && isset($account->{$field->name}) && $field_tokens = \Drupal::token()->findWithPrefix($tokens, $field->token_name)) {
-        $date = $account->{$field->name};
-        $replacements += \Drupal::token()->generate('date', $field_tokens, array('date' => gmmktime(0, 0, 0, $date['month'], $date['day'], $date['year'])), $options);
-      }
-    }
-  }
-
-  return $replacements;
-}
-
-/**
- * Fetch an array of profile field objects, keyed by token name.
- */
-function _token_profile_fields() {
-  $fields = &drupal_static(__FUNCTION__);
-
-  if (!isset($fields)) {
-    $fields = array();
-    $results = db_query("SELECT name, title, category, type FROM {profile_field}");
-    foreach ($results as $field) {
-      $field->token_name = token_clean_token_name($field->name);
-      $fields[$field->token_name] = $field;
-    }
-  }
-
-  return $fields;
-}
-
-/**
  * Fetch an array of field data used for tokens.
  */
 function _token_field_info($field_name = NULL) {
-- 
1.9.3 (Apple Git-50)


From e5f5bd7e42cd5909c670921ae4a41b125c2844c7 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 15:58:20 +1300
Subject: [PATCH 059/230] Issue #1962358 by larowlan: entity info is an object

---
 token.module | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.module b/token.module
index 598ea07..d567723 100644
--- a/token.module
+++ b/token.module
@@ -342,7 +342,7 @@ function token_get_entity_mapping($value_type = 'token', $value = NULL) {
 
   if (empty($mapping)) {
     foreach (\Drupal::entityManager()->getDefinitions() as $entity_type => $info) {
-      $mapping[$entity_type] = !empty($info['token type']) ? $info['token type'] : $entity_type;
+      $mapping[$entity_type] = $info->get('token type') ? $info->get('token type') : $entity_type;
     }
   }
 
-- 
1.9.3 (Apple Git-50)


From 4056d7561e16ddd6e91338a8ea75fb6c09bfeab0 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <grom358@gmail.com>
Date: Fri, 14 Feb 2014 16:22:35 +1300
Subject: [PATCH 060/230] Issue #1962358 by grom358: Fixed errors preventing
 help page from loading

---
 token.module       | 10 ++++------
 token.services.yml |  4 ++--
 token.tokens.inc   | 46 +++++++++++++++++++++++-----------------------
 3 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/token.module b/token.module
index d567723..6ca3f9d 100644
--- a/token.module
+++ b/token.module
@@ -439,8 +439,6 @@ function token_flush_caches() {
  * @see hook_token_info_alter()
  */
 function token_get_info($token_type = NULL, $token = NULL) {
-  global $language_interface;
-
   // Use the advanced drupal_static() pattern, since this is called very often.
   static $drupal_static_fast;
   if (!isset($drupal_static_fast)) {
@@ -449,7 +447,8 @@ function token_get_info($token_type = NULL, $token = NULL) {
   $token_info = &$drupal_static_fast['token_info'];
 
   if (empty($token_info)) {
-    $cid = "info:{$language_interface->langcode}";
+    $langcode = \Drupal::languageManager()->getCurrentLanguage()->id;
+    $cid = "info:{$langcode}";
 
     if ($cache = cache('cache_token')->get($cid)) {
       $token_info = $cache->data;
@@ -812,8 +811,6 @@ function token_form_user_admin_settings_alter(&$form, &$form_state) {
  *   An optional array with the current parents of the tokens.
  */
 function token_build_tree($token_type, array $options = array()) {
-  global $language_interface;
-
   // Static cache of already built token trees.
   $trees = &drupal_static(__FUNCTION__, array());
 
@@ -833,7 +830,8 @@ function token_build_tree($token_type, array $options = array()) {
     $token_type = $entity_token_type;
   }
 
-  $tree_cid = "tree:{$token_type}:{$language_interface->langcode}:{$options['depth']}";
+  $langcode = \Drupal::languageManager()->getCurrentLanguage()->id;
+  $tree_cid = "tree:{$token_type}:{$langcode}:{$options['depth']}";
 
   // If we do not have this base tree in the static cache, check {cache_token}
   // otherwise generate and store it in the cache.
diff --git a/token.services.yml b/token.services.yml
index 7c5938d..71fe59b 100644
--- a/token.services.yml
+++ b/token.services.yml
@@ -1,8 +1,8 @@
 services:
-  cache.token:
+  cache.cache_token:
     class: Drupal\Core\Cache\CacheBackendInterface
     tags:
       - { name: cache.bin }
     factory_method: get
     factory_service: cache_factory
-    arguments: [token]
+    arguments: [cache_token]
diff --git a/token.tokens.inc b/token.tokens.inc
index 68d5aa8..6c776e0 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -47,7 +47,8 @@ function token_token_info_alter(&$info) {
   // Add [token:url] tokens for any URI-able entities.
   $entities = \Drupal::entityManager()->getDefinitions();
   foreach ($entities as $entity => $entity_info) {
-    if (!isset($entity_info['token type'])) {
+    /* @var \Drupal\Core\Entity\EntityType $entity_info */
+    if (!$entity_info->hasKey('token type')) {
       continue;
     }
 
@@ -1194,31 +1195,30 @@ function _token_field_info($field_name = NULL) {
       $entity_info = \Drupal::entityManager()->getDefinitions();
 
       foreach ($fields as $field) {
-        $key = $field['field_name'];
-        if (!empty($field['bundles'])) {
-          foreach (array_keys($field['bundles']) as $entity) {
-            // Make sure a token type exists for this entity.
-            $token_type = token_get_entity_mapping('entity', $entity);
-            if (empty($token_type)) {
+        /* @var \Drupal\field\FieldInterface $field */
+        $key = $field->getName();
+        foreach (array_keys($field->getBundles()) as $entity) {
+          // Make sure a token type exists for this entity.
+          $token_type = token_get_entity_mapping('entity', $entity);
+          if (empty($token_type)) {
+            continue;
+          }
+
+          $info[$key]['token types'][] = $token_type;
+          $info[$key] += array('labels' => array(), 'bundles' => array());
+
+          // Find which label is most commonly used.
+          foreach ($field['bundles'][$entity] as $bundle) {
+            // Field information will included fields attached to disabled
+            // bundles, so check that the bundle exists before provided a
+            // token for it.
+            // @see http://drupal.org/node/1252566
+            if (!isset($entity_info[$entity]['bundles'][$bundle])) {
               continue;
             }
 
-            $info[$key]['token types'][] = $token_type;
-            $info[$key] += array('labels' => array(), 'bundles' => array());
-
-            // Find which label is most commonly used.
-            foreach ($field['bundles'][$entity] as $bundle) {
-              // Field information will included fields attached to disabled
-              // bundles, so check that the bundle exists before provided a
-              // token for it.
-              // @see http://drupal.org/node/1252566
-              if (!isset($entity_info[$entity]['bundles'][$bundle])) {
-                continue;
-              }
-
-              $info[$key]['labels'][] = $instances[$entity][$bundle][$key]['label'];
-              $info[$key]['bundles'][$token_type][$bundle] = $entity_info[$entity]['bundles'][$bundle]['label'];
-            }
+            $info[$key]['labels'][] = $instances[$entity][$bundle][$key]['label'];
+            $info[$key]['bundles'][$token_type][$bundle] = $entity_info[$entity]['bundles'][$bundle]['label'];
           }
         }
 
-- 
1.9.3 (Apple Git-50)


From 7a3e8d78c80ef0dc0f48b27e81748f94693f25be Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 13:36:41 +1000
Subject: [PATCH 061/230] Issue #1962358 by larowlan: Clean up TestBase

---
 lib/Drupal/token/Tests/TokenTestBase.php | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenTestBase.php b/lib/Drupal/token/Tests/TokenTestBase.php
index c2e2b45..6c884eb 100644
--- a/lib/Drupal/token/Tests/TokenTestBase.php
+++ b/lib/Drupal/token/Tests/TokenTestBase.php
@@ -6,7 +6,9 @@
  */
 namespace Drupal\token\Tests;
 
+use Drupal\Core\Entity\EntityInterface;
 use Drupal\simpletest\WebTestBase;
+use Drupal\Core\Language\Language;
 
 /**
  * Helper test class with some added functions for testing.
@@ -14,14 +16,7 @@ use Drupal\simpletest\WebTestBase;
 class TokenTestBase extends WebTestBase {
   protected $profile = 'testing';
 
-  public function setUp($modules = array()) {
-    $modules[] = 'path';
-    $modules[] = 'token';
-    $modules[] = 'token_test';
-    parent::setUp($modules);
-
-    variable_set('clean_url', 1);
-  }
+  protected static $modules = array('path', 'token', 'token_test');
 
   function assertToken($type, array $data, $token, $expected, array $options = array()) {
     return $this->assertTokens($type, $data, array($token => $expected), $options);
@@ -29,7 +24,7 @@ class TokenTestBase extends WebTestBase {
 
   function assertTokens($type, array $data, array $tokens, array $options = array()) {
     $input = $this->mapTokenNames($type, array_keys($tokens));
-    $replacements = token_generate($type, $input, $data, $options);
+    $replacements = \Drupal::token()->generate($input, $data, $options);
     foreach ($tokens as $name => $expected) {
       $token = $input[$name];
       if (!isset($expected)) {
@@ -59,7 +54,7 @@ class TokenTestBase extends WebTestBase {
 
   function assertNoTokens($type, array $data, array $tokens, array $options = array()) {
     $input = $this->mapTokenNames($type, $tokens);
-    $replacements = token_generate($type, $input, $data, $options);
+    $replacements = \Drupal::token()->generate($type, $input, $data, $options);
     foreach ($tokens as $name) {
       $token = $input[$name];
       $this->assertTrue(!isset($replacements[$token]), t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token)));
@@ -67,18 +62,18 @@ class TokenTestBase extends WebTestBase {
     return $values;
   }
 
-  function saveAlias($source, $alias, $language = LANGUAGE_NOT_SPECIFIED) {
+  function saveAlias($source, $alias, $language = Language::LANGCODE_NOT_SPECIFIED) {
     $alias = array(
       'source' => $source,
       'alias' => $alias,
       'language' => $language,
     );
-    path_save($alias);
+    \Drupal::service('path.crud')->save($alias['source'], $alias['alias']);
     return $alias;
   }
 
-  function saveEntityAlias($entity_type, $entity, $alias, $language = LANGUAGE_NOT_SPECIFIED) {
-    $uri = entity_uri($entity_type, $entity);
+  function saveEntityAlias($entity_type, EntityInterface $entity, $alias, $language = Language::LANGCODE_NOT_SPECIFIED) {
+    $uri = $entity->urlInfo();
     return $this->saveAlias($uri['path'], $alias, $language);
   }
 
@@ -95,12 +90,12 @@ class TokenTestBase extends WebTestBase {
       'data' => $data,
       'options' => $options,
     );
-    variable_set('token_page_tokens', $token_page_tokens);
+    \Drupal::state()->set('token_page_tokens', $token_page_tokens);
 
     $options += array('url_options' => array());
     $this->drupalGet($url, $options['url_options']);
     $this->refreshVariables();
-    $result = variable_get('token_page_tokens', array());
+    $result = \Drupal::state()->get('token_page_tokens', array());
 
     if (!isset($result['values']) || !is_array($result['values'])) {
       return $this->fail('Failed to generate tokens.');
@@ -118,4 +113,5 @@ class TokenTestBase extends WebTestBase {
       }
     }
   }
+
 }
-- 
1.9.3 (Apple Git-50)


From 427005e4c17448f238894ce19e06a444c34f888b Mon Sep 17 00:00:00 2001
From: Cameron Zemek <grom358@gmail.com>
Date: Fri, 14 Feb 2014 16:37:48 +1300
Subject: [PATCH 062/230] Issue #1962358 by grom358: Replaced calls to
 variable_get and token_replace

---
 tests/token_test.module | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/token_test.module b/tests/token_test.module
index 3174cb6..8af0b8d 100644
--- a/tests/token_test.module
+++ b/tests/token_test.module
@@ -9,12 +9,12 @@
  * Implements hook_exit().
  */
 function token_test_exit() {
-  if ($debug = variable_get('token_page_tokens', array())) {
+  if ($debug = \Drupal::state()->get('token_page_tokens', array())) {
     $debug += array('tokens' => array(), 'data' => array(), 'options' => array());
     foreach (array_keys($debug['tokens']) as $token) {
-      $debug['values'][$token] = token_replace($token, $debug['data'], $debug['options']);
+      $debug['values'][$token] = \Drupal::token()->replace($token, $debug['data'], $debug['options']);
     }
-    variable_set('token_page_tokens', $debug);
+    \Drupal::state()->set('token_page_tokens', $debug);
   }
 }
 
@@ -27,7 +27,7 @@ function token_test_date_format_types() {
   $info['token_test'] = t('Token test date format');
 
   // Explicitly set the variable here as well.
-  variable_set('date_format_token_test', 'Y');
+  \Drupal::state()->set('date_format_token_test', 'Y');
 
   return $info;
 }
-- 
1.9.3 (Apple Git-50)


From 30acad81d99ef0558d89c1537822a9e2d979eb19 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Sat, 15 Feb 2014 06:21:30 +1000
Subject: [PATCH 063/230] Issue #1962358 by larowlan: Fixes use of generate()
 in test base

---
 lib/Drupal/token/Tests/TokenTestBase.php | 2 +-
 token.tokens.inc                         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenTestBase.php b/lib/Drupal/token/Tests/TokenTestBase.php
index 6c884eb..dbcbb92 100644
--- a/lib/Drupal/token/Tests/TokenTestBase.php
+++ b/lib/Drupal/token/Tests/TokenTestBase.php
@@ -24,7 +24,7 @@ class TokenTestBase extends WebTestBase {
 
   function assertTokens($type, array $data, array $tokens, array $options = array()) {
     $input = $this->mapTokenNames($type, array_keys($tokens));
-    $replacements = \Drupal::token()->generate($input, $data, $options);
+    $replacements = \Drupal::token()->generate($type, $input, $data, $options);
     foreach ($tokens as $name => $expected) {
       $token = $input[$name];
       if (!isset($expected)) {
diff --git a/token.tokens.inc b/token.tokens.inc
index 6c776e0..2f47d24 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -770,7 +770,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
   }
 
   // Entity tokens.
-  if (!empty($data[$type]) && $entity_type = token_get_entity_mapping('token', $type)) {
+  if (!empty($data[$type]) && ($entity_type = token_get_entity_mapping('token', $type))) {
     /* @var \Drupal\Core\Entity\EntityInterface $entity */
     $entity = $data[$type];
 
-- 
1.9.3 (Apple Git-50)


From abe0f7c28b901a9acc99dc1a9188457e93c61cba Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Sat, 15 Feb 2014 13:06:19 +1300
Subject: [PATCH 064/230] Issue #1962358 by larowlan: setup block module for
 block test

---
 lib/Drupal/token/Tests/TokenBlockTestCase.php | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenBlockTestCase.php b/lib/Drupal/token/Tests/TokenBlockTestCase.php
index e34c2f4..8a571dc 100644
--- a/lib/Drupal/token/Tests/TokenBlockTestCase.php
+++ b/lib/Drupal/token/Tests/TokenBlockTestCase.php
@@ -10,6 +10,8 @@ namespace Drupal\token\Tests;
  * Tests block tokens.
  */
 class TokenBlockTestCase extends TokenTestBase {
+  protected static $modules = array('path', 'token', 'token_test', 'block');
+
   public static function getInfo() {
     return array(
       'name' => 'Block token tests',
@@ -19,9 +21,6 @@ class TokenBlockTestCase extends TokenTestBase {
   }
 
   public function setUp($modules = array()) {
-    $modules[] = 'block';
-    parent::setUp($modules);
-
     $this->admin_user = $this->drupalCreateUser(array('access content', 'administer blocks'));
     $this->drupalLogin($this->admin_user);
   }
-- 
1.9.3 (Apple Git-50)


From f1d97e48ccf0e957ab4f5a342bc77c150ce4f327 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Fri, 14 Feb 2014 12:11:10 +1300
Subject: [PATCH 065/230] Issue #1962358 by grom358: Replaced deprecated
 function calls

---
 token.module     | 26 ++++++++++----------
 token.pages.inc  |  2 +-
 token.tokens.inc | 72 ++++++++++++++++++++++++++++----------------------------
 3 files changed, 50 insertions(+), 50 deletions(-)

diff --git a/token.module b/token.module
index 1b19d20..b7a9d6c 100644
--- a/token.module
+++ b/token.module
@@ -74,7 +74,7 @@ function token_menu() {
   );*/
 
   // Devel token pages.
-  if (module_exists('devel')) {
+  if (\Drupal::moduleHandler()->module_exists('devel')) {
     $items['node/%node/devel/token'] = array(
       'title' => 'Tokens',
       'page callback' => 'token_devel_token_object',
@@ -132,7 +132,7 @@ function token_admin_menu_output_alter(&$content) {
     '#title' => t('Token registry'),
     '#href' => 'token/flush-cache',
     '#options' => array(
-      'query' => drupal_get_destination() + array('token' => drupal_get_token('token/flush-cache')),
+      'query' => drupal_get_destination() + array('token' => \Drupal::csrfToken()->get('token/flush-cache')),
     ),
   );
 }
@@ -339,7 +339,7 @@ function token_get_entity_mapping($value_type = 'token', $value = NULL) {
   $mapping = &drupal_static(__FUNCTION__, array());
 
   if (empty($mapping)) {
-    foreach (entity_get_info() as $entity_type => $info) {
+    foreach (\Drupal::entityManager()->getDefinitions() as $entity_type => $info) {
       $mapping[$entity_type] = !empty($info['token type']) ? $info['token type'] : $entity_type;
     }
   }
@@ -402,7 +402,7 @@ function token_entity_info_alter(&$info) {
 function token_module_implements_alter(&$implementations, $hook) {
   if ($hook == 'tokens' || $hook == 'token_info') {
     foreach (_token_core_supported_modules() as $module) {
-      if (module_exists($module)) {
+      if (\Drupal::moduleHandler()->moduleExists($module)) {
         $implementations[$module] = TRUE;
       }
     }
@@ -662,22 +662,22 @@ function token_element_validate(&$element, &$form_state) {
   // Validate if an element must have a minimum number of tokens.
   if (isset($element['#min_tokens']) && count($tokens) < $element['#min_tokens']) {
     // @todo Change this error message to include the minimum number.
-    $error = format_plural($element['#min_tokens'], 'The %element-title cannot contain fewer than one token.', 'The %element-title must contain at least @count tokens.', array('%element-title' => $title));
-    form_error($element, $error);
+    $error = \Drupal::translation()->formatPlural($element['#min_tokens'], 'The %element-title cannot contain fewer than one token.', 'The %element-title must contain at least @count tokens.', array('%element-title' => $title));
+    \Drupal::formBuilder()->setError($element, $error);
   }
 
   // Validate if an element must have a maximum number of tokens.
   if (isset($element['#max_tokens']) && count($tokens) > $element['#max_tokens']) {
     // @todo Change this error message to include the maximum number.
-    $error = format_plural($element['#max_tokens'], 'The %element-title must contain as most one token.', 'The %element-title must contain at most @count tokens.', array('%element-title' => $title));
-    form_error($element, $error);
+    $error = \Drupal::translation()->formatPlural($element['#max_tokens'], 'The %element-title must contain as most one token.', 'The %element-title must contain at most @count tokens.', array('%element-title' => $title));
+    \Drupal::formBuilder()->setError($element, $error);
   }
 
   // Check if the field defines specific token types.
   if (!empty($element['#token_types'])) {
     $invalid_tokens = token_get_invalid_tokens_by_context($tokens, $element['#token_types']);
     if ($invalid_tokens) {
-      form_error($element, t('The %element-title is using the following invalid tokens: @invalid-tokens.', array('%element-title' => $title, '@invalid-tokens' => implode(', ', $invalid_tokens))));
+      \Drupal::formBuilder()->setError($element, t('The %element-title is using the following invalid tokens: @invalid-tokens.', array('%element-title' => $title, '@invalid-tokens' => implode(', ', $invalid_tokens))));
     }
   }
 
@@ -743,7 +743,7 @@ function token_form_system_actions_configure_alter(&$form, $form_state) {
 function token_form_user_admin_settings_alter(&$form, &$form_state) {
   $email_token_help = t('Available variables are: [site:name], [site:url], [user:name], [user:mail], [site:login-url], [site:url-brief], [user:edit-url], [user:one-time-login-url], [user:cancel-url].');
 
-  foreach (element_children($form) as $key) {
+  foreach (Element::children($form) as $key) {
     $element = &$form[$key];
 
     // Remove the crummy default token help text.
@@ -770,7 +770,7 @@ function token_form_user_admin_settings_alter(&$form, &$form_state) {
         continue 2;
     }
 
-    foreach (element_children($element) as $sub_key) {
+    foreach (Element::children($element) as $sub_key) {
       if (!isset($element[$sub_key]['#type'])) {
         continue;
       }
@@ -1058,7 +1058,7 @@ function _token_menu_link_translate(&$item) {
   // options array. For performance reasons we only invoke this hook if the link
   // has the 'alter' flag set in the options array.
   if (!empty($item['options']['alter'])) {
-    drupal_alter('translated_menu_link', $item, $map);
+    \Drupal::moduleHandler()->alter('translated_menu_link', $item, $map);
   }
 
   return $map;
@@ -1107,7 +1107,7 @@ function token_render_array(array $array, array $options = array()) {
 function token_render_array_value($value, array $options = array()) {
   $rendered = is_array($value) ? render($value) : (string) $value;
   if (!empty($options['sanitize'])) {
-    $rendered = check_plain($rendered);
+    $rendered = String::checkPlain($rendered);
   }
   return $rendered;
 }
diff --git a/token.pages.inc b/token.pages.inc
index d2f06e9..77ee7c8 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -215,7 +215,7 @@ function token_devel_token_object($entity_type, $entity) {
  * Page callback to clear the token registry caches.
  */
 function token_flush_cache_callback() {
-  if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], current_path())) {
+  if (!isset($_GET['token']) || !\Drupal::csrfToken()->validate($_GET['token'], current_path())) {
     return MENU_NOT_FOUND;
   }
 
diff --git a/token.tokens.inc b/token.tokens.inc
index 4ed44b8..8a3e2e5 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -31,17 +31,17 @@ function token_token_info_alter(&$info) {
   unset($info['tokens']['node']['type-name']);
 
   // Support 'url' type tokens for core tokens.
-  if (isset($info['tokens']['comment']['url']) && module_exists('comment')) {
+  if (isset($info['tokens']['comment']['url']) && \Drupal::moduleHandler()->moduleExists('comment')) {
     $info['tokens']['comment']['url']['type'] = 'url';
   }
   $info['tokens']['node']['url']['type'] = 'url';
-  if (isset($info['tokens']['term']['url']) && module_exists('taxonomy')) {
+  if (isset($info['tokens']['term']['url']) && \Drupal::moduleHandler()->moduleExists('taxonomy')) {
     $info['tokens']['term']['url']['type'] = 'url';
   }
   $info['tokens']['user']['url']['type'] = 'url';
 
   // Add [token:url] tokens for any URI-able entities.
-  $entities = entity_get_info();
+  $entities = \Drupal::entityManager()->getDefinitions();
   foreach ($entities as $entity => $entity_info) {
     if (!isset($entity_info['token type'])) {
       continue;
@@ -137,7 +137,7 @@ function token_token_info() {
   );
 
   // Taxonomy term and vocabulary tokens.
-  if (module_exists('taxonomy')) {
+  if (\Drupal::moduleHandler()->moduleExists('taxonomy')) {
     $info['tokens']['term']['edit-url'] = array(
       'name' => t('Edit URL'),
       'description' => t("The URL of the taxonomy term's edit page."),
@@ -424,7 +424,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           break;
         case 'content-type':
           $type_name = node_type_get_name($node);
-          $replacements[$original] = $sanitize ? check_plain($type_name) : $type_name;
+          $replacements[$original] = $sanitize ? String::checkPlain($type_name) : $type_name;
           break;
       }
     }
@@ -448,7 +448,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'name':
-          $replacements[$original] = $sanitize ? check_plain($node_type->name) : $node_type->name;
+          $replacements[$original] = $sanitize ? String::checkPlain($node_type->name) : $node_type->name;
           break;
         case 'machine-name':
           // This is a machine name so does not ever need to be sanitized.
@@ -491,7 +491,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           $parents = taxonomy_get_parents_all($term->tid);
           $root_term = end($parents);
           if ($root_term->tid != $term->tid) {
-            $replacements[$original] = $sanitize ? check_plain($root_term->name) : $root_term->name;
+            $replacements[$original] = $sanitize ? String::checkPlain($root_term->name) : $root_term->name;
           }
           break;
       }
@@ -541,11 +541,11 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       switch ($name) {
         case 'basename':
           $basename = pathinfo($file->uri, PATHINFO_BASENAME);
-          $replacements[$original] = $sanitize ? check_plain($basename) : $basename;
+          $replacements[$original] = $sanitize ? String::checkPlain($basename) : $basename;
           break;
         case 'extension':
           $extension = pathinfo($file->uri, PATHINFO_EXTENSION);
-          $replacements[$original] = $sanitize ? check_plain($extension) : $extension;
+          $replacements[$original] = $sanitize ? String::checkPlain($extension) : $extension;
           break;
         case 'size-raw':
           $replacements[$original] = (int) $file->filesize;
@@ -597,7 +597,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       switch ($name) {
         case 'ip-address':
           $ip = ip_address();
-          $replacements[$original] = $sanitize ? check_plain($ip) : $ip;
+          $replacements[$original] = $sanitize ? String::checkPlain($ip) : $ip;
           break;
       }
     }
@@ -618,14 +618,14 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           $replacements[$original] = $link['mlid'];
           break;
         case 'title':
-          $replacements[$original] = $sanitize ? check_plain($link['title']) : $link['title'];
+          $replacements[$original] = $sanitize ? String::checkPlain($link['title']) : $link['title'];
           break;
         case 'url':
           $replacements[$original] = url($link['href'], $url_options);
           break;
         case 'parent':
           if (!empty($link['plid']) && $parent = token_menu_link_load($link['plid'])) {
-            $replacements[$original] = $sanitize ? check_plain($parent['title']) : $parent['title'];
+            $replacements[$original] = $sanitize ? String::checkPlain($parent['title']) : $parent['title'];
           }
           break;
         case 'parents':
@@ -635,7 +635,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           break;
         case 'root';
           if (!empty($link['p1']) && $link['p1'] != $link['mlid'] && $root = token_menu_link_load($link['p1'])) {
-            $replacements[$original] = $sanitize ? check_plain($root['title']) : $root['title'];
+            $replacements[$original] = $sanitize ? String::checkPlain($root['title']) : $root['title'];
           }
           break;
       }
@@ -688,7 +688,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     if ($arg_tokens = token_find_with_prefix($tokens, 'arg')) {
       foreach ($arg_tokens as $name => $original) {
         if (is_numeric($name) && ($arg = arg($name)) && isset($arg)) {
-          $replacements[$original] = $sanitize ? check_plain($arg) : $arg;
+          $replacements[$original] = $sanitize ? String::checkPlain($arg) : $arg;
         }
       }
     }
@@ -698,7 +698,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       foreach ($query_tokens as $name => $original) {
         // @todo Should this use filter_input()?
         if (isset($_GET[$name])) {
-          $replacements[$original] = $sanitize ? check_plain($_GET[$name]) : $_GET[$name];
+          $replacements[$original] = $sanitize ? String::checkPlain($_GET[$name]) : $_GET[$name];
         }
       }
     }
@@ -722,12 +722,12 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       switch ($name) {
         case 'path':
           $value = empty($url_options['alias']) ? drupal_get_path_alias($path, $language_code) : $path;
-          $replacements[$original] = $sanitize ? check_plain($value) : $value;
+          $replacements[$original] = $sanitize ? String::checkPlain($value) : $value;
           break;
         case 'alias':
           // @deprecated
           $alias = drupal_get_path_alias($path, $language_code);
-          $replacements[$original] = $sanitize ? check_plain($alias) : $alias;
+          $replacements[$original] = $sanitize ? String::checkPlain($alias) : $alias;
           break;
         case 'absolute':
           $replacements[$original] = url($path, $url_options);
@@ -784,7 +784,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
         case 'original':
           if (_token_module($type, 'original') == 'token' && !empty($entity->original)) {
             $label = entity_label($entity_type, $entity->original);
-            $replacements[$original] = $sanitize ? check_plain($label) : $label;
+            $replacements[$original] = $sanitize ? String::checkPlain($label) : $label;
           }
           break;
       }
@@ -822,12 +822,12 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
         case 'first':
           $value = $array[$keys[0]];
           $value = is_array($value) ? render($value) : (string) $value;
-          $replacements[$original] = $sanitize ? check_plain($value) : $value;
+          $replacements[$original] = $sanitize ? String::checkPlain($value) : $value;
           break;
         case 'last':
           $value = $array[$keys[count($keys) - 1]];
           $value = is_array($value) ? render($value) : (string) $value;
-          $replacements[$original] = $sanitize ? check_plain($value) : $value;
+          $replacements[$original] = $sanitize ? String::checkPlain($value) : $value;
           break;
         case 'count':
           $replacements[$original] = count($keys);
@@ -944,7 +944,7 @@ function token_tokens_alter(array &$replacements, array $context) {
             $account->name = $comment->name;
           }
           $name = format_username($account);
-          $replacements[$original] = $sanitize ? check_plain($name) : $name;
+          $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
           break;
       }
     }
@@ -961,7 +961,7 @@ function token_tokens_alter(array &$replacements, array $context) {
           if (version_compare(VERSION, '7.9', '<')) {
             $account = user_load($node->uid);
             $name = format_username($account);
-            $replacements[$original] = $sanitize ? check_plain($name) : $name;
+            $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
           }
           break;
       }
@@ -979,7 +979,7 @@ function token_tokens_alter(array &$replacements, array $context) {
           if (version_compare(VERSION, '7.7', '<')) {
             $account = user_load($file->uid);
             $name = format_username($account);
-            $replacements[$original] = $sanitize ? check_plain($name) : $name;
+            $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
           }
           break;
       }
@@ -1016,7 +1016,7 @@ function book_tokens($type, $tokens, array $data = array(), array $options = arr
       foreach ($tokens as $name => $original) {
         switch ($name) {
           case 'book':
-            $replacements[$original] = $sanitize ? check_plain($link['title']) : $link['title'];
+            $replacements[$original] = $sanitize ? String::checkPlain($link['title']) : $link['title'];
             break;
         }
       }
@@ -1105,7 +1105,7 @@ function menu_tokens($type, $tokens, array $data = array(), array $options = arr
       switch ($name) {
         case 'menu-link':
           if ($link = token_node_menu_link_load($node)) {
-            $replacements[$original] = $sanitize ? check_plain($link['title']) : $link['title'];
+            $replacements[$original] = $sanitize ? String::checkPlain($link['title']) : $link['title'];
           }
           break;
       }
@@ -1127,7 +1127,7 @@ function menu_tokens($type, $tokens, array $data = array(), array $options = arr
       switch ($name) {
         case 'menu':
           if ($menu = menu_load($link['menu_name'])) {
-            $replacements[$original] = $sanitize ? check_plain($menu['title']) : $menu['title'];
+            $replacements[$original] = $sanitize ? String::checkPlain($menu['title']) : $menu['title'];
           }
           break;
         case 'edit-url':
@@ -1149,7 +1149,7 @@ function menu_tokens($type, $tokens, array $data = array(), array $options = arr
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'name':
-          $replacements[$original] = $sanitize ? check_plain($menu['title']) : $menu['title'];
+          $replacements[$original] = $sanitize ? String::checkPlain($menu['title']) : $menu['title'];
           break;
         case 'machine-name':
           // This is a machine name so does not ever need to be sanitized.
@@ -1183,7 +1183,7 @@ function profile_token_info() {
 
   foreach (_token_profile_fields() as $field) {
     $info['tokens']['user'][$field->token_name] = array(
-      'name' => check_plain($field->title),
+      'name' => String::checkPlain($field->title),
       'description' => t('@category @type field.', array('@category' => drupal_ucfirst($field->category), '@type' => $field->type)),
     );
 
@@ -1234,7 +1234,7 @@ function profile_tokens($type, $tokens, array $data = array(), array $options =
             break;
           case 'checkbox':
             // Checkbox field if checked should return the text.
-            $replacements[$original] = $sanitize ? check_plain($profile_fields[$name]->title) : $profile_fields[$name]->title;
+            $replacements[$original] = $sanitize ? String::checkPlain($profile_fields[$name]->title) : $profile_fields[$name]->title;
             break;
           case 'list':
             $value = preg_split("/[,\n\r]/", $value);
@@ -1242,7 +1242,7 @@ function profile_tokens($type, $tokens, array $data = array(), array $options =
             $value = implode(', ', $value);
             // Intentionally fall through to the default condition.
           default:
-            $replacements[$original] = $sanitize ? check_plain($value) : $value;
+            $replacements[$original] = $sanitize ? String::checkPlain($value) : $value;
             break;
         }
       }
@@ -1292,9 +1292,9 @@ function _token_field_info($field_name = NULL) {
       $info = array();
 
       $fields = field_info_fields();
-      $instances = field_info_instances();
+      $instances = Field::fieldInfo()->getInstances();
       $type_info = field_info_field_types();
-      $entity_info = entity_get_info();
+      $entity_info = \Drupal::entityManager()->getDefinitions();
 
       foreach ($fields as $field) {
         $key = $field['field_name'];
@@ -1328,7 +1328,7 @@ function _token_field_info($field_name = NULL) {
         if (isset($info[$key])) {
           $labels = array_count_values($info[$key]['labels']);
           arsort($labels);
-          $info[$key]['label'] = check_plain(key($labels));
+          $info[$key]['label'] = String::checkPlain(key($labels));
 
           // Generate a description for the token.
           $info[$key]['description'] = t('@type field.', array('@type' => $type_info[$field['type']]['label']));
@@ -1338,7 +1338,7 @@ function _token_field_info($field_name = NULL) {
         }
       }
 
-      drupal_alter('token_field_info', $info);
+      \Drupal::moduleHandler()->alter('token_field_info', $info);
       cache('cache_token')->set('field:info', $info);
     }
   }
@@ -1407,7 +1407,7 @@ function field_tokens($type, $tokens, array $data = array(), array $options = ar
     unset($entity->_field_view_prepared);
 
     list(, , $bundle) = entity_extract_ids($entity_type, $entity);
-    $fields = field_info_instances($entity_type, $bundle);
+    $fields = Field::fieldInfo()->getBundleInstances($entity_type, $bundle);
 
     foreach (array_keys($fields) as $field_name) {
       // Do not continue if the field is empty.
@@ -1450,7 +1450,7 @@ function token_pre_render_field_token(&$elements) {
 
   // Prevent multi-value fields from appearing smooshed together by appending
   // a join suffix to all but the last value.
-  $deltas = element_get_visible_children($elements);
+  $deltas = Element::getVisibleChildren($elements);
   $count = count($deltas);
   if ($count > 1) {
     $join = isset($elements['#token_options']['join']) ? $elements['#token_options']['join'] : ", ";
-- 
1.9.3 (Apple Git-50)


From 3ae37f1eaea635cf9786b4f354b0f6b8803f3432 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Fri, 14 Feb 2014 12:21:51 +1300
Subject: [PATCH 066/230] Issue #1962358 by grom358: Replaced use of  with
 Request object

---
 token.pages.inc  | 2 +-
 token.tokens.inc | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/token.pages.inc b/token.pages.inc
index 77ee7c8..ac71c9f 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -215,7 +215,7 @@ function token_devel_token_object($entity_type, $entity) {
  * Page callback to clear the token registry caches.
  */
 function token_flush_cache_callback() {
-  if (!isset($_GET['token']) || !\Drupal::csrfToken()->validate($_GET['token'], current_path())) {
+  if (!\Drupal::request()->query->has('token') || !\Drupal::csrfToken()->validate(\Drupal::request()->query->get('token'), current_path())) {
     return MENU_NOT_FOUND;
   }
 
diff --git a/token.tokens.inc b/token.tokens.inc
index 8a3e2e5..6494ebf 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -697,8 +697,9 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     if ($query_tokens = token_find_with_prefix($tokens, 'query')) {
       foreach ($query_tokens as $name => $original) {
         // @todo Should this use filter_input()?
-        if (isset($_GET[$name])) {
-          $replacements[$original] = $sanitize ? String::checkPlain($_GET[$name]) : $_GET[$name];
+        if (\Drupal::request()->query->has($name)) {
+          $value = \Drupal::request()->query->get($name);
+          $replacements[$original] = $sanitize ? String::checkPlain($value) : $value;
         }
       }
     }
-- 
1.9.3 (Apple Git-50)


From 48d821b763d068f2ae963eb87a85482f4bfe23bd Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Fri, 14 Feb 2014 12:34:38 +1300
Subject: [PATCH 067/230] Issue #1962358 by grom358: Replaced use of  with
 Request object

---
 token.module | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/token.module b/token.module
index b7a9d6c..1f9f515 100644
--- a/token.module
+++ b/token.module
@@ -1138,14 +1138,14 @@ function token_render_cache_get($elements) {
  */
 function token_render_cache_set(&$markup, $elements) {
   // This should only run of drupal_render_cache_set() did not.
-  if (in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD'))) {
+  if (in_array(\Drupal::request()->server->get('REQUEST_METHOD'), array('GET', 'HEAD'))) {
     return FALSE;
   }
 
-  $original_method = $_SERVER['REQUEST_METHOD'];
-  $_SERVER['REQUEST_METHOD'] = 'GET';
+  $original_method = \Drupal::request()->server->get('REQUEST_METHOD');
+  \Drupal::request()->server->set('REQUEST_METHOD', 'GET');
   drupal_render_cache_set($markup, $elements);
-  $_SERVER['REQUEST_METHOD'] = $original_method;
+  \Drupal::request()->server->set('REQUEST_METHOD', $original_method);
 }
 
 function token_menu_link_load_all_parents($mlid) {
-- 
1.9.3 (Apple Git-50)


From 50663820254a72325fc19b4ee80b62b670540842 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Fri, 14 Feb 2014 13:08:15 +1300
Subject: [PATCH 068/230] Issue #1962358 by grom358: Fixed typo with call to
 moduleExists and replaced a deprecated call to module_exists

---
 token.module | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/token.module b/token.module
index 1f9f515..88b2603 100644
--- a/token.module
+++ b/token.module
@@ -74,7 +74,7 @@ function token_menu() {
   );*/
 
   // Devel token pages.
-  if (\Drupal::moduleHandler()->module_exists('devel')) {
+  if (\Drupal::moduleHandler()->moduleExists('devel')) {
     $items['node/%node/devel/token'] = array(
       'title' => 'Tokens',
       'page callback' => 'token_devel_token_object',
@@ -695,7 +695,7 @@ function token_element_validate_token_context(&$element, &$form_state) {
  * Implements hook_form_FORM_ID_alter().
  */
 function token_form_field_ui_field_edit_form_alter(&$form, $form_state) {
-  if (($form['#field']['type'] == 'file' || $form['#field']['type'] == 'image') && isset($form['instance']['settings']['file_directory']) && !module_exists('filefield_paths')) {
+  if (($form['#field']['type'] == 'file' || $form['#field']['type'] == 'image') && isset($form['instance']['settings']['file_directory']) && !\Drupal::moduleHandler()->moduleExists('filefield_paths')) {
     // GAH! We can only support global tokens in the upload file directory path.
     $form['instance']['settings']['file_directory']['#element_validate'][] = 'token_element_validate';
     $form['instance']['settings']['file_directory']['#token_types'] = array();
-- 
1.9.3 (Apple Git-50)


From b7d92fbd86e550aa68a538920244cd75d57276b7 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Sat, 15 Feb 2014 13:08:44 +1300
Subject: [PATCH 069/230] Issue #1962358 by grom358: Replaced call to
 variable_get

---
 lib/Drupal/token/Tests/TokenBlockTestCase.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenBlockTestCase.php b/lib/Drupal/token/Tests/TokenBlockTestCase.php
index e34c2f4..a61584c 100644
--- a/lib/Drupal/token/Tests/TokenBlockTestCase.php
+++ b/lib/Drupal/token/Tests/TokenBlockTestCase.php
@@ -34,11 +34,11 @@ class TokenBlockTestCase extends TokenTestBase {
     $this->drupalPost('admin/structure/block/add', $edit, 'Save block');
 
     $this->drupalGet('node');
-    $this->assertText('Welcome to ' . variable_get('site_name', 'Drupal') . ' block title');
+    $this->assertText('Welcome to ' . \Drupal::config('system.site')->get('name') . ' block title');
 
     // Ensure that tokens are not double-escaped when output as a block title.
     $node = $this->drupalCreateNode(array('title' => "Site's first node"));
-    $this->drupalGet('node/' . $node->nid);
+    $this->drupalGet('node/' . $node->id());
     // The apostraphe should only be escaped once via check_plain().
     $this->assertRaw("Site&#039;s first node block title");
   }
-- 
1.9.3 (Apple Git-50)


From c5c9af5df4b1d82b54c117e78a93c9fbf151c8bf Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Fri, 14 Feb 2014 13:27:33 +1300
Subject: [PATCH 070/230] Issue #1962358 by grom358: Added missing use of
 Element

---
 token.module | 1 +
 1 file changed, 1 insertion(+)

diff --git a/token.module b/token.module
index 88b2603..7ba6cc5 100644
--- a/token.module
+++ b/token.module
@@ -4,6 +4,7 @@
  * @file
  * Enhances the token API in core: adds a browseable UI, missing tokens, etc.
  */
+use Drupal\Core\Render\Element;
 
 /**
  * The maximum depth for token tree recursion.
-- 
1.9.3 (Apple Git-50)


From 4f67a2696a487666b562bb02f54dfa0abba4ae17 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Fri, 14 Feb 2014 13:29:58 +1300
Subject: [PATCH 071/230] Issue #1962358 by grom358: Added missing use for
 String

---
 token.module | 1 +
 1 file changed, 1 insertion(+)

diff --git a/token.module b/token.module
index 7ba6cc5..fff400b 100644
--- a/token.module
+++ b/token.module
@@ -4,6 +4,7 @@
  * @file
  * Enhances the token API in core: adds a browseable UI, missing tokens, etc.
  */
+use Drupal\Component\Utility\String;
 use Drupal\Core\Render\Element;
 
 /**
-- 
1.9.3 (Apple Git-50)


From c3ac5fa2980d5cca17654d29752dbb1139c4265f Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Fri, 14 Feb 2014 13:32:16 +1300
Subject: [PATCH 072/230] Issue #1962358 by grom358: Added missing use imports

---
 token.tokens.inc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/token.tokens.inc b/token.tokens.inc
index 6494ebf..b6d743d 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -4,6 +4,8 @@
  * @file
  * Token callbacks for the token module.
  */
+use Drupal\Component\Utility\String;
+use Drupal\Core\Render\Element;
 
 /**
  * Implements hook_token_info_alter().
-- 
1.9.3 (Apple Git-50)


From 7833fd452cf5741736de9ef3a727d5b057d8bfbc Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Fri, 14 Feb 2014 13:52:05 +1300
Subject: [PATCH 073/230] Issue #1962358 by grom358: Replaced calls to
 token_info etc to the Token service

---
 token.module     |  14 +++----
 token.pages.inc  |   4 +-
 token.tokens.inc | 114 +++++++++++++++++++++++++++----------------------------
 3 files changed, 66 insertions(+), 66 deletions(-)

diff --git a/token.module b/token.module
index fff400b..00f804a 100644
--- a/token.module
+++ b/token.module
@@ -210,7 +210,7 @@ function token_block_view_alter(&$data, $block) {
   if (!empty($block->title) && $block->title != '<none>') {
     // Perform unsanitized token replacement since _block_render_blocks() will
     // call check_plain() on $block->title.
-    $block->title = token_replace($block->title, array(), array('sanitize' => FALSE));
+    $block->title = \Drupal::token()->replace($block->title, array(), array('sanitize' => FALSE));
   }
 }
 
@@ -236,7 +236,7 @@ function token_form_block_admin_configure_alter(&$form, $form_state) {
  */
 function token_field_widget_form_alter(&$element, &$form_state, $context) {
   if (!empty($element['#description']) && is_string($element['#description'])) {
-    $element['#description'] = token_replace($element['#description']);
+    $element['#description'] = \Drupal::token()->replace($element['#description']);
   }
 }
 
@@ -458,7 +458,7 @@ function token_get_info($token_type = NULL, $token = NULL) {
       $token_info = $cache->data;
     }
     else {
-      $token_info = token_info();
+      $token_info = \Drupal::token()->getInfo();
 
       foreach (array_keys($token_info['types']) as $type_key) {
         if (isset($token_info['types'][$type_key]['type'])) {
@@ -569,7 +569,7 @@ function token_get_invalid_tokens_by_context($value, $valid_types = array()) {
   }
 
   $invalid_tokens = array();
-  $value_tokens = is_string($value) ? token_scan($value) : $value;
+  $value_tokens = is_string($value) ? \Drupal::token()->scan($value) : $value;
 
   foreach ($value_tokens as $type => $tokens) {
     if (!in_array($type, $valid_types)) {
@@ -620,7 +620,7 @@ function token_get_invalid_tokens($type, $tokens) {
       }
       else {
         // Resursively check the chained tokens.
-        $sub_tokens = token_find_with_prefix(array($token => $full_token), $parts[0]);
+        $sub_tokens = \Drupal::token()->findWithPrefix(array($token => $full_token), $parts[0]);
         $invalid_tokens = array_merge($invalid_tokens, token_get_invalid_tokens($sub_token_info['type'], $sub_tokens));
       }
     }
@@ -657,7 +657,7 @@ function token_element_validate(&$element, &$form_state) {
     return $element;
   }
 
-  $tokens = token_scan($value);
+  $tokens = \Drupal::token()->scan($value);
   $title = empty($element['#title']) ? $element['#parents'][0] : $element['#title'];
   // @todo Find old Drupal 6 style tokens and add them to invalid tokens.
 
@@ -870,7 +870,7 @@ function token_build_tree($token_type, array $options = array()) {
       }
     }
     if (!empty($token_values)) {
-      $token_values = token_generate($token_type, $token_values, $options['data']);
+      $token_values = \Drupal::token()->generate($token_type, $token_values, $options['data']);
       foreach ($token_values as $token => $replacement) {
         $tree[$token]['value'] = $replacement;
       }
diff --git a/token.pages.inc b/token.pages.inc
index ac71c9f..ef47d03 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -228,7 +228,7 @@ function token_autocomplete() {
   $args = func_get_args();
   $string = implode('/', $args);
 
-  $token_info = token_info();
+  $token_info = \Drupal::token()->getInfo();
 
   preg_match_all('/\[([^\s\]:]*):?([^\s\]]*)?\]?/', $string, $matches);
   $types = $matches[1];
@@ -246,7 +246,7 @@ function token_autocomplete() {
 }
 
 function token_autocomplete_type($string = '') {
-  $token_info = token_info();
+  $token_info = \Drupal::token()->getInfo();
   $types = $token_info['types'];
   $matches = array();
 
diff --git a/token.tokens.inc b/token.tokens.inc
index b6d743d..8285f10 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -396,7 +396,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
   // Current date tokens.
   // @todo Remove when http://drupal.org/node/943028 is fixed.
   if ($type == 'current-date') {
-    $replacements += token_generate('date', $tokens, array('date' => REQUEST_TIME), $options);
+    $replacements += \Drupal::token()->generate('date', $tokens, array('date' => REQUEST_TIME), $options);
   }
 
   // Comment tokens.
@@ -404,8 +404,8 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     $comment = $data['comment'];
 
     // Chained token relationships.
-    if (($url_tokens = token_find_with_prefix($tokens, 'url'))) {
-      $replacements += token_generate('url', $url_tokens, entity_uri('comment', $comment), $options);
+    if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
+      $replacements += \Drupal::token()->generate('url', $url_tokens, entity_uri('comment', $comment), $options);
     }
   }
 
@@ -432,14 +432,14 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // Chained token relationships.
-    if (!empty($node->tnid) && ($source_tokens = token_find_with_prefix($tokens, 'source')) && $source_node = node_load($node->tnid)) {
-      $replacements += token_generate('node', $source_tokens, array('node' => $source_node), $options);
+    if (!empty($node->tnid) && ($source_tokens = \Drupal::token()->findWithPrefix($tokens, 'source')) && $source_node = node_load($node->tnid)) {
+      $replacements += \Drupal::token()->generate('node', $source_tokens, array('node' => $source_node), $options);
     }
-    if (($node_type_tokens = token_find_with_prefix($tokens, 'content-type')) && $node_type = node_type_load($node->type)) {
-      $replacements += token_generate('content-type', $node_type_tokens, array('node_type' => $node_type), $options);
+    if (($node_type_tokens = \Drupal::token()->findWithPrefix($tokens, 'content-type')) && $node_type = node_type_load($node->type)) {
+      $replacements += \Drupal::token()->generate('content-type', $node_type_tokens, array('node_type' => $node_type), $options);
     }
-    if (($url_tokens = token_find_with_prefix($tokens, 'url'))) {
-      $replacements += token_generate('url', $url_tokens, entity_uri('node', $node), $options);
+    if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
+      $replacements += \Drupal::token()->generate('url', $url_tokens, entity_uri('node', $node), $options);
     }
   }
 
@@ -500,20 +500,20 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // Chained token relationships.
-    if (($url_tokens = token_find_with_prefix($tokens, 'url'))) {
-      $replacements += token_generate('url', $url_tokens, entity_uri('taxonomy_term', $term), $options);
+    if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
+      $replacements += \Drupal::token()->generate('url', $url_tokens, entity_uri('taxonomy_term', $term), $options);
     }
     // [term:parents:*] chained tokens.
-    if ($parents_tokens = token_find_with_prefix($tokens, 'parents')) {
+    if ($parents_tokens = \Drupal::token()->findWithPrefix($tokens, 'parents')) {
       if ($parents = token_taxonomy_term_load_all_parents($term->tid)) {
-        $replacements += token_generate('array', $parents_tokens, array('array' => $parents), $options);
+        $replacements += \Drupal::token()->generate('array', $parents_tokens, array('array' => $parents), $options);
       }
     }
-    if ($root_tokens = token_find_with_prefix($tokens, 'root')) {
+    if ($root_tokens = \Drupal::token()->findWithPrefix($tokens, 'root')) {
       $parents = taxonomy_get_parents_all($term->tid);
       $root_term = end($parents);
       if ($root_term->tid != $term->tid) {
-        $replacements += token_generate('term', $root_tokens, array('term' => $root_term), $options);
+        $replacements += \Drupal::token()->generate('term', $root_tokens, array('term' => $root_term), $options);
       }
     }
   }
@@ -577,19 +577,19 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // Chained token relationships.
-    if (variable_get('user_pictures', 0) && !empty($account->picture) && ($picture_tokens = token_find_with_prefix($tokens, 'picture'))) {
+    if (variable_get('user_pictures', 0) && !empty($account->picture) && ($picture_tokens = \Drupal::token()->findWithPrefix($tokens, 'picture'))) {
       // @todo Remove when core bug http://drupal.org/node/978028 is fixed.
       $account->picture->description = '';
-      $replacements += token_generate('file', $picture_tokens, array('file' => $account->picture), $options);
+      $replacements += \Drupal::token()->generate('file', $picture_tokens, array('file' => $account->picture), $options);
     }
-    if ($url_tokens = token_find_with_prefix($tokens, 'url')) {
-      $replacements += token_generate('url', $url_tokens, entity_uri('user', $account), $options);
+    if ($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) {
+      $replacements += \Drupal::token()->generate('url', $url_tokens, entity_uri('user', $account), $options);
     }
-    if ($role_tokens = token_find_with_prefix($tokens, 'roles')) {
+    if ($role_tokens = \Drupal::token()->findWithPrefix($tokens, 'roles')) {
       // The roles array may be set from checkbox values so ensure it always
       // has 'proper' data with the role names.
       $roles = array_intersect_key(user_roles(), $account->roles);
-      $replacements += token_generate('array', $role_tokens, array('array' => $roles), $options);
+      $replacements += \Drupal::token()->generate('array', $role_tokens, array('array' => $roles), $options);
     }
   }
 
@@ -644,20 +644,20 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // Chained token relationships.
-    if (!empty($link['plid']) && ($source_tokens = token_find_with_prefix($tokens, 'parent')) && $parent = token_menu_link_load($link['plid'])) {
-      $replacements += token_generate('menu-link', $source_tokens, array('menu-link' => $parent), $options);
+    if (!empty($link['plid']) && ($source_tokens = \Drupal::token()->findWithPrefix($tokens, 'parent')) && $parent = token_menu_link_load($link['plid'])) {
+      $replacements += \Drupal::token()->generate('menu-link', $source_tokens, array('menu-link' => $parent), $options);
     }
     // [menu-link:parents:*] chained tokens.
-    if ($parents_tokens = token_find_with_prefix($tokens, 'parents')) {
+    if ($parents_tokens = \Drupal::token()->findWithPrefix($tokens, 'parents')) {
       if ($parents = token_menu_link_load_all_parents($link['mlid'])) {
-        $replacements += token_generate('array', $parents_tokens, array('array' => $parents), $options);
+        $replacements += \Drupal::token()->generate('array', $parents_tokens, array('array' => $parents), $options);
       }
     }
-    if (!empty($link['p1']) && $link['p1'] != $link['mlid'] && ($root_tokens = token_find_with_prefix($tokens, 'root')) && $root = token_menu_link_load($link['p1'])) {
-      $replacements += token_generate('menu-link', $root_tokens, array('menu-link' => $root), $options);
+    if (!empty($link['p1']) && $link['p1'] != $link['mlid'] && ($root_tokens = \Drupal::token()->findWithPrefix($tokens, 'root')) && $root = token_menu_link_load($link['p1'])) {
+      $replacements += \Drupal::token()->generate('menu-link', $root_tokens, array('menu-link' => $root), $options);
     }
-    if ($url_tokens = token_find_with_prefix($tokens, 'url')) {
-      $replacements += token_generate('url', $url_tokens, array('path' => $link['href']), $options);
+    if ($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) {
+      $replacements += \Drupal::token()->generate('url', $url_tokens, array('path' => $link['href']), $options);
     }
   }
 
@@ -687,7 +687,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
     // @deprecated
     // [current-page:arg] dynamic tokens.
-    if ($arg_tokens = token_find_with_prefix($tokens, 'arg')) {
+    if ($arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'arg')) {
       foreach ($arg_tokens as $name => $original) {
         if (is_numeric($name) && ($arg = arg($name)) && isset($arg)) {
           $replacements[$original] = $sanitize ? String::checkPlain($arg) : $arg;
@@ -696,7 +696,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // [current-page:query] dynamic tokens.
-    if ($query_tokens = token_find_with_prefix($tokens, 'query')) {
+    if ($query_tokens = \Drupal::token()->findWithPrefix($tokens, 'query')) {
       foreach ($query_tokens as $name => $original) {
         // @todo Should this use filter_input()?
         if (\Drupal::request()->query->has($name)) {
@@ -707,8 +707,8 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // Chained token relationships.
-    if ($url_tokens = token_find_with_prefix($tokens, 'url')) {
-      $replacements += token_generate('url', $url_tokens, array('path' => $current_path), $options);
+    if ($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) {
+      $replacements += \Drupal::token()->generate('url', $url_tokens, array('path' => $current_path), $options);
     }
   }
 
@@ -752,17 +752,17 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // [url:arg:*] chained tokens.
-    if ($arg_tokens = token_find_with_prefix($tokens, 'args')) {
+    if ($arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'args')) {
       $value = empty($url_options['alias']) ? drupal_get_path_alias($path, $language_code) : $path;
-      $replacements += token_generate('array', $arg_tokens, array('array' => arg(NULL, $value)), $options);
+      $replacements += \Drupal::token()->generate('array', $arg_tokens, array('array' => arg(NULL, $value)), $options);
     }
 
     // [url:unaliased:*] chained tokens.
-    if ($unaliased_tokens = token_find_with_prefix($tokens, 'unaliased')) {
+    if ($unaliased_tokens = \Drupal::token()->findWithPrefix($tokens, 'unaliased')) {
       $unaliased_token_data['path'] = $path;
       $unaliased_token_data['options'] = isset($data['options']) ? $data['options'] : array();
       $unaliased_token_data['options']['alias'] = TRUE;
-      $replacements += token_generate('url', $unaliased_tokens, $unaliased_token_data, $options);
+      $replacements += \Drupal::token()->generate('url', $unaliased_tokens, $unaliased_token_data, $options);
     }
   }
 
@@ -794,13 +794,13 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // [entity:url:*] chained tokens.
-    if (($url_tokens = token_find_with_prefix($tokens, 'url')) && _token_module($type, 'url') == 'token') {
-      $replacements += token_generate('url', $url_tokens, entity_uri($entity_type, $entity), $options);
+    if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) && _token_module($type, 'url') == 'token') {
+      $replacements += \Drupal::token()->generate('url', $url_tokens, entity_uri($entity_type, $entity), $options);
     }
 
     // [entity:original:*] chained tokens.
-    if (($original_tokens = token_find_with_prefix($tokens, 'original')) && _token_module($type, 'original') == 'token' && !empty($entity->original)) {
-      $replacements += token_generate($type, $original_tokens, array($type => $entity->original), $options);
+    if (($original_tokens = \Drupal::token()->findWithPrefix($tokens, 'original')) && _token_module($type, 'original') == 'token' && !empty($entity->original)) {
+      $replacements += \Drupal::token()->generate($type, $original_tokens, array($type => $entity->original), $options);
     }
 
     // Pass through to an generic 'entity' token type generation.
@@ -810,7 +810,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       'token_type' => $type,
     );
     // @todo Investigate passing through more data like everything from entity_extract_ids().
-    $replacements += token_generate('entity', $tokens, $entity_data, $options);
+    $replacements += \Drupal::token()->generate('entity', $tokens, $entity_data, $options);
   }
 
   // Array tokens.
@@ -849,7 +849,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // [array:value:*] dynamic tokens.
-    if ($value_tokens = token_find_with_prefix($tokens, 'value')) {
+    if ($value_tokens = \Drupal::token()->findWithPrefix($tokens, 'value')) {
       foreach ($value_tokens as $key => $original) {
         if ($key[0] !== '#' && isset($array[$key])) {
           $replacements[$original] = token_render_array_value($array[$key], $options);
@@ -858,20 +858,20 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // [array:join:*] dynamic tokens.
-    if ($join_tokens = token_find_with_prefix($tokens, 'join')) {
+    if ($join_tokens = \Drupal::token()->findWithPrefix($tokens, 'join')) {
       foreach ($join_tokens as $join => $original) {
         $replacements[$original] = token_render_array($array, array('join' => $join) + $options);
       }
     }
 
     // [array:keys:*] chained tokens.
-    if ($key_tokens = token_find_with_prefix($tokens, 'keys')) {
-      $replacements += token_generate('array', $key_tokens, array('array' => $keys), $options);
+    if ($key_tokens = \Drupal::token()->findWithPrefix($tokens, 'keys')) {
+      $replacements += \Drupal::token()->generate('array', $key_tokens, array('array' => $keys), $options);
     }
 
     // [array:reversed:*] chained tokens.
-    if ($reversed_tokens = token_find_with_prefix($tokens, 'reversed')) {
-      $replacements += token_generate('array', $reversed_tokens, array('array' => array_reverse($array, TRUE)), array('array sort' => FALSE) + $options);
+    if ($reversed_tokens = \Drupal::token()->findWithPrefix($tokens, 'reversed')) {
+      $replacements += \Drupal::token()->generate('array', $reversed_tokens, array('array' => array_reverse($array, TRUE)), array('array sort' => FALSE) + $options);
     }
 
     // @todo Handle if the array values are not strings and could be chained.
@@ -888,7 +888,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // [custom:hash:*] dynamic token.
-    if ($hash_tokens = token_find_with_prefix($tokens, 'hash')) {
+    if ($hash_tokens = \Drupal::token()->findWithPrefix($tokens, 'hash')) {
       $algos = hash_algos();
       foreach ($hash_tokens as $name => $original) {
         if (in_array($name, $algos)) {
@@ -1025,8 +1025,8 @@ function book_tokens($type, $tokens, array $data = array(), array $options = arr
       }
 
       // Chained token relationships.
-      if ($book_tokens = token_find_with_prefix($tokens, 'book')) {
-        $replacements += token_generate('menu-link', $book_tokens, array('menu-link' => $link), $options);
+      if ($book_tokens = \Drupal::token()->findWithPrefix($tokens, 'book')) {
+        $replacements += \Drupal::token()->generate('menu-link', $book_tokens, array('menu-link' => $link), $options);
       }
     }
   }
@@ -1114,9 +1114,9 @@ function menu_tokens($type, $tokens, array $data = array(), array $options = arr
       }
 
       // Chained token relationships.
-      if ($menu_tokens = token_find_with_prefix($tokens, 'menu-link')) {
+      if ($menu_tokens = \Drupal::token()->findWithPrefix($tokens, 'menu-link')) {
         if ($link = token_node_menu_link_load($node)) {
-          $replacements += token_generate('menu-link', $menu_tokens, array('menu-link' => $link), $options);
+          $replacements += \Drupal::token()->generate('menu-link', $menu_tokens, array('menu-link' => $link), $options);
         }
       }
     }
@@ -1140,8 +1140,8 @@ function menu_tokens($type, $tokens, array $data = array(), array $options = arr
     }
 
     // Chained token relationships.
-    if (($menu_tokens = token_find_with_prefix($tokens, 'menu')) && $menu = menu_load($link['menu_name'])) {
-      $replacements += token_generate('menu', $menu_tokens, array('menu' => $menu), $options);
+    if (($menu_tokens = \Drupal::token()->findWithPrefix($tokens, 'menu')) && $menu = menu_load($link['menu_name'])) {
+      $replacements += \Drupal::token()->generate('menu', $menu_tokens, array('menu' => $menu), $options);
     }
   }
 
@@ -1253,9 +1253,9 @@ function profile_tokens($type, $tokens, array $data = array(), array $options =
 
     // Chained token relationships.
     foreach ($profile_fields as $field) {
-      if ($field->type == 'date' && isset($account->{$field->name}) && $field_tokens = token_find_with_prefix($tokens, $field->token_name)) {
+      if ($field->type == 'date' && isset($account->{$field->name}) && $field_tokens = \Drupal::token()->findWithPrefix($tokens, $field->token_name)) {
         $date = $account->{$field->name};
-        $replacements += token_generate('date', $field_tokens, array('date' => gmmktime(0, 0, 0, $date['month'], $date['day'], $date['year'])), $options);
+        $replacements += \Drupal::token()->generate('date', $field_tokens, array('date' => gmmktime(0, 0, 0, $date['month'], $date['day'], $date['year'])), $options);
       }
     }
   }
-- 
1.9.3 (Apple Git-50)


From 021bfb6495c707ef7050192e784ea7ac26ac2fb9 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Fri, 14 Feb 2014 13:54:29 +1300
Subject: [PATCH 074/230] Issue #1962358 by grom358: Added missing import of
 Field

---
 token.tokens.inc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/token.tokens.inc b/token.tokens.inc
index 8285f10..52a896d 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -6,6 +6,7 @@
  */
 use Drupal\Component\Utility\String;
 use Drupal\Core\Render\Element;
+use Drupal\field\Field;
 
 /**
  * Implements hook_token_info_alter().
-- 
1.9.3 (Apple Git-50)


From 67b08c2db37eaa64f1cea2706bcd9dfc13d6c30a Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 10:50:36 +1000
Subject: [PATCH 075/230] Issue #1962358 by larowlan: Create token view modes
 on install

---
 token.install | 25 +++++++++++++++++++++++++
 token.module  | 19 ++++++++-----------
 2 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/token.install b/token.install
index 5a8e5df..5b0286f 100644
--- a/token.install
+++ b/token.install
@@ -39,6 +39,31 @@ function token_requirements($phase = 'runtime') {
 }
 
 /**
+ * Implements hook_install().
+ */
+function token_install() {
+  // Create a token view mode for each entity type.
+  $info = \Drupal::entityManager()->getDefinitions();
+  foreach ($info as $entity_type => $entity_type_info) {
+    // We're only interested in entity types with a view builder.
+    if (!$entity_type_info->getViewBuilderClass()) {
+      continue;
+    }
+    // Try to find a token view mode for that entity type.
+    $storage_controller = \Drupal::entityManager()->getStorageController('view_mode');
+    // Add a token view mode if it does not already exist.
+    if (!$storage_controller->load("$entity_type.token")) {
+      $storage_controller->create(array(
+        'targetEntityType' => $entity_type,
+        'id' => "$entity_type.token",
+        'status' => TRUE,
+        'label' => t('Token'),
+      ))->save();
+    }
+  }
+}
+
+/**
  * Build a list of Drupal 6 tokens and their Drupal 7 token names.
  */
 function _token_upgrade_token_list() {
diff --git a/token.module b/token.module
index 00f804a..1b1cc14 100644
--- a/token.module
+++ b/token.module
@@ -368,15 +368,7 @@ function token_get_entity_mapping($value_type = 'token', $value = NULL) {
  */
 function token_entity_info_alter(&$info) {
   foreach (array_keys($info) as $entity_type) {
-    // Add a token view mode if it does not already exist.
-    if (!empty($info[$entity_type]['view modes']) && !isset($info[$entity_type]['view modes']['token'])) {
-      $info[$entity_type]['view modes']['token'] = array(
-        'label' => t('Tokens'),
-        'custom settings' => FALSE,
-      );
-    }
-
-    if (!empty($info[$entity_type]['token type'])) {
+    if ($info[$entity_type]->get('token type')) {
       // If the entity's token type is already defined, great!
       continue;
     }
@@ -386,17 +378,22 @@ function token_entity_info_alter(&$info) {
       case 'taxonomy_term':
       case 'taxonomy_vocabulary':
         // Stupid taxonomy token types...
-        $info[$entity_type]['token type'] = str_replace('taxonomy_', '', $entity_type);
+        $info[$entity_type]->set('token type', str_replace('taxonomy_', '', $entity_type));
         break;
+
       default:
         // By default the token type is the same as the entity type.
-        $info[$entity_type]['token type'] = $entity_type;
+        $info[$entity_type]->set('token type', $entity_type);
         break;
     }
   }
 }
 
 /**
+ * Implements hook_entity_view_modes_info().
+ */
+
+/**
  * Implements hook_module_implements_alter().
  *
  * Adds missing token support for core modules.
-- 
1.9.3 (Apple Git-50)


From a9fbaf0523bb717031bd969e851792d4d3acefa3 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Fri, 14 Feb 2014 14:10:05 +1300
Subject: [PATCH 076/230] Issue #1962358 by grom358: Replaced call to undefined
 function system_get_date_types()

---
 token.tokens.inc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index 52a896d..1f6bc19 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -79,11 +79,11 @@ function token_token_info_alter(&$info) {
 
   // Add support for custom date formats.
   // @todo Remove when http://drupal.org/node/1173706 is fixed.
-  $date_format_types = system_get_date_types();
+  $date_format_types = \Drupal::entityManager()->getStorageController('date_format')->loadMultiple();
   foreach ($date_format_types as $date_format_type => $date_format_type_info) {
     if (!isset($info['tokens']['date'][$date_format_type])) {
       $info['tokens']['date'][$date_format_type] = array(
-        'name' => $date_format_type_info['title'],
+        'name' => $date_format_type_info->label(),
         'description' => t("A date in '@type' format. (%date)", array('@type' => $date_format_type, '%date' => format_date(REQUEST_TIME, $date_format_type))),
         'module' => 'token',
       );
@@ -386,7 +386,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     $date = !empty($data['date']) ? $data['date'] : REQUEST_TIME;
 
     // @todo Remove when http://drupal.org/node/1173706 is fixed.
-    $date_format_types = system_get_date_types();
+    $date_format_types = \Drupal::entityManager()->getStorageController('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);
-- 
1.9.3 (Apple Git-50)


From 566d79041e7c2fc556242d780aff50e95d93c448 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Fri, 14 Feb 2014 14:27:11 +1300
Subject: [PATCH 077/230] Issue #1962358 by grom358: Field type and formatter
 types are not plugins

---
 token.module     | 4 ++--
 token.tokens.inc | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/token.module b/token.module
index 1b1cc14..c249e34 100644
--- a/token.module
+++ b/token.module
@@ -275,11 +275,11 @@ function token_field_display_alter(&$display, $context) {
     // If the token view mode fell back to the 'default' view mode, then
     // use the default token formatter.
     if (empty($view_mode_settings[$context['view_mode']]['custom_settings'])) {
-      $field_type_info = field_info_field_types($context['field']['type']);
+      $field_type_info = \Drupal::service('plugin.manager.field.field_type')->getDefinition($context['field']['type']);
       if (!empty($field_type_info['default_token_formatter'])) {
         $display['type'] = $field_type_info['default_token_formatter'];
 
-        $formatter_info = field_info_formatter_types($display['type']);
+        $formatter_info = \Drupal::service('plugin.manager.field.formatter')->getDefinition($display['type']);
         $display['settings'] = isset($formatter_info['settings']) ? $formatter_info['settings'] : array();
         $display['settings']['label'] = 'hidden';
         $display['module'] = $formatter_info['module'];
diff --git a/token.tokens.inc b/token.tokens.inc
index 1f6bc19..9fd6de5 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -1297,7 +1297,7 @@ function _token_field_info($field_name = NULL) {
 
       $fields = field_info_fields();
       $instances = Field::fieldInfo()->getInstances();
-      $type_info = field_info_field_types();
+      $type_info = \Drupal::service('plugin.manager.field.field_type')->getDefinitions();
       $entity_info = \Drupal::entityManager()->getDefinitions();
 
       foreach ($fields as $field) {
-- 
1.9.3 (Apple Git-50)


From 3e70dc71161c019b5b283d714f490eec5437b5dd Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Fri, 14 Feb 2014 14:28:05 +1300
Subject: [PATCH 078/230] Issue #1962358 by grom358: Fixed typo of __FUNCTION__
 constant

---
 token.module | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.module b/token.module
index c249e34..522e452 100644
--- a/token.module
+++ b/token.module
@@ -1200,7 +1200,7 @@ function token_taxonomy_term_load_all_parents($tid) {
  * @see token_menu_link_load()
  */
 function token_node_menu_link_load($node) {
-  $cache = &drupal_static(__FUNCTIon__, array());
+  $cache = &drupal_static(__FUNCTION__, array());
 
   if (!isset($cache[$node->nid])) {
     $mlid = FALSE;
-- 
1.9.3 (Apple Git-50)


From c13a73da96b414b341e6d5e6407151ac66210d70 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Fri, 14 Feb 2014 14:48:53 +1300
Subject: [PATCH 079/230] Issue #1962358 by grom358: Replaced use of
 entity_label and entity_uri

---
 token.module     |  2 +-
 token.tokens.inc | 14 +++++++-------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/token.module b/token.module
index 522e452..278836b 100644
--- a/token.module
+++ b/token.module
@@ -1179,7 +1179,7 @@ function token_taxonomy_term_load_all_parents($tid) {
     array_shift($parents); // Remove this term from the array.
     $parents = array_reverse($parents);
     foreach ($parents as $term) {
-      $cache[$tid][$term->tid] = entity_label('taxonomy_term', $term);
+      $cache[$tid][$term->tid] = $term->label();
     }
   }
 
diff --git a/token.tokens.inc b/token.tokens.inc
index 9fd6de5..01a0fe5 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -406,7 +406,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
     // Chained token relationships.
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, entity_uri('comment', $comment), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, $comment->urlInfo(), $options);
     }
   }
 
@@ -440,7 +440,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       $replacements += \Drupal::token()->generate('content-type', $node_type_tokens, array('node_type' => $node_type), $options);
     }
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, entity_uri('node', $node), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, $node->urlInfo(), $options);
     }
   }
 
@@ -502,7 +502,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
     // Chained token relationships.
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, entity_uri('taxonomy_term', $term), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, $term->urlInfo(), $options);
     }
     // [term:parents:*] chained tokens.
     if ($parents_tokens = \Drupal::token()->findWithPrefix($tokens, 'parents')) {
@@ -584,7 +584,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       $replacements += \Drupal::token()->generate('file', $picture_tokens, array('file' => $account->picture), $options);
     }
     if ($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, entity_uri('user', $account), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, $account->urlInfo(), $options);
     }
     if ($role_tokens = \Drupal::token()->findWithPrefix($tokens, 'roles')) {
       // The roles array may be set from checkbox values so ensure it always
@@ -780,14 +780,14 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'url':
-          if (_token_module($type, 'url') == 'token' && $uri = entity_uri($entity_type, $entity)) {
+          if (_token_module($type, 'url') == 'token' && $uri = $entity->urlInfo()) {
             $replacements[$original] = url($uri['path'], $uri['options']);
           }
           break;
 
         case 'original':
           if (_token_module($type, 'original') == 'token' && !empty($entity->original)) {
-            $label = entity_label($entity_type, $entity->original);
+            $label = $entity->original->label();
             $replacements[$original] = $sanitize ? String::checkPlain($label) : $label;
           }
           break;
@@ -796,7 +796,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
     // [entity:url:*] chained tokens.
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) && _token_module($type, 'url') == 'token') {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, entity_uri($entity_type, $entity), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, $entity->urlInfo(), $options);
     }
 
     // [entity:original:*] chained tokens.
-- 
1.9.3 (Apple Git-50)


From 5642702c5d631edad98496f14122025c143ddb77 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 11:38:31 +1000
Subject: [PATCH 080/230] Issue #1962358 by larowlan: User picture is a field

---
 token.tokens.inc | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index 01a0fe5..67429ec 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -196,13 +196,11 @@ function token_token_info() {
     'restricted' => TRUE,
     // 'type' => 'url',
   );
-  if (variable_get('user_pictures', 0)) {
-    $info['tokens']['user']['picture'] = array(
-      'name' => t('Picture'),
-      'description' => t('The picture of the user.'),
-      'type' => 'file',
-    );
-  }
+  $info['tokens']['user']['picture'] = array(
+    'name' => t('Picture'),
+    'description' => t('The picture of the user.'),
+    'type' => 'file',
+  );
   $info['tokens']['user']['roles'] = array(
     'name' => t('Roles'),
     'description' => t('The user roles associated with the user account.'),
@@ -564,10 +562,9 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'picture':
-          if (variable_get('user_pictures', 0)) {
-            $replacements[$original] = theme('user_picture', array('account' => $account));
-          }
+          $replacements[$original] = theme('user_picture', array('account' => $account));
           break;
+
         case 'roles':
           // The roles array may be set from checkbox values so ensure it always
           // has 'proper' data with the role names.
@@ -578,10 +575,8 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
 
     // Chained token relationships.
-    if (variable_get('user_pictures', 0) && !empty($account->picture) && ($picture_tokens = \Drupal::token()->findWithPrefix($tokens, 'picture'))) {
-      // @todo Remove when core bug http://drupal.org/node/978028 is fixed.
-      $account->picture->description = '';
-      $replacements += \Drupal::token()->generate('file', $picture_tokens, array('file' => $account->picture), $options);
+    if (!empty($account->user_picture) && ($picture_tokens = \Drupal::token()->findWithPrefix($tokens, 'picture'))) {
+      $replacements += \Drupal::token()->generate('file', $picture_tokens, array('file' => $account->user_picture->entity), $options);
     }
     if ($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) {
       $replacements += \Drupal::token()->generate('url', $url_tokens, $account->urlInfo(), $options);
-- 
1.9.3 (Apple Git-50)


From 479231ef91a1d46bd58da09ecce84f68dddb362a Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 11:41:22 +1000
Subject: [PATCH 081/230] Issue #1962358 by larowlan: ip_address() removed

---
 token.tokens.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index 67429ec..c889120 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -594,7 +594,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'ip-address':
-          $ip = ip_address();
+          $ip = \Drupal::request()->getClientIp();
           $replacements[$original] = $sanitize ? String::checkPlain($ip) : $ip;
           break;
       }
-- 
1.9.3 (Apple Git-50)


From 96e590e79ead67e694d3ccb1afd658370b6cbea2 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 15:13:15 +1300
Subject: [PATCH 082/230] Issue #1962358 by larowlan:
 taxonomy_get_parents_all() replaced

---
 token.module     | 2 +-
 token.tokens.inc | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/token.module b/token.module
index 278836b..598ea07 100644
--- a/token.module
+++ b/token.module
@@ -1175,7 +1175,7 @@ function token_taxonomy_term_load_all_parents($tid) {
 
   if (!isset($cache[$tid])) {
     $cache[$tid] = array();
-    $parents = taxonomy_get_parents_all($tid);
+    $parents = taxonomy_term_load_parents_all($tid);
     array_shift($parents); // Remove this term from the array.
     $parents = array_reverse($parents);
     foreach ($parents as $term) {
diff --git a/token.tokens.inc b/token.tokens.inc
index c889120..4d333ec 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -489,7 +489,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           break;
 
         case 'root':
-          $parents = taxonomy_get_parents_all($term->tid);
+          $parents = taxonomy_term_load_parents_all($term->tid);
           $root_term = end($parents);
           if ($root_term->tid != $term->tid) {
             $replacements[$original] = $sanitize ? String::checkPlain($root_term->name) : $root_term->name;
@@ -509,7 +509,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       }
     }
     if ($root_tokens = \Drupal::token()->findWithPrefix($tokens, 'root')) {
-      $parents = taxonomy_get_parents_all($term->tid);
+      $parents = taxonomy_term_load_parents_all($term->tid);
       $root_term = end($parents);
       if ($root_term->tid != $term->tid) {
         $replacements += \Drupal::token()->generate('term', $root_tokens, array('term' => $root_term), $options);
-- 
1.9.3 (Apple Git-50)


From 44ea9028ebd5d723185d8a174968c0c81ea20d7c Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 15:53:31 +1300
Subject: [PATCH 083/230] Issue #1962358 by larowlan: drupal_random_bytes()
 removed

---
 token.tokens.inc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index 4d333ec..a71c77f 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -4,6 +4,7 @@
  * @file
  * Token callbacks for the token module.
  */
+use Drupal\Component\Utility\Crypt;
 use Drupal\Component\Utility\String;
 use Drupal\Core\Render\Element;
 use Drupal\field\Field;
@@ -888,7 +889,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       $algos = hash_algos();
       foreach ($hash_tokens as $name => $original) {
         if (in_array($name, $algos)) {
-          $replacements[$original] = hash($name, drupal_random_bytes(55));
+          $replacements[$original] = hash($name, Crypt::randomStringHashed(55));
         }
       }
     }
-- 
1.9.3 (Apple Git-50)


From 3513190df5dc511874af4981dead41be11e9388c Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 15:54:15 +1300
Subject: [PATCH 084/230] Issue #1962358 by larowlan: Use new entity API
 elements

---
 token.tokens.inc | 53 +++++++++++++++++++++++++++--------------------------
 1 file changed, 27 insertions(+), 26 deletions(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index a71c77f..e80b4fc 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -82,6 +82,7 @@ function token_token_info_alter(&$info) {
   // @todo Remove when http://drupal.org/node/1173706 is fixed.
   $date_format_types = \Drupal::entityManager()->getStorageController('date_format')->loadMultiple();
   foreach ($date_format_types as $date_format_type => $date_format_type_info) {
+    /* @var \Drupal\system\Entity\DateFormat $date_format_type_info */
     if (!isset($info['tokens']['date'][$date_format_type])) {
       $info['tokens']['date'][$date_format_type] = array(
         'name' => $date_format_type_info->label(),
@@ -401,6 +402,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
   // Comment tokens.
   if ($type == 'comment' && !empty($data['comment'])) {
+    /* @var \Drupal\comment\CommentInterface $comment */
     $comment = $data['comment'];
 
     // Chained token relationships.
@@ -411,21 +413,22 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
   // Node tokens.
   if ($type == 'node' && !empty($data['node'])) {
+    /* @var \Drupal\node\NodeInterface $node */
     $node = $data['node'];
 
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'source':
           if (!empty($node->tnid) && $source_node = node_load($node->tnid)) {
-            $title = $source_node->title;
+            $title = $source_node->label();
             $replacements[$original] = $sanitize ? filter_xss($title) : $title;
           }
           break;
         case 'log':
-          $replacements[$original] = $sanitize ? filter_xss($node->log) : $node->log;
+          $replacements[$original] = $sanitize ? filter_xss($node->log->value) : $node->log->value;
           break;
         case 'content-type':
-          $type_name = node_type_get_name($node);
+          $type_name = \Drupal::entityManager()->getStorageController('node_type')->load($node->getType())->label();
           $replacements[$original] = $sanitize ? String::checkPlain($type_name) : $type_name;
           break;
       }
@@ -475,24 +478,25 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
   // Taxonomy term tokens.
   if ($type == 'term' && !empty($data['term'])) {
+    /* @var \Drupal\taxonomy\TermInterface $term */
     $term = $data['term'];
 
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'edit-url':
-          $replacements[$original] = url("taxonomy/term/{$term->tid}/edit", $url_options);
+          $replacements[$original] = url("taxonomy/term/{$term->id()}/edit", $url_options);
           break;
 
         case 'parents':
-          if ($parents = token_taxonomy_term_load_all_parents($term->tid)) {
+          if ($parents = token_taxonomy_term_load_all_parents($term->id())) {
             $replacements[$original] = token_render_array($parents, $options);
           }
           break;
 
         case 'root':
-          $parents = taxonomy_term_load_parents_all($term->tid);
+          $parents = taxonomy_term_load_parents_all($term->id());
           $root_term = end($parents);
-          if ($root_term->tid != $term->tid) {
+          if ($root_term->tid != $term->id()) {
             $replacements[$original] = $sanitize ? String::checkPlain($root_term->name) : $root_term->name;
           }
           break;
@@ -505,14 +509,14 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     }
     // [term:parents:*] chained tokens.
     if ($parents_tokens = \Drupal::token()->findWithPrefix($tokens, 'parents')) {
-      if ($parents = token_taxonomy_term_load_all_parents($term->tid)) {
+      if ($parents = token_taxonomy_term_load_all_parents($term->id())) {
         $replacements += \Drupal::token()->generate('array', $parents_tokens, array('array' => $parents), $options);
       }
     }
     if ($root_tokens = \Drupal::token()->findWithPrefix($tokens, 'root')) {
-      $parents = taxonomy_term_load_parents_all($term->tid);
+      $parents = taxonomy_term_load_parents_all($term->id());
       $root_term = end($parents);
-      if ($root_term->tid != $term->tid) {
+      if ($root_term->tid != $term->id()) {
         $replacements += \Drupal::token()->generate('term', $root_tokens, array('term' => $root_term), $options);
       }
     }
@@ -558,6 +562,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
   // User tokens.
   if ($type == 'user' && !empty($data['user'])) {
+    /* @var \Drupal\user\UserInterface $account */
     $account = $data['user'];
 
     foreach ($tokens as $name => $original) {
@@ -569,7 +574,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
         case 'roles':
           // The roles array may be set from checkbox values so ensure it always
           // has 'proper' data with the role names.
-          $roles = array_intersect_key(user_roles(), $account->roles);
+          $roles = array_intersect_key(user_roles(), $account->getRoles());
           $replacements[$original] = token_render_array($roles, $options);
           break;
       }
@@ -585,7 +590,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     if ($role_tokens = \Drupal::token()->findWithPrefix($tokens, 'roles')) {
       // The roles array may be set from checkbox values so ensure it always
       // has 'proper' data with the role names.
-      $roles = array_intersect_key(user_roles(), $account->roles);
+      $roles = array_intersect_key(user_roles(), $account->getRoles());
       $replacements += \Drupal::token()->generate('array', $role_tokens, array('array' => $roles), $options);
     }
   }
@@ -765,6 +770,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
   // Entity tokens.
   if (!empty($data[$type]) && $entity_type = token_get_entity_mapping('token', $type)) {
+    /* @var \Drupal\Core\Entity\EntityInterface $entity */
     $entity = $data[$type];
 
     // Sometimes taxonomy terms are not properly loaded.
@@ -943,7 +949,7 @@ function token_tokens_alter(array &$replacements, array $context) {
             $account = drupal_anonymous_user();
             $account->name = $comment->name;
           }
-          $name = format_username($account);
+          $name = $account->getUsername();
           $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
           break;
       }
@@ -957,12 +963,9 @@ function token_tokens_alter(array &$replacements, array $context) {
     foreach ($context['tokens'] as $name => $original) {
       switch ($name) {
         case 'author':
-          // http://drupal.org/node/1185842 was fixed in core release 7.9.
-          if (version_compare(VERSION, '7.9', '<')) {
-            $account = user_load($node->uid);
-            $name = format_username($account);
-            $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
-          }
+          $account = user_load($node->uid);
+          $name = $account->getUsername();
+          $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
           break;
       }
     }
@@ -975,12 +978,9 @@ function token_tokens_alter(array &$replacements, array $context) {
     foreach ($context['tokens'] as $name => $original) {
       switch ($name) {
         case 'owner':
-          // http://drupal.org/node/978028 was fixed in core release 7.7.
-          if (version_compare(VERSION, '7.7', '<')) {
-            $account = user_load($file->uid);
-            $name = format_username($account);
-            $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
-          }
+          $account = user_load($file->uid);
+          $name = $account->getUsername();
+          $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
           break;
       }
     }
@@ -1400,13 +1400,14 @@ function field_tokens($type, $tokens, array $data = array(), array $options = ar
     $entity_type = $data['entity_type'];
 
     // The field API does weird stuff to the entity, so let's clone it.
+    /* @var \Drupal\Core\Entity\EntityInterface $entity */
     $entity = clone $data['entity'];
 
     // Reset the prepared view flag in case token generation is called from
     // inside field_attach_view().
     unset($entity->_field_view_prepared);
 
-    list(, , $bundle) = entity_extract_ids($entity_type, $entity);
+    $bundle = $entity->bundle();
     $fields = Field::fieldInfo()->getBundleInstances($entity_type, $bundle);
 
     foreach (array_keys($fields) as $field_name) {
-- 
1.9.3 (Apple Git-50)


From 85192881b40e9d329afe289ef60713dbc396f076 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 15:54:33 +1300
Subject: [PATCH 085/230] Issue #1962358 by larowlan: drupal_get_path_alias()
 removed

---
 token.tokens.inc | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index e80b4fc..6ee71e0 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -726,12 +726,12 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'path':
-          $value = empty($url_options['alias']) ? drupal_get_path_alias($path, $language_code) : $path;
+          $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getPathAlias($path, $language_code) : $path;
           $replacements[$original] = $sanitize ? String::checkPlain($value) : $value;
           break;
         case 'alias':
           // @deprecated
-          $alias = drupal_get_path_alias($path, $language_code);
+          $alias = \Drupal::service('path.alias_manager')->getPathAlias($path, $language_code);
           $replacements[$original] = $sanitize ? String::checkPlain($alias) : $alias;
           break;
         case 'absolute':
@@ -747,7 +747,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           $replacements[$original] = url($path, array('alias' => TRUE) + $url_options);
           break;
         case 'args':
-          $value = empty($url_options['alias']) ? drupal_get_path_alias($path, $language_code) : $path;
+          $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getPathAlias($path, $language_code) : $path;
           $replacements[$original] = token_render_array(arg(NULL, $value), $options);
           break;
       }
@@ -755,7 +755,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
     // [url:arg:*] chained tokens.
     if ($arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'args')) {
-      $value = empty($url_options['alias']) ? drupal_get_path_alias($path, $language_code) : $path;
+      $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getPathAlias($path, $language_code) : $path;
       $replacements += \Drupal::token()->generate('array', $arg_tokens, array('array' => arg(NULL, $value)), $options);
     }
 
-- 
1.9.3 (Apple Git-50)


From 4564711c6c15a5ae3ac1fc3122795652ecc7bf25 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 15:54:47 +1300
Subject: [PATCH 086/230] Issue #1962358 by larowlan: profile removed from core

---
 token.tokens.inc | 103 -------------------------------------------------------
 1 file changed, 103 deletions(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index 6ee71e0..68d5aa8 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -1176,109 +1176,6 @@ function menu_tokens($type, $tokens, array $data = array(), array $options = arr
 }
 
 /**
- * Implements hook_token_info() on behalf of profile.module.
- */
-function profile_token_info() {
-  $info = array();
-
-  foreach (_token_profile_fields() as $field) {
-    $info['tokens']['user'][$field->token_name] = array(
-      'name' => String::checkPlain($field->title),
-      'description' => t('@category @type field.', array('@category' => drupal_ucfirst($field->category), '@type' => $field->type)),
-    );
-
-    switch ($field->type) {
-      case 'date':
-        $info['tokens']['user'][$field->token_name]['type'] = 'date';
-        break;
-    }
-  }
-
-  return $info;
-}
-
-/**
- * Implements hook_tokens() on behalf of profile.module.
- */
-function profile_tokens($type, $tokens, array $data = array(), array $options = array()) {
-  $replacements = array();
-  $sanitize = !empty($options['sanitize']);
-  $language_code = isset($options['language']) ? $options['language']->language : NULL;
-
-  if ($type == 'user' && !empty($data['user'])) {
-    $account = $data['user'];
-
-    // Load profile fields if this is the global user account.
-    // @see http://drupal.org/node/361471
-    // @see http://drupal.org/node/967330
-    if ($account->uid == $GLOBALS['user']->uid && isset($account->timestamp)) {
-      $profile_users = array($account->uid => $account);
-      profile_user_load($profile_users);
-      $account = $profile_users[$account->uid];
-    }
-
-    $profile_fields = _token_profile_fields();
-    foreach ($tokens as $name => $original) {
-      if (isset($profile_fields[$name]) && !empty($account->{$profile_fields[$name]->name})) {
-        $value = $account->{$profile_fields[$name]->name};
-        switch ($profile_fields[$name]->type) {
-          case 'textarea':
-            $replacements[$original] = $sanitize ? check_markup($value, filter_default_format($account), '', TRUE) : $value;
-            break;
-          case 'date':
-            $timestamp = gmmktime(0, 0, 0, $value['month'], $value['day'], $value['year']);
-            $replacements[$original] = format_date($timestamp, 'medium', '', NULL, $language_code);
-            break;
-          case 'url':
-            $replacements[$original] = $sanitize ? check_url($value) : $value;
-            break;
-          case 'checkbox':
-            // Checkbox field if checked should return the text.
-            $replacements[$original] = $sanitize ? String::checkPlain($profile_fields[$name]->title) : $profile_fields[$name]->title;
-            break;
-          case 'list':
-            $value = preg_split("/[,\n\r]/", $value);
-            $value = array_map('trim', $value);
-            $value = implode(', ', $value);
-            // Intentionally fall through to the default condition.
-          default:
-            $replacements[$original] = $sanitize ? String::checkPlain($value) : $value;
-            break;
-        }
-      }
-    }
-
-    // Chained token relationships.
-    foreach ($profile_fields as $field) {
-      if ($field->type == 'date' && isset($account->{$field->name}) && $field_tokens = \Drupal::token()->findWithPrefix($tokens, $field->token_name)) {
-        $date = $account->{$field->name};
-        $replacements += \Drupal::token()->generate('date', $field_tokens, array('date' => gmmktime(0, 0, 0, $date['month'], $date['day'], $date['year'])), $options);
-      }
-    }
-  }
-
-  return $replacements;
-}
-
-/**
- * Fetch an array of profile field objects, keyed by token name.
- */
-function _token_profile_fields() {
-  $fields = &drupal_static(__FUNCTION__);
-
-  if (!isset($fields)) {
-    $fields = array();
-    $results = db_query("SELECT name, title, category, type FROM {profile_field}");
-    foreach ($results as $field) {
-      $field->token_name = token_clean_token_name($field->name);
-      $fields[$field->token_name] = $field;
-    }
-  }
-
-  return $fields;
-}
-
-/**
  * Fetch an array of field data used for tokens.
  */
 function _token_field_info($field_name = NULL) {
-- 
1.9.3 (Apple Git-50)


From d91119233d90d4e4e7c6c5cc431931820e232134 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 15:58:20 +1300
Subject: [PATCH 087/230] Issue #1962358 by larowlan: entity info is an object

---
 token.module | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.module b/token.module
index 598ea07..d567723 100644
--- a/token.module
+++ b/token.module
@@ -342,7 +342,7 @@ function token_get_entity_mapping($value_type = 'token', $value = NULL) {
 
   if (empty($mapping)) {
     foreach (\Drupal::entityManager()->getDefinitions() as $entity_type => $info) {
-      $mapping[$entity_type] = !empty($info['token type']) ? $info['token type'] : $entity_type;
+      $mapping[$entity_type] = $info->get('token type') ? $info->get('token type') : $entity_type;
     }
   }
 
-- 
1.9.3 (Apple Git-50)


From 8287c4007c8b3a51d72306cd57c7d0b6d7b09b02 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Fri, 14 Feb 2014 16:22:35 +1300
Subject: [PATCH 088/230] Issue #1962358 by grom358: Fixed errors preventing
 help page from loading

---
 token.module       | 10 ++++------
 token.services.yml |  4 ++--
 token.tokens.inc   | 46 +++++++++++++++++++++++-----------------------
 3 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/token.module b/token.module
index d567723..6ca3f9d 100644
--- a/token.module
+++ b/token.module
@@ -439,8 +439,6 @@ function token_flush_caches() {
  * @see hook_token_info_alter()
  */
 function token_get_info($token_type = NULL, $token = NULL) {
-  global $language_interface;
-
   // Use the advanced drupal_static() pattern, since this is called very often.
   static $drupal_static_fast;
   if (!isset($drupal_static_fast)) {
@@ -449,7 +447,8 @@ function token_get_info($token_type = NULL, $token = NULL) {
   $token_info = &$drupal_static_fast['token_info'];
 
   if (empty($token_info)) {
-    $cid = "info:{$language_interface->langcode}";
+    $langcode = \Drupal::languageManager()->getCurrentLanguage()->id;
+    $cid = "info:{$langcode}";
 
     if ($cache = cache('cache_token')->get($cid)) {
       $token_info = $cache->data;
@@ -812,8 +811,6 @@ function token_form_user_admin_settings_alter(&$form, &$form_state) {
  *   An optional array with the current parents of the tokens.
  */
 function token_build_tree($token_type, array $options = array()) {
-  global $language_interface;
-
   // Static cache of already built token trees.
   $trees = &drupal_static(__FUNCTION__, array());
 
@@ -833,7 +830,8 @@ function token_build_tree($token_type, array $options = array()) {
     $token_type = $entity_token_type;
   }
 
-  $tree_cid = "tree:{$token_type}:{$language_interface->langcode}:{$options['depth']}";
+  $langcode = \Drupal::languageManager()->getCurrentLanguage()->id;
+  $tree_cid = "tree:{$token_type}:{$langcode}:{$options['depth']}";
 
   // If we do not have this base tree in the static cache, check {cache_token}
   // otherwise generate and store it in the cache.
diff --git a/token.services.yml b/token.services.yml
index 7c5938d..71fe59b 100644
--- a/token.services.yml
+++ b/token.services.yml
@@ -1,8 +1,8 @@
 services:
-  cache.token:
+  cache.cache_token:
     class: Drupal\Core\Cache\CacheBackendInterface
     tags:
       - { name: cache.bin }
     factory_method: get
     factory_service: cache_factory
-    arguments: [token]
+    arguments: [cache_token]
diff --git a/token.tokens.inc b/token.tokens.inc
index 68d5aa8..6c776e0 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -47,7 +47,8 @@ function token_token_info_alter(&$info) {
   // Add [token:url] tokens for any URI-able entities.
   $entities = \Drupal::entityManager()->getDefinitions();
   foreach ($entities as $entity => $entity_info) {
-    if (!isset($entity_info['token type'])) {
+    /* @var \Drupal\Core\Entity\EntityType $entity_info */
+    if (!$entity_info->hasKey('token type')) {
       continue;
     }
 
@@ -1194,31 +1195,30 @@ function _token_field_info($field_name = NULL) {
       $entity_info = \Drupal::entityManager()->getDefinitions();
 
       foreach ($fields as $field) {
-        $key = $field['field_name'];
-        if (!empty($field['bundles'])) {
-          foreach (array_keys($field['bundles']) as $entity) {
-            // Make sure a token type exists for this entity.
-            $token_type = token_get_entity_mapping('entity', $entity);
-            if (empty($token_type)) {
+        /* @var \Drupal\field\FieldInterface $field */
+        $key = $field->getName();
+        foreach (array_keys($field->getBundles()) as $entity) {
+          // Make sure a token type exists for this entity.
+          $token_type = token_get_entity_mapping('entity', $entity);
+          if (empty($token_type)) {
+            continue;
+          }
+
+          $info[$key]['token types'][] = $token_type;
+          $info[$key] += array('labels' => array(), 'bundles' => array());
+
+          // Find which label is most commonly used.
+          foreach ($field['bundles'][$entity] as $bundle) {
+            // Field information will included fields attached to disabled
+            // bundles, so check that the bundle exists before provided a
+            // token for it.
+            // @see http://drupal.org/node/1252566
+            if (!isset($entity_info[$entity]['bundles'][$bundle])) {
               continue;
             }
 
-            $info[$key]['token types'][] = $token_type;
-            $info[$key] += array('labels' => array(), 'bundles' => array());
-
-            // Find which label is most commonly used.
-            foreach ($field['bundles'][$entity] as $bundle) {
-              // Field information will included fields attached to disabled
-              // bundles, so check that the bundle exists before provided a
-              // token for it.
-              // @see http://drupal.org/node/1252566
-              if (!isset($entity_info[$entity]['bundles'][$bundle])) {
-                continue;
-              }
-
-              $info[$key]['labels'][] = $instances[$entity][$bundle][$key]['label'];
-              $info[$key]['bundles'][$token_type][$bundle] = $entity_info[$entity]['bundles'][$bundle]['label'];
-            }
+            $info[$key]['labels'][] = $instances[$entity][$bundle][$key]['label'];
+            $info[$key]['bundles'][$token_type][$bundle] = $entity_info[$entity]['bundles'][$bundle]['label'];
           }
         }
 
-- 
1.9.3 (Apple Git-50)


From 6420cbe84cc5130585b95acc3d4cdff4f1097251 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 14 Feb 2014 13:36:41 +1000
Subject: [PATCH 089/230] Issue #1962358 by larowlan: Clean up TestBase

---
 lib/Drupal/token/Tests/TokenTestBase.php | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenTestBase.php b/lib/Drupal/token/Tests/TokenTestBase.php
index c2e2b45..6c884eb 100644
--- a/lib/Drupal/token/Tests/TokenTestBase.php
+++ b/lib/Drupal/token/Tests/TokenTestBase.php
@@ -6,7 +6,9 @@
  */
 namespace Drupal\token\Tests;
 
+use Drupal\Core\Entity\EntityInterface;
 use Drupal\simpletest\WebTestBase;
+use Drupal\Core\Language\Language;
 
 /**
  * Helper test class with some added functions for testing.
@@ -14,14 +16,7 @@ use Drupal\simpletest\WebTestBase;
 class TokenTestBase extends WebTestBase {
   protected $profile = 'testing';
 
-  public function setUp($modules = array()) {
-    $modules[] = 'path';
-    $modules[] = 'token';
-    $modules[] = 'token_test';
-    parent::setUp($modules);
-
-    variable_set('clean_url', 1);
-  }
+  protected static $modules = array('path', 'token', 'token_test');
 
   function assertToken($type, array $data, $token, $expected, array $options = array()) {
     return $this->assertTokens($type, $data, array($token => $expected), $options);
@@ -29,7 +24,7 @@ class TokenTestBase extends WebTestBase {
 
   function assertTokens($type, array $data, array $tokens, array $options = array()) {
     $input = $this->mapTokenNames($type, array_keys($tokens));
-    $replacements = token_generate($type, $input, $data, $options);
+    $replacements = \Drupal::token()->generate($input, $data, $options);
     foreach ($tokens as $name => $expected) {
       $token = $input[$name];
       if (!isset($expected)) {
@@ -59,7 +54,7 @@ class TokenTestBase extends WebTestBase {
 
   function assertNoTokens($type, array $data, array $tokens, array $options = array()) {
     $input = $this->mapTokenNames($type, $tokens);
-    $replacements = token_generate($type, $input, $data, $options);
+    $replacements = \Drupal::token()->generate($type, $input, $data, $options);
     foreach ($tokens as $name) {
       $token = $input[$name];
       $this->assertTrue(!isset($replacements[$token]), t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token)));
@@ -67,18 +62,18 @@ class TokenTestBase extends WebTestBase {
     return $values;
   }
 
-  function saveAlias($source, $alias, $language = LANGUAGE_NOT_SPECIFIED) {
+  function saveAlias($source, $alias, $language = Language::LANGCODE_NOT_SPECIFIED) {
     $alias = array(
       'source' => $source,
       'alias' => $alias,
       'language' => $language,
     );
-    path_save($alias);
+    \Drupal::service('path.crud')->save($alias['source'], $alias['alias']);
     return $alias;
   }
 
-  function saveEntityAlias($entity_type, $entity, $alias, $language = LANGUAGE_NOT_SPECIFIED) {
-    $uri = entity_uri($entity_type, $entity);
+  function saveEntityAlias($entity_type, EntityInterface $entity, $alias, $language = Language::LANGCODE_NOT_SPECIFIED) {
+    $uri = $entity->urlInfo();
     return $this->saveAlias($uri['path'], $alias, $language);
   }
 
@@ -95,12 +90,12 @@ class TokenTestBase extends WebTestBase {
       'data' => $data,
       'options' => $options,
     );
-    variable_set('token_page_tokens', $token_page_tokens);
+    \Drupal::state()->set('token_page_tokens', $token_page_tokens);
 
     $options += array('url_options' => array());
     $this->drupalGet($url, $options['url_options']);
     $this->refreshVariables();
-    $result = variable_get('token_page_tokens', array());
+    $result = \Drupal::state()->get('token_page_tokens', array());
 
     if (!isset($result['values']) || !is_array($result['values'])) {
       return $this->fail('Failed to generate tokens.');
@@ -118,4 +113,5 @@ class TokenTestBase extends WebTestBase {
       }
     }
   }
+
 }
-- 
1.9.3 (Apple Git-50)


From 914361032c9062fde306103b616f56413170f4df Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Fri, 14 Feb 2014 16:37:48 +1300
Subject: [PATCH 090/230] Issue #1962358 by grom358: Replaced calls to
 variable_get and token_replace

---
 tests/token_test.module | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/token_test.module b/tests/token_test.module
index 3174cb6..8af0b8d 100644
--- a/tests/token_test.module
+++ b/tests/token_test.module
@@ -9,12 +9,12 @@
  * Implements hook_exit().
  */
 function token_test_exit() {
-  if ($debug = variable_get('token_page_tokens', array())) {
+  if ($debug = \Drupal::state()->get('token_page_tokens', array())) {
     $debug += array('tokens' => array(), 'data' => array(), 'options' => array());
     foreach (array_keys($debug['tokens']) as $token) {
-      $debug['values'][$token] = token_replace($token, $debug['data'], $debug['options']);
+      $debug['values'][$token] = \Drupal::token()->replace($token, $debug['data'], $debug['options']);
     }
-    variable_set('token_page_tokens', $debug);
+    \Drupal::state()->set('token_page_tokens', $debug);
   }
 }
 
@@ -27,7 +27,7 @@ function token_test_date_format_types() {
   $info['token_test'] = t('Token test date format');
 
   // Explicitly set the variable here as well.
-  variable_set('date_format_token_test', 'Y');
+  \Drupal::state()->set('date_format_token_test', 'Y');
 
   return $info;
 }
-- 
1.9.3 (Apple Git-50)


From 15a3e5cea8ac7068628dfc56cbc4b8df3eaf3e6a Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Sat, 15 Feb 2014 06:21:30 +1000
Subject: [PATCH 091/230] Issue #1962358 by larowlan: Fixes use of generate()
 in test base

---
 lib/Drupal/token/Tests/TokenTestBase.php | 2 +-
 token.tokens.inc                         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenTestBase.php b/lib/Drupal/token/Tests/TokenTestBase.php
index 6c884eb..dbcbb92 100644
--- a/lib/Drupal/token/Tests/TokenTestBase.php
+++ b/lib/Drupal/token/Tests/TokenTestBase.php
@@ -24,7 +24,7 @@ class TokenTestBase extends WebTestBase {
 
   function assertTokens($type, array $data, array $tokens, array $options = array()) {
     $input = $this->mapTokenNames($type, array_keys($tokens));
-    $replacements = \Drupal::token()->generate($input, $data, $options);
+    $replacements = \Drupal::token()->generate($type, $input, $data, $options);
     foreach ($tokens as $name => $expected) {
       $token = $input[$name];
       if (!isset($expected)) {
diff --git a/token.tokens.inc b/token.tokens.inc
index 6c776e0..2f47d24 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -770,7 +770,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
   }
 
   // Entity tokens.
-  if (!empty($data[$type]) && $entity_type = token_get_entity_mapping('token', $type)) {
+  if (!empty($data[$type]) && ($entity_type = token_get_entity_mapping('token', $type))) {
     /* @var \Drupal\Core\Entity\EntityInterface $entity */
     $entity = $data[$type];
 
-- 
1.9.3 (Apple Git-50)


From 1afbbfc1923c2bb95add94ff0df3e104151f32b7 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Sat, 15 Feb 2014 13:06:19 +1300
Subject: [PATCH 092/230] Issue #1962358 by larowlan: setup block module for
 block test

---
 lib/Drupal/token/Tests/TokenBlockTestCase.php | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenBlockTestCase.php b/lib/Drupal/token/Tests/TokenBlockTestCase.php
index e34c2f4..8a571dc 100644
--- a/lib/Drupal/token/Tests/TokenBlockTestCase.php
+++ b/lib/Drupal/token/Tests/TokenBlockTestCase.php
@@ -10,6 +10,8 @@ namespace Drupal\token\Tests;
  * Tests block tokens.
  */
 class TokenBlockTestCase extends TokenTestBase {
+  protected static $modules = array('path', 'token', 'token_test', 'block');
+
   public static function getInfo() {
     return array(
       'name' => 'Block token tests',
@@ -19,9 +21,6 @@ class TokenBlockTestCase extends TokenTestBase {
   }
 
   public function setUp($modules = array()) {
-    $modules[] = 'block';
-    parent::setUp($modules);
-
     $this->admin_user = $this->drupalCreateUser(array('access content', 'administer blocks'));
     $this->drupalLogin($this->admin_user);
   }
-- 
1.9.3 (Apple Git-50)


From 935edfd5ca804e667064608d684941fca965882e Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Sat, 15 Feb 2014 13:57:37 +1300
Subject: [PATCH 093/230] Issue #1962358 by grom358: Made tests able to run

---
 lib/Drupal/token/Tests/TokenBlockTestCase.php      |  3 +-
 lib/Drupal/token/Tests/TokenCommentTestCase.php    | 63 +++++++++++-----------
 .../token/Tests/TokenCurrentPageTestCase.php       | 14 ++---
 lib/Drupal/token/Tests/TokenEntityTestCase.php     | 20 +++----
 lib/Drupal/token/Tests/TokenFileTestCase.php       | 13 ++---
 lib/Drupal/token/Tests/TokenMenuTestCase.php       | 23 ++++----
 lib/Drupal/token/Tests/TokenNodeTestCase.php       | 24 ++++-----
 lib/Drupal/token/Tests/TokenTaxonomyTestCase.php   | 50 +++++++++--------
 lib/Drupal/token/Tests/TokenUserTestCase.php       | 26 +++++----
 token.tokens.inc                                   |  4 ++
 10 files changed, 118 insertions(+), 122 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenBlockTestCase.php b/lib/Drupal/token/Tests/TokenBlockTestCase.php
index 9129512..542fd04 100644
--- a/lib/Drupal/token/Tests/TokenBlockTestCase.php
+++ b/lib/Drupal/token/Tests/TokenBlockTestCase.php
@@ -10,7 +10,7 @@ namespace Drupal\token\Tests;
  * Tests block tokens.
  */
 class TokenBlockTestCase extends TokenTestBase {
-  protected static $modules = array('path', 'token', 'token_test', 'block');
+  protected static $modules = array('path', 'token', 'token_test', 'block', 'node');
 
   public static function getInfo() {
     return array(
@@ -21,6 +21,7 @@ class TokenBlockTestCase extends TokenTestBase {
   }
 
   public function setUp($modules = array()) {
+    parent::setUp();
     $this->admin_user = $this->drupalCreateUser(array('access content', 'administer blocks'));
     $this->drupalLogin($this->admin_user);
   }
diff --git a/lib/Drupal/token/Tests/TokenCommentTestCase.php b/lib/Drupal/token/Tests/TokenCommentTestCase.php
index e4dbec0..a97ac73 100644
--- a/lib/Drupal/token/Tests/TokenCommentTestCase.php
+++ b/lib/Drupal/token/Tests/TokenCommentTestCase.php
@@ -24,47 +24,46 @@ class TokenCommentTestCase extends TokenTestBase {
   }
 
   function testCommentTokens() {
-    $node = $this->drupalCreateNode(array('comment' => COMMENT_NODE_OPEN));
+    \Drupal::service('comment.manager')->addDefaultField('node', 'page');
+    $node = $this->drupalCreateNode();
 
-    $parent_comment = new stdClass;
-    $parent_comment->nid = $node->nid;
-    $parent_comment->pid = 0;
-    $parent_comment->cid = NULL;
-    $parent_comment->uid = 0;
-    $parent_comment->name = 'anonymous user';
-    $parent_comment->mail = 'anonymous@example.com';
-    $parent_comment->subject = $this->randomName();
-    $parent_comment->timestamp = mt_rand($node->created, REQUEST_TIME);
-    $parent_comment->language = LANGUAGE_NOT_SPECIFIED;
-    $parent_comment->body[LANGUAGE_NOT_SPECIFIED][0] = $this->randomName();
-    comment_save($parent_comment);
+    $parent_comment = entity_create('comment', array(
+      'entity_id' => $node->id(),
+      'entity_type' => 'node',
+      'field_name' => 'comment',
+      'name' => 'anonymous user',
+      'mail' => 'anonymous@example.com',
+      'subject' => $this->randomName(),
+      'body' => $this->randomName(),
+    ))->save();
 
     $tokens = array(
-      'url' => url('comment/' . $parent_comment->cid, array('fragment' => 'comment-' . $parent_comment->cid, 'absolute' => TRUE)),
-      'url:absolute' => url('comment/' . $parent_comment->cid, array('fragment' => 'comment-' . $parent_comment->cid, 'absolute' => TRUE)),
-      'url:relative' => url('comment/' . $parent_comment->cid, array('fragment' => 'comment-' . $parent_comment->cid, 'absolute' => FALSE)),
-      'url:path' => 'comment/' . $parent_comment->cid,
+      'url' => url('comment/' . $parent_comment->id(), array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
+      'url:absolute' => url('comment/' . $parent_comment->id(), array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
+      'url:relative' => url('comment/' . $parent_comment->id(), array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => FALSE)),
+      'url:path' => 'comment/' . $parent_comment->id(),
       'parent:url:absolute' => NULL,
     );
     $this->assertTokens('comment', array('comment' => $parent_comment), $tokens);
 
-    $comment = new stdClass();
-    $comment->nid = $node->nid;
-    $comment->pid = $parent_comment->cid;
-    $comment->cid = NULL;
-    $comment->uid = 1;
-    $comment->subject = $this->randomName();
-    $comment->timestamp = mt_rand($parent_comment->created, REQUEST_TIME);
-    $comment->language = LANGUAGE_NOT_SPECIFIED;
-    $comment->body[LANGUAGE_NOT_SPECIFIED][0] = $this->randomName();
-    comment_save($comment);
+    $comment = entity_create('comment', array(
+      'entity_id' => $node->id(),
+      'pid' => $parent_comment->id(),
+      'entity_type' => 'node',
+      'field_name' => 'comment',
+      'uid' => 1,
+      'name' => 'anonymous user',
+      'mail' => 'anonymous@example.com',
+      'subject' => $this->randomName(),
+      'body' => $this->randomName(),
+    ))->save();
 
     $tokens = array(
-      'url' => url('comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid, 'absolute' => TRUE)),
-      'url:absolute' => url('comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid, 'absolute' => TRUE)),
-      'url:relative' => url('comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid, 'absolute' => FALSE)),
-      'url:path' => 'comment/' . $comment->cid,
-      'parent:url:absolute' => url('comment/' . $parent_comment->cid, array('fragment' => 'comment-' . $parent_comment->cid, 'absolute' => TRUE)),
+      'url' => url('comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id(), 'absolute' => TRUE)),
+      'url:absolute' => url('comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id(), 'absolute' => TRUE)),
+      'url:relative' => url('comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id(), 'absolute' => FALSE)),
+      'url:path' => 'comment/' . $comment->id(),
+      'parent:url:absolute' => url('comment/' . $parent_comment->id(), array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
     );
     $this->assertTokens('comment', array('comment' => $comment), $tokens);
   }
diff --git a/lib/Drupal/token/Tests/TokenCurrentPageTestCase.php b/lib/Drupal/token/Tests/TokenCurrentPageTestCase.php
index 578ddc7..c872b37 100644
--- a/lib/Drupal/token/Tests/TokenCurrentPageTestCase.php
+++ b/lib/Drupal/token/Tests/TokenCurrentPageTestCase.php
@@ -20,7 +20,7 @@ class TokenCurrentPageTestCase extends TokenTestBase {
 
   function testCurrentPageTokens() {
     $tokens = array(
-      '[current-page:title]' => t('Welcome to @site-name', array('@site-name' => variable_get('site_name', 'Drupal'))),
+      '[current-page:title]' => t('Welcome to @site-name', array('@site-name' => \Drupal::config('system.site')->get('name'))),
       '[current-page:url]' => url('node', array('absolute' => TRUE)),
       '[current-page:url:absolute]' => url('node', array('absolute' => TRUE)),
       '[current-page:url:relative]' => url('node', array('absolute' => FALSE)),
@@ -41,15 +41,15 @@ class TokenCurrentPageTestCase extends TokenTestBase {
     $node = $this->drupalCreateNode(array('title' => 'Node title', 'path' => array('alias' => 'node-alias')));
     $tokens = array(
       '[current-page:title]' => 'Node title',
-      '[current-page:url]' => url("node/{$node->nid}", array('absolute' => TRUE)),
-      '[current-page:url:absolute]' => url("node/{$node->nid}", array('absolute' => TRUE)),
-      '[current-page:url:relative]' => url("node/{$node->nid}", array('absolute' => FALSE)),
+      '[current-page:url]' => url("node/{$node->id()}", array('absolute' => TRUE)),
+      '[current-page:url:absolute]' => url("node/{$node->id()}", array('absolute' => TRUE)),
+      '[current-page:url:relative]' => url("node/{$node->id()}", array('absolute' => FALSE)),
       '[current-page:url:alias]' => 'node-alias',
       '[current-page:url:args:value:0]' => 'node-alias',
       '[current-page:url:args:value:1]' => NULL,
-      '[current-page:url:unaliased]' => url("node/{$node->nid}", array('absolute' => TRUE, 'alias' => TRUE)),
+      '[current-page:url:unaliased]' => url("node/{$node->id()}", array('absolute' => TRUE, 'alias' => TRUE)),
       '[current-page:url:unaliased:args:value:0]' => 'node',
-      '[current-page:url:unaliased:args:value:1]' => $node->nid,
+      '[current-page:url:unaliased:args:value:1]' => $node->id(),
       '[current-page:url:unaliased:args:value:2]' => NULL,
       '[current-page:page-number]' => 1,
       '[current-page:query:foo]' => 'bar',
@@ -60,6 +60,6 @@ class TokenCurrentPageTestCase extends TokenTestBase {
       '[current-page:arg:1]' => 1,
       '[current-page:arg:2]' => NULL,
     );
-    $this->assertPageTokens("node/{$node->nid}", $tokens, array(), array('url_options' => array('query' => array('foo' => 'bar'))));
+    $this->assertPageTokens("node/{$node->id()}", $tokens, array(), array('url_options' => array('query' => array('foo' => 'bar'))));
   }
 }
diff --git a/lib/Drupal/token/Tests/TokenEntityTestCase.php b/lib/Drupal/token/Tests/TokenEntityTestCase.php
index 11a3353..295ab8a 100644
--- a/lib/Drupal/token/Tests/TokenEntityTestCase.php
+++ b/lib/Drupal/token/Tests/TokenEntityTestCase.php
@@ -5,6 +5,7 @@
  * Contains \Drupal\token\Tests\TokenEntityTestCase.
  */
 namespace Drupal\token\Tests;
+use Drupal\taxonomy\VocabularyInterface;
 
 /**
  * Tests entity tokens.
@@ -45,17 +46,16 @@ class TokenEntityTestCase extends TokenTestBase {
     // that we still get the tokens replaced.
     $vocabulary = taxonomy_vocabulary_machine_name_load('tags');
     $term = $this->addTerm($vocabulary);
-    $this->assertIdentical(token_replace('[vocabulary:name]', array('taxonomy_vocabulary' => $vocabulary)), $vocabulary->name);
-    $this->assertIdentical(token_replace('[term:name][term:vocabulary:name]', array('taxonomy_term' => $term)), $term->name . $vocabulary->name);
+    $this->assertIdentical(\Drupal::token()->replace('[vocabulary:name]', array('taxonomy_vocabulary' => $vocabulary)), $vocabulary->name);
+    $this->assertIdentical(\Drupal::token()->replace('[term:name][term:vocabulary:name]', array('taxonomy_term' => $term)), $term->name . $vocabulary->name);
   }
 
-  function addTerm(TaxonomyVocabulary $vocabulary, array $term = array()) {
+  function addTerm(VocabularyInterface $vocabulary, array $term = array()) {
     $term += array(
       'name' => drupal_strtolower($this->randomName(5)),
-      'vid' => $vocabulary->vid,
+      'vid' => $vocabulary->id(),
     );
-    $term = entity_create('taxonomy_term', $term);
-    taxonomy_term_save($term);
+    $term = entity_create('taxonomy_term', $term)->save();
     return $term;
   }
 
@@ -66,7 +66,7 @@ class TokenEntityTestCase extends TokenTestBase {
     $node = $this->drupalCreateNode(array('title' => 'Original title'));
 
     $tokens = array(
-      'nid' => $node->nid,
+      'nid' => $node->id(),
       'title' => 'Original title',
       'original' => NULL,
       'original:nid' => NULL,
@@ -75,14 +75,14 @@ class TokenEntityTestCase extends TokenTestBase {
 
     // Emulate the original entity property that would be available from
     // node_save() and change the title for the node.
-    $node->original = entity_load_unchanged('node', $node->nid);
+    $node->original = entity_load_unchanged('node', $node->id());
     $node->title = 'New title';
 
     $tokens = array(
-      'nid' => $node->nid,
+      'nid' => $node->id(),
       'title' => 'New title',
       'original' => 'Original title',
-      'original:nid' => $node->nid,
+      'original:nid' => $node->id(),
     );
     $this->assertTokens('node', array('node' => $node), $tokens);
   }
diff --git a/lib/Drupal/token/Tests/TokenFileTestCase.php b/lib/Drupal/token/Tests/TokenFileTestCase.php
index 65656dc..ac14f79 100644
--- a/lib/Drupal/token/Tests/TokenFileTestCase.php
+++ b/lib/Drupal/token/Tests/TokenFileTestCase.php
@@ -20,12 +20,13 @@ class TokenFileTestCase extends TokenTestBase {
 
   function testFileTokens() {
     // Create a test file object.
-    $file = new stdClass();
-    $file->fid = 1;
-    $file->filename = 'test.png';
-    $file->filesize = 100;
-    $file->uri = 'public://images/test.png';
-    $file->filemime = 'image/png';
+    $file = entity_create('file', array(
+      'fid' => 1,
+      'filename' => 'test.png',
+      'filesize' => 100,
+      'uri' => 'public://images/test.png',
+      'filemime' => 'image/png',
+    ));
 
     $tokens = array(
       'basename' => 'test.png',
diff --git a/lib/Drupal/token/Tests/TokenMenuTestCase.php b/lib/Drupal/token/Tests/TokenMenuTestCase.php
index 05a75ee..12fe957 100644
--- a/lib/Drupal/token/Tests/TokenMenuTestCase.php
+++ b/lib/Drupal/token/Tests/TokenMenuTestCase.php
@@ -10,6 +10,8 @@ namespace Drupal\token\Tests;
  * Tests menu tokens.
  */
 class TokenMenuTestCase extends TokenTestBase {
+  protected static $modules = array('path', 'token', 'token_test', 'menu');
+
   public static function getInfo() {
     return array(
       'name' => 'Menu link and menu token tests',
@@ -18,28 +20,21 @@ class TokenMenuTestCase extends TokenTestBase {
     );
   }
 
-  public function setUp($modules = array()) {
-    $modules[] = 'menu';
-    parent::setUp($modules);
-  }
-
   function testMenuTokens() {
     // Add a root link.
-    $root_link = array(
+    $root_link = entity_create('menu_link', array(
       'link_path' => 'root',
       'link_title' => 'Root link',
       'menu_name' => 'main-menu',
-    );
-    menu_link_save($root_link);
+    ))->save();
 
     // Add another link with the root link as the parent
-    $parent_link = array(
+    $parent_link = entity_create('menu_link', array(
       'link_path' => 'root/parent',
       'link_title' => 'Parent link',
       'menu_name' => 'main-menu',
       'plid' => $root_link['mlid'],
-    );
-    menu_link_save($parent_link);
+    ))->save();
 
     // Test menu link tokens.
     $tokens = array(
@@ -88,8 +83,8 @@ class TokenMenuTestCase extends TokenTestBase {
       'menu-link:mlid' => $node->menu['mlid'],
       'menu-link:title' => 'Node link',
       'menu-link:menu' => 'Main menu',
-      'menu-link:url' => url('node/' . $node->nid, array('absolute' => TRUE)),
-      'menu-link:url:path' => 'node/' . $node->nid,
+      'menu-link:url' => url('node/' . $node->id(), array('absolute' => TRUE)),
+      'menu-link:url:path' => 'node/' . $node->id(),
       'menu-link:edit-url' => url("admin/structure/menu/item/{$node->menu['mlid']}/edit", array('absolute' => TRUE)),
       'menu-link:parent' => 'Parent link',
       'menu-link:parent:mlid' => $node->menu['plid'],
@@ -103,7 +98,7 @@ class TokenMenuTestCase extends TokenTestBase {
     $this->assertTokens('node', array('node' => $node), $tokens);
 
     // Reload the node which will not have $node->menu defined and re-test.
-    $loaded_node = node_load($node->nid);
+    $loaded_node = node_load($node->id());
     $this->assertTokens('node', array('node' => $loaded_node), $tokens);
 
     // Regression test for http://drupal.org/node/1317926 to ensure the
diff --git a/lib/Drupal/token/Tests/TokenNodeTestCase.php b/lib/Drupal/token/Tests/TokenNodeTestCase.php
index a4b03bb..70444c0 100644
--- a/lib/Drupal/token/Tests/TokenNodeTestCase.php
+++ b/lib/Drupal/token/Tests/TokenNodeTestCase.php
@@ -27,9 +27,9 @@ class TokenNodeTestCase extends TokenTestBase {
       'source:nid' => NULL,
       'log' => $source_node->log,
       'url:path' => 'content/source-node',
-      'url:absolute' => url("node/{$source_node->nid}", array('absolute' => TRUE)),
-      'url:relative' => url("node/{$source_node->nid}", array('absolute' => FALSE)),
-      'url:unaliased:path' => "node/{$source_node->nid}",
+      'url:absolute' => url("node/{$source_node->id()}", array('absolute' => TRUE)),
+      'url:relative' => url("node/{$source_node->id()}", array('absolute' => FALSE)),
+      'url:unaliased:path' => "node/{$source_node->id()}",
       'content-type' => 'Basic page',
       'content-type:name' => 'Basic page',
       'content-type:machine-name' => 'page',
@@ -44,15 +44,15 @@ class TokenNodeTestCase extends TokenTestBase {
     );
     $this->assertTokens('node', array('node' => $source_node), $tokens);
 
-    $translated_node = $this->drupalCreateNode(array('tnid' => $source_node->nid, 'type' => 'article'));
+    $translated_node = $this->drupalCreateNode(array('tnid' => $source_node->id(), 'type' => 'article'));
     $tokens = array(
-      'source' => $source_node->title,
-      'source:nid' => $source_node->nid,
+      'source' => $source_node->label(),
+      'source:nid' => $source_node->id(),
       'log' => '',
-      'url:path' => "node/{$translated_node->nid}",
-      'url:absolute' => url("node/{$translated_node->nid}", array('absolute' => TRUE)),
-      'url:relative' => url("node/{$translated_node->nid}", array('absolute' => FALSE)),
-      'url:unaliased:path' => "node/{$translated_node->nid}",
+      'url:path' => "node/{$translated_node->id()}",
+      'url:absolute' => url("node/{$translated_node->id()}", array('absolute' => TRUE)),
+      'url:relative' => url("node/{$translated_node->id()}", array('absolute' => FALSE)),
+      'url:unaliased:path' => "node/{$translated_node->id()}",
       'content-type' => 'Article',
       'content-type:name' => 'Article',
       'content-type:machine-name' => 'article',
@@ -62,8 +62,8 @@ class TokenNodeTestCase extends TokenTestBase {
       // Deprecated tokens.
       'type' => 'article',
       'type-name' => 'Article',
-      'tnid' => $source_node->nid,
-      'url:alias' => "node/{$translated_node->nid}",
+      'tnid' => $source_node->id(),
+      'url:alias' => "node/{$translated_node->id()}",
     );
     $this->assertTokens('node', array('node' => $translated_node), $tokens);
   }
diff --git a/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php b/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php
index 9fec241..37a0489 100644
--- a/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php
+++ b/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php
@@ -5,6 +5,7 @@
  * Contains \Drupal\token\Tests\TokenTaxonomyTestCase.
  */
 namespace Drupal\token\Tests;
+use Drupal\Component\Utility\String;
 
 /**
  * Tests taxonomy tokens.
@@ -28,8 +29,7 @@ class TokenTaxonomyTestCase extends TokenTestBase {
     $vocabulary = entity_create('taxonomy_vocabulary', array(
       'name' => 'Tags',
       'machine_name' => 'tags',
-    ));
-    taxonomy_vocabulary_save($vocabulary);
+    ))->save();
     $this->vocab = $vocabulary;
   }
 
@@ -39,12 +39,12 @@ class TokenTaxonomyTestCase extends TokenTestBase {
   function testTaxonomyTokens() {
     $root_term = $this->addTerm($this->vocab, array('name' => 'Root term', 'path' => array('alias' => 'root-term')));
     $tokens = array(
-      'url' => url("taxonomy/term/{$root_term->tid}", array('absolute' => TRUE)),
-      'url:absolute' => url("taxonomy/term/{$root_term->tid}", array('absolute' => TRUE)),
-      'url:relative' => url("taxonomy/term/{$root_term->tid}", array('absolute' => FALSE)),
+      'url' => url("taxonomy/term/{$root_term->id()}", array('absolute' => TRUE)),
+      'url:absolute' => url("taxonomy/term/{$root_term->id()}", array('absolute' => TRUE)),
+      'url:relative' => url("taxonomy/term/{$root_term->id()}", array('absolute' => FALSE)),
       'url:path' => 'root-term',
-      'url:unaliased:path' => "taxonomy/term/{$root_term->tid}",
-      'edit-url' => url("taxonomy/term/{$root_term->tid}/edit", array('absolute' => TRUE)),
+      'url:unaliased:path' => "taxonomy/term/{$root_term->id()}",
+      'edit-url' => url("taxonomy/term/{$root_term->id()}/edit", array('absolute' => TRUE)),
       'parents' => NULL,
       'parents:count' => NULL,
       'parents:keys' => NULL,
@@ -54,29 +54,29 @@ class TokenTaxonomyTestCase extends TokenTestBase {
     );
     $this->assertTokens('term', array('term' => $root_term), $tokens);
 
-    $parent_term = $this->addTerm($this->vocab, array('name' => 'Parent term', 'parent' => $root_term->tid));
+    $parent_term = $this->addTerm($this->vocab, array('name' => 'Parent term', 'parent' => $root_term->id()));
     $tokens = array(
-      'url' => url("taxonomy/term/{$parent_term->tid}", array('absolute' => TRUE)),
-      'url:absolute' => url("taxonomy/term/{$parent_term->tid}", array('absolute' => TRUE)),
-      'url:relative' => url("taxonomy/term/{$parent_term->tid}", array('absolute' => FALSE)),
-      'url:path' => "taxonomy/term/{$parent_term->tid}",
-      'url:unaliased:path' => "taxonomy/term/{$parent_term->tid}",
-      'edit-url' => url("taxonomy/term/{$parent_term->tid}/edit", array('absolute' => TRUE)),
+      'url' => url("taxonomy/term/{$parent_term->id()}", array('absolute' => TRUE)),
+      'url:absolute' => url("taxonomy/term/{$parent_term->id()}", array('absolute' => TRUE)),
+      'url:relative' => url("taxonomy/term/{$parent_term->id()}", array('absolute' => FALSE)),
+      'url:path' => "taxonomy/term/{$parent_term->id()}",
+      'url:unaliased:path' => "taxonomy/term/{$parent_term->id()}",
+      'edit-url' => url("taxonomy/term/{$parent_term->id()}/edit", array('absolute' => TRUE)),
       'parents' => 'Root term',
       'parents:count' => 1,
-      'parents:keys' => $root_term->tid,
-      'root' => check_plain($root_term->name),
-      'root:tid' => $root_term->tid,
+      'parents:keys' => $root_term->id(),
+      'root' => String::checkPlain($root_term->label()),
+      'root:tid' => $root_term->id(),
       // Deprecated tokens
-      'url:alias' => "taxonomy/term/{$parent_term->tid}",
+      'url:alias' => "taxonomy/term/{$parent_term->id()}",
     );
     $this->assertTokens('term', array('term' => $parent_term), $tokens);
 
-    $term = $this->addTerm($this->vocab, array('name' => 'Test term', 'parent' => $parent_term->tid));
+    $term = $this->addTerm($this->vocab, array('name' => 'Test term', 'parent' => $parent_term->id()));
     $tokens = array(
       'parents' => 'Root term, Parent term',
       'parents:count' => 2,
-      'parents:keys' => implode(', ', array($root_term->tid, $parent_term->tid)),
+      'parents:keys' => implode(', ', array($root_term->id(), $parent_term->id())),
     );
     $this->assertTokens('term', array('term' => $term), $tokens);
   }
@@ -98,18 +98,16 @@ class TokenTaxonomyTestCase extends TokenTestBase {
       'name' => drupal_strtolower($this->randomName(5)),
       'nodes' => array('article' => 'article'),
     );
-    $vocabulary = entity_create('taxonomy_vocabulary', $vocabulary);
-    taxonomy_vocabulary_save($vocabulary);
+    $vocabulary = entity_create('taxonomy_vocabulary', $vocabulary)->save();
     return $vocabulary;
   }
 
-  function addTerm(stdClass $vocabulary, array $term = array()) {
+  function addTerm($vocabulary, array $term = array()) {
     $term += array(
       'name' => drupal_strtolower($this->randomName(5)),
-      'vid' => $vocabulary->vid,
+      'vid' => $vocabulary->id(),
     );
-    $term = entity_create('taxonomy_term', $term);
-    taxonomy_term_save($term);
+    $term = entity_create('taxonomy_term', $term)->save();
     return $term;
   }
 }
diff --git a/lib/Drupal/token/Tests/TokenUserTestCase.php b/lib/Drupal/token/Tests/TokenUserTestCase.php
index b348050..7157f52 100644
--- a/lib/Drupal/token/Tests/TokenUserTestCase.php
+++ b/lib/Drupal/token/Tests/TokenUserTestCase.php
@@ -24,11 +24,11 @@ class TokenUserTestCase extends TokenTestBase {
     parent::setUp($modules);
 
     // Enable user pictures.
-    variable_set('user_pictures', 1);
-    variable_set('user_picture_file_size', '');
+    \Drupal::state()->set('user_pictures', 1);
+    \Drupal::state()->set('user_picture_file_size', '');
 
     // Set up the pictures directory.
-    $picture_path = file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures');
+    $picture_path = file_default_scheme() . '://' . \Drupal::state()->get('user_picture_path', 'pictures');
     if (!file_prepare_directory($picture_path, FILE_CREATE_DIRECTORY)) {
       $this->fail('Could not create directory ' . $picture_path . '.');
     }
@@ -41,19 +41,19 @@ class TokenUserTestCase extends TokenTestBase {
     // Add a user picture to the account.
     $image = current($this->drupalGetTestFiles('image'));
     $edit = array('files[picture_upload]' => drupal_realpath($image->uri));
-    $this->drupalPost('user/' . $this->account->uid . '/edit', $edit, t('Save'));
+    $this->drupalPost('user/' . $this->account->id() . '/edit', $edit, t('Save'));
 
     // Load actual user data from database.
-    $this->account = user_load($this->account->uid, TRUE);
-    $this->assertTrue(!empty($this->account->picture->fid), 'User picture uploaded.');
+    $this->account = user_load($this->account->id(), TRUE);
+    $this->assertTrue(!empty($this->account->user_picture->target_id), 'User picture uploaded.');
 
     $user_tokens = array(
       'picture' => theme('user_picture', array('account' => $this->account)),
-      'picture:fid' => $this->account->picture->fid,
+      'picture:fid' => $this->account->user_picture->target_id,
       'picture:size-raw' => 125,
       'ip-address' => NULL,
-      'roles' => implode(', ', $this->account->roles),
-      'roles:keys' => implode(', ', array_keys($this->account->roles)),
+      'roles' => implode(', ', $this->account->getRoles()),
+      'roles:keys' => implode(', ', array_keys($this->account->getRoles())),
     );
     $this->assertTokens('user', array('user' => $this->account), $user_tokens);
 
@@ -62,8 +62,8 @@ class TokenUserTestCase extends TokenTestBase {
     $this->assertText('The configuration options have been saved.');
 
     // Remove the simpletest-created user role.
-    user_role_delete(end($this->account->roles));
-    $this->account = user_load($this->account->uid, TRUE);
+    $this->account->removeRole(end($this->account->getRoles()));
+    $this->account = user_load($this->account->id(), TRUE);
 
     $user_tokens = array(
       'picture' => NULL,
@@ -76,13 +76,11 @@ class TokenUserTestCase extends TokenTestBase {
 
     // The ip address token should work for the current user token type.
     $tokens = array(
-      'ip-address' => ip_address(),
+      'ip-address' => \Drupal::request()->getClientIp(),
     );
     $this->assertTokens('current-user', array(), $tokens);
 
     $anonymous = drupal_anonymous_user();
-    // Mess with the role array to ensure we still get consistent output.
-    $anonymous->roles[DRUPAL_ANONYMOUS_RID] = DRUPAL_ANONYMOUS_RID;
     $tokens = array(
       'roles' => 'anonymous user',
       'roles:keys' => (string) DRUPAL_ANONYMOUS_RID,
diff --git a/token.tokens.inc b/token.tokens.inc
index 2f47d24..1fcfc72 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -6,6 +6,7 @@
  */
 use Drupal\Component\Utility\Crypt;
 use Drupal\Component\Utility\String;
+use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Render\Element;
 use Drupal\field\Field;
 
@@ -1299,6 +1300,9 @@ function field_tokens($type, $tokens, array $data = array(), array $options = ar
     // The field API does weird stuff to the entity, so let's clone it.
     /* @var \Drupal\Core\Entity\EntityInterface $entity */
     $entity = clone $data['entity'];
+    if (!($entity instanceof EntityInterface)) {
+      return $replacements;
+    }
 
     // Reset the prepared view flag in case token generation is called from
     // inside field_attach_view().
-- 
1.9.3 (Apple Git-50)


From 08b13facad7a1a56f241808da2c61f8230056fcf Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Sun, 16 Feb 2014 11:44:08 +1300
Subject: [PATCH 094/230] Issue #1962358 by grom358: Fixed TokenBlockTestCase

---
 lib/Drupal/token/Tests/TokenBlockTestCase.php | 27 +++++++++++++++++++--------
 token.module                                  | 10 +++++-----
 token.tokens.inc                              |  5 ++++-
 3 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenBlockTestCase.php b/lib/Drupal/token/Tests/TokenBlockTestCase.php
index 542fd04..7245d7f 100644
--- a/lib/Drupal/token/Tests/TokenBlockTestCase.php
+++ b/lib/Drupal/token/Tests/TokenBlockTestCase.php
@@ -10,7 +10,7 @@ namespace Drupal\token\Tests;
  * Tests block tokens.
  */
 class TokenBlockTestCase extends TokenTestBase {
-  protected static $modules = array('path', 'token', 'token_test', 'block', 'node');
+  protected static $modules = array('path', 'token', 'token_test', 'block', 'node', 'views', 'custom_block');
 
   public static function getInfo() {
     return array(
@@ -27,14 +27,25 @@ class TokenBlockTestCase extends TokenTestBase {
   }
 
   public function testBlockTitleTokens() {
-    $edit['title'] = '[current-page:title] block title';
-    $edit['info'] = 'Test token title block';
-    $edit['body[value]'] = 'This is the test token title block.';
-    $edit['regions[bartik]'] = 'sidebar_first';
-    $this->drupalPost('admin/structure/block/add', $edit, 'Save block');
+    $label = 'tokenblock';
+    $bundle = entity_create('custom_block_type', array(
+      'id' => $label,
+      'label' => $label,
+      'revision' => FALSE
+    ));
+    $bundle->save();
 
-    $this->drupalGet('node');
-    $this->assertText('Welcome to ' . \Drupal::config('system.site')->get('name') . ' block title');
+    /* @var \Drupal\custom_block\CustomBlockInterface $block */
+    $block = entity_create('custom_block', array(
+      'type' => $label,
+      'label' => '[current-page:title] block title',
+      'info' => 'Test token title block',
+      'body[value]' => 'This is the test token title block.',
+    ));
+    $block->save();
+    $this->drupalPlaceBlock('custom_block:' . $block->uuid(), array(
+      'label' => '[current-page:title] block title',
+    ));
 
     // Ensure that tokens are not double-escaped when output as a block title.
     $node = $this->drupalCreateNode(array('title' => "Site's first node"));
diff --git a/token.module b/token.module
index 6ca3f9d..385f706 100644
--- a/token.module
+++ b/token.module
@@ -206,11 +206,11 @@ function token_form_alter(&$form, $form_state, $form_id) {
 /**
  * Implements hook_block_view_alter().
  */
-function token_block_view_alter(&$data, $block) {
-  if (!empty($block->title) && $block->title != '<none>') {
-    // Perform unsanitized token replacement since _block_render_blocks() will
-    // call check_plain() on $block->title.
-    $block->title = \Drupal::token()->replace($block->title, array(), array('sanitize' => FALSE));
+function token_block_view_alter(&$data, \Drupal\block\BlockPluginInterface $block) {
+  $label = $block->getConfiguration()['label'];
+  if ($label != '<none>') {
+    //$block->setConfigurationValue('label', \Drupal::token()->replace($label, array(), array('sanitize' => TRUE)));
+    $data['#configuration']['label'] = \Drupal::token()->replace($label, array(), array('sanitize' => TRUE));
   }
 }
 
diff --git a/token.tokens.inc b/token.tokens.inc
index 1fcfc72..198ea02 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -9,6 +9,7 @@ use Drupal\Component\Utility\String;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Render\Element;
 use Drupal\field\Field;
+use Symfony\Cmf\Component\Routing\RouteObjectInterface;
 
 /**
  * Implements hook_token_info_alter().
@@ -672,7 +673,9 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'title':
-          $title = drupal_get_title();
+          $request = \Drupal::request();
+          $route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT);
+          $title = \Drupal::service('title_resolver')->getTitle($request, $route);
           $replacements[$original] = $sanitize ? $title : decode_entities($title);
           break;
         case 'url':
-- 
1.9.3 (Apple Git-50)


From dbe5944c820e4e491f17da35d542c887bea58ab8 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Sun, 16 Feb 2014 11:52:46 +1300
Subject: [PATCH 095/230] Issue #1962358 by larowlan: More test fixes

---
 lib/Drupal/token/Tests/TokenTaxonomyTestCase.php | 13 ++++---
 lib/Drupal/token/Tests/TokenUnitTestCase.php     |  2 +
 lib/Drupal/token/Tests/TokenUserTestCase.php     | 22 ++++++-----
 token.module                                     |  2 +-
 token.tokens.inc                                 | 48 ++++++++++++------------
 5 files changed, 46 insertions(+), 41 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php b/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php
index 37a0489..b1b69e6 100644
--- a/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php
+++ b/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php
@@ -13,6 +13,8 @@ use Drupal\Component\Utility\String;
 class TokenTaxonomyTestCase extends TokenTestBase {
   protected $vocab;
 
+  protected static $modules = array('path', 'token', 'token_test', 'taxonomy');
+
   public static function getInfo() {
     return array(
       'name' => 'Taxonomy and vocabulary token tests',
@@ -22,14 +24,14 @@ class TokenTaxonomyTestCase extends TokenTestBase {
   }
 
   public function setUp($modules = array()) {
-    $modules[] = 'taxonomy';
     parent::setUp($modules);
 
     // Create the default tags vocabulary.
     $vocabulary = entity_create('taxonomy_vocabulary', array(
       'name' => 'Tags',
-      'machine_name' => 'tags',
-    ))->save();
+      'vid' => 'tags',
+    ));
+    $vocabulary->save();
     $this->vocab = $vocabulary;
   }
 
@@ -88,7 +90,7 @@ class TokenTaxonomyTestCase extends TokenTestBase {
     $vocabulary = $this->vocab;
     $tokens = array(
       'machine-name' => 'tags',
-      'edit-url' => url("admin/structure/taxonomy/{$vocabulary->machine_name}/edit", array('absolute' => TRUE)),
+      'edit-url' => url("admin/structure/taxonomy/{$vocabulary->id()}/edit", array('absolute' => TRUE)),
     );
     $this->assertTokens('vocabulary', array('vocabulary' => $vocabulary), $tokens);
   }
@@ -107,7 +109,8 @@ class TokenTaxonomyTestCase extends TokenTestBase {
       'name' => drupal_strtolower($this->randomName(5)),
       'vid' => $vocabulary->id(),
     );
-    $term = entity_create('taxonomy_term', $term)->save();
+    $term = entity_create('taxonomy_term', $term);
+    $term->save();
     return $term;
   }
 }
diff --git a/lib/Drupal/token/Tests/TokenUnitTestCase.php b/lib/Drupal/token/Tests/TokenUnitTestCase.php
index 96d09ee..1d25b62 100644
--- a/lib/Drupal/token/Tests/TokenUnitTestCase.php
+++ b/lib/Drupal/token/Tests/TokenUnitTestCase.php
@@ -10,6 +10,8 @@ namespace Drupal\token\Tests;
  * Token unit tests.
  */
 class TokenUnitTestCase extends TokenTestBase {
+  protected static $modules = array('path', 'token', 'token_test', 'file');
+
   public static function getInfo() {
     return array(
       'name' => 'Token unit tests',
diff --git a/lib/Drupal/token/Tests/TokenUserTestCase.php b/lib/Drupal/token/Tests/TokenUserTestCase.php
index 7157f52..a95c14a 100644
--- a/lib/Drupal/token/Tests/TokenUserTestCase.php
+++ b/lib/Drupal/token/Tests/TokenUserTestCase.php
@@ -5,6 +5,7 @@
  * Contains \Drupal\token\Tests\TokenUserTestCase.
  */
 namespace Drupal\token\Tests;
+use Drupal\field\Field;
 
 /**
  * Tests user tokens.
@@ -12,6 +13,9 @@ namespace Drupal\token\Tests;
 class TokenUserTestCase extends TokenTestBase {
   protected $account = NULL;
 
+  // User pictures only exist in standard now.
+  protected $profile = 'standard';
+
   public static function getInfo() {
     return array(
       'name' => 'User token tests',
@@ -40,8 +44,8 @@ class TokenUserTestCase extends TokenTestBase {
   function testUserTokens() {
     // Add a user picture to the account.
     $image = current($this->drupalGetTestFiles('image'));
-    $edit = array('files[picture_upload]' => drupal_realpath($image->uri));
-    $this->drupalPost('user/' . $this->account->id() . '/edit', $edit, t('Save'));
+    $edit = array('files[user_picture_0]' => drupal_realpath($image->uri));
+    $this->drupalPostForm('user/' . $this->account->id() . '/edit', $edit, t('Save'));
 
     // Load actual user data from database.
     $this->account = user_load($this->account->id(), TRUE);
@@ -53,23 +57,21 @@ class TokenUserTestCase extends TokenTestBase {
       'picture:size-raw' => 125,
       'ip-address' => NULL,
       'roles' => implode(', ', $this->account->getRoles()),
-      'roles:keys' => implode(', ', array_keys($this->account->getRoles())),
     );
     $this->assertTokens('user', array('user' => $this->account), $user_tokens);
 
-    $edit = array('user_pictures' => FALSE);
-    $this->drupalPost('admin/config/people/accounts', $edit, 'Save configuration');
-    $this->assertText('The configuration options have been saved.');
+    // Remove the user picture field.
+    Field::fieldInfo()->getField('user', 'user_picture')->delete();
 
     // Remove the simpletest-created user role.
-    $this->account->removeRole(end($this->account->getRoles()));
-    $this->account = user_load($this->account->id(), TRUE);
+    $roles = $this->account->getRoles();
+    $this->account->removeRole(end($roles));
 
     $user_tokens = array(
       'picture' => NULL,
       'picture:fid' => NULL,
       'ip-address' => NULL,
-      'roles' => 'authenticated user',
+      'roles' => 'authenticated',
       'roles:keys' => (string) DRUPAL_AUTHENTICATED_RID,
     );
     $this->assertTokens('user', array('user' => $this->account), $user_tokens);
@@ -82,7 +84,7 @@ class TokenUserTestCase extends TokenTestBase {
 
     $anonymous = drupal_anonymous_user();
     $tokens = array(
-      'roles' => 'anonymous user',
+      'roles' => 'anonymous',
       'roles:keys' => (string) DRUPAL_ANONYMOUS_RID,
     );
     $this->assertTokens('user', array('user' => $anonymous), $tokens);
diff --git a/token.module b/token.module
index 385f706..848a8ff 100644
--- a/token.module
+++ b/token.module
@@ -1177,7 +1177,7 @@ function token_taxonomy_term_load_all_parents($tid) {
     array_shift($parents); // Remove this term from the array.
     $parents = array_reverse($parents);
     foreach ($parents as $term) {
-      $cache[$tid][$term->tid] = $term->label();
+      $cache[$tid][$term->id()] = $term->label();
     }
   }
 
diff --git a/token.tokens.inc b/token.tokens.inc
index 198ea02..98c26c8 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -29,7 +29,9 @@ function token_token_info_alter(&$info) {
 
   // The [file:size] may not always return in kilobytes.
   // @todo Remove when http://drupal.org/node/1193044 is fixed.
-  $info['tokens']['file']['size']['description'] = t('The size of the file.');
+  if (!empty($info['tokens']['file']['size'])) {
+    $info['tokens']['file']['size']['description'] = t('The size of the file.');
+  }
 
   // Remove deprecated tokens from being listed.
   unset($info['tokens']['node']['tnid']);
@@ -61,10 +63,10 @@ function token_token_info_alter(&$info) {
 
     // Add [entity:url] tokens if they do not already exist.
     // @todo Support entity:label
-    if (!isset($info['tokens'][$token_type]['url']) && !empty($entity_info['uri callback'])) {
+    if (!isset($info['tokens'][$token_type]['url'])) {
       $info['tokens'][$token_type]['url'] = array(
         'name' => t('URL'),
-        'description' => t('The URL of the @entity.', array('@entity' => drupal_strtolower($entity_info['label']))),
+        'description' => t('The URL of the @entity.', array('@entity' => drupal_strtolower($entity_info->getLabel()))),
         'module' => 'token',
         'type' => 'url',
       );
@@ -73,8 +75,8 @@ function token_token_info_alter(&$info) {
     // Add [entity:original] tokens if they do not already exist.
     if (!isset($info['tokens'][$token_type]['original'])) {
       $info['tokens'][$token_type]['original'] = array(
-        'name' => t('Original @entity', array('@entity' => drupal_strtolower($entity_info['label']))),
-        'description' => t('The original @entity data if the @entity is being updated or saved.', array('@entity' => drupal_strtolower($entity_info['label']))),
+        'name' => t('Original @entity', array('@entity' => drupal_strtolower($entity_info->getLabel()))),
+        'description' => t('The original @entity data if the @entity is being updated or saved.', array('@entity' => drupal_strtolower($entity_info->getLabel()))),
         'module' => 'token',
         'type' => $token_type,
       );
@@ -499,8 +501,8 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
         case 'root':
           $parents = taxonomy_term_load_parents_all($term->id());
           $root_term = end($parents);
-          if ($root_term->tid != $term->id()) {
-            $replacements[$original] = $sanitize ? String::checkPlain($root_term->name) : $root_term->name;
+          if ($root_term->id() != $term->id()) {
+            $replacements[$original] = $sanitize ? String::checkPlain($root_term->label()) : $root_term->label();
           }
           break;
       }
@@ -533,10 +535,10 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       switch ($name) {
         case 'machine-name':
           // This is a machine name so does not ever need to be sanitized.
-          $replacements[$original] = $vocabulary->machine_name;
+          $replacements[$original] = $vocabulary->id();
           break;
         case 'edit-url':
-          $replacements[$original] = url("admin/structure/taxonomy/{$vocabulary->machine_name}/edit", $url_options);
+          $replacements[$original] = url("admin/structure/taxonomy/{$vocabulary->id()}/edit", $url_options);
           break;
       }
     }
@@ -549,15 +551,15 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'basename':
-          $basename = pathinfo($file->uri, PATHINFO_BASENAME);
+          $basename = pathinfo($file->uri->value, PATHINFO_BASENAME);
           $replacements[$original] = $sanitize ? String::checkPlain($basename) : $basename;
           break;
         case 'extension':
-          $extension = pathinfo($file->uri, PATHINFO_EXTENSION);
+          $extension = pathinfo($file->uri->value, PATHINFO_EXTENSION);
           $replacements[$original] = $sanitize ? String::checkPlain($extension) : $extension;
           break;
         case 'size-raw':
-          $replacements[$original] = (int) $file->filesize;
+          $replacements[$original] = (int) $file->filesize->value;
           break;
       }
     }
@@ -577,7 +579,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
         case 'roles':
           // The roles array may be set from checkbox values so ensure it always
           // has 'proper' data with the role names.
-          $roles = array_intersect_key(user_roles(), $account->getRoles());
+          $roles = $account->getRoles();
           $replacements[$original] = token_render_array($roles, $options);
           break;
       }
@@ -720,8 +722,10 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
   }
 
   // URL tokens.
-  if ($type == 'url' && !empty($data['path'])) {
-    $path = $data['path'];
+  if ($type == 'url' && !empty($data['route_name'])) {
+    $route = $data['route_name'];
+    $route_param = $data['route_params'];
+    $path = \Drupal::url($route, $route_param);
 
     if (isset($data['options'])) {
       // Merge in the URL options if available.
@@ -740,16 +744,16 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           $replacements[$original] = $sanitize ? String::checkPlain($alias) : $alias;
           break;
         case 'absolute':
-          $replacements[$original] = url($path, $url_options);
+          $replacements[$original] = \Drupal::url($route, $route_param, $url_options);
           break;
         case 'relative':
-          $replacements[$original] = url($path, array('absolute' => FALSE) + $url_options);
+          $replacements[$original] = \Drupal::url($route, $route_param, array('absolute' => FALSE) + $url_options);
           break;
         case 'brief':
-          $replacements[$original] = preg_replace(array('!^https?://!', '!/$!'), '', url($path, $url_options));
+          $replacements[$original] = preg_replace(array('!^https?://!', '!/$!'), '', \Drupal::url($route, $route_param, $url_options));
           break;
         case 'unaliased':
-          $replacements[$original] = url($path, array('alias' => TRUE) + $url_options);
+          $replacements[$original] = \Drupal::url($route, $route_param, array('alias' => TRUE) + $url_options);
           break;
         case 'args':
           $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getPathAlias($path, $language_code) : $path;
@@ -778,12 +782,6 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     /* @var \Drupal\Core\Entity\EntityInterface $entity */
     $entity = $data[$type];
 
-    // Sometimes taxonomy terms are not properly loaded.
-    // @see http://drupal.org/node/870528
-    if ($entity_type == 'taxonomy_term' && !isset($entity->vocabulary_machine_name)) {
-      $entity->vocabulary_machine_name = db_query("SELECT machine_name FROM {taxonomy_vocabulary} WHERE vid = :vid", array(':vid' => $entity->vid))->fetchField();
-    }
-
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'url':
-- 
1.9.3 (Apple Git-50)


From 1c052363307f33023a9c4677a785297b0a1b134a Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Sun, 16 Feb 2014 12:15:30 +1300
Subject: [PATCH 096/230] Issue #1962358 by grom358: Fixed TokenDateTestCase

---
 tests/token_test/config/system.date_format.token_test.yml | 9 +++++++++
 tests/{ => token_test}/token_test.info.yml                | 0
 tests/{ => token_test}/token_test.module                  | 0
 token.tokens.inc                                          | 4 +++-
 4 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 tests/token_test/config/system.date_format.token_test.yml
 rename tests/{ => token_test}/token_test.info.yml (100%)
 rename tests/{ => token_test}/token_test.module (100%)

diff --git a/tests/token_test/config/system.date_format.token_test.yml b/tests/token_test/config/system.date_format.token_test.yml
new file mode 100644
index 0000000..43e8a62
--- /dev/null
+++ b/tests/token_test/config/system.date_format.token_test.yml
@@ -0,0 +1,9 @@
+id: token_test
+uuid: 3A60E8ED-25C7-4402-8F2A-C305B8916B0E
+label: 'Token test'
+status: true
+langcode: en
+locked: true
+pattern:
+  php: Y
+  intl: yyyy
diff --git a/tests/token_test.info.yml b/tests/token_test/token_test.info.yml
similarity index 100%
rename from tests/token_test.info.yml
rename to tests/token_test/token_test.info.yml
diff --git a/tests/token_test.module b/tests/token_test/token_test.module
similarity index 100%
rename from tests/token_test.module
rename to tests/token_test/token_test.module
diff --git a/token.tokens.inc b/token.tokens.inc
index 98c26c8..fc3679b 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -42,7 +42,9 @@ function token_token_info_alter(&$info) {
   if (isset($info['tokens']['comment']['url']) && \Drupal::moduleHandler()->moduleExists('comment')) {
     $info['tokens']['comment']['url']['type'] = 'url';
   }
-  $info['tokens']['node']['url']['type'] = 'url';
+  if (isset($info['tokens']['node']['url']) && \Drupal::moduleHandler()->moduleExists('node')) {
+    $info['tokens']['node']['url']['type'] = 'url';
+  }
   if (isset($info['tokens']['term']['url']) && \Drupal::moduleHandler()->moduleExists('taxonomy')) {
     $info['tokens']['term']['url']['type'] = 'url';
   }
-- 
1.9.3 (Apple Git-50)


From 1200452b86010ce9bb1dc4f8157fd0bba97f0301 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Sun, 16 Feb 2014 13:10:26 +1300
Subject: [PATCH 097/230] Issue #1962358 by grom358: Fixed TokenFileTestCase

---
 lib/Drupal/token/Tests/TokenFileTestCase.php | 2 ++
 token.tokens.inc                             | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/Drupal/token/Tests/TokenFileTestCase.php b/lib/Drupal/token/Tests/TokenFileTestCase.php
index ac14f79..84b47ef 100644
--- a/lib/Drupal/token/Tests/TokenFileTestCase.php
+++ b/lib/Drupal/token/Tests/TokenFileTestCase.php
@@ -10,6 +10,8 @@ namespace Drupal\token\Tests;
  * Tests file tokens.
  */
 class TokenFileTestCase extends TokenTestBase {
+  protected static $modules = array('path', 'token', 'token_test', 'file');
+
   public static function getInfo() {
     return array(
       'name' => 'File token tests',
diff --git a/token.tokens.inc b/token.tokens.inc
index fc3679b..5932f29 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -726,7 +726,10 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
   // URL tokens.
   if ($type == 'url' && !empty($data['route_name'])) {
     $route = $data['route_name'];
-    $route_param = $data['route_params'];
+    $route_param = array();
+    if (isset($data['route_parameters'])) {
+      $route_param = $data['route_parameters'];
+    }
     $path = \Drupal::url($route, $route_param);
 
     if (isset($data['options'])) {
-- 
1.9.3 (Apple Git-50)


From ec74786b28ee2b938adf13e98b0b7da20c76d33e Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Sun, 16 Feb 2014 14:13:46 +1300
Subject: [PATCH 098/230] Issue #1962358 by grom358: More test fixes

---
 token.tokens.inc | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index 5932f29..3b27920 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -445,7 +445,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     if (!empty($node->tnid) && ($source_tokens = \Drupal::token()->findWithPrefix($tokens, 'source')) && $source_node = node_load($node->tnid)) {
       $replacements += \Drupal::token()->generate('node', $source_tokens, array('node' => $source_node), $options);
     }
-    if (($node_type_tokens = \Drupal::token()->findWithPrefix($tokens, 'content-type')) && $node_type = node_type_load($node->type)) {
+    if (($node_type_tokens = \Drupal::token()->findWithPrefix($tokens, 'content-type')) && $node_type = node_type_load($node->bundle())) {
       $replacements += \Drupal::token()->generate('content-type', $node_type_tokens, array('node_type' => $node_type), $options);
     }
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
@@ -579,9 +579,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           break;
 
         case 'roles':
-          // The roles array may be set from checkbox values so ensure it always
-          // has 'proper' data with the role names.
-          $roles = $account->getRoles();
+          $roles = drupal_map_assoc($account->getRoles());
           $replacements[$original] = token_render_array($roles, $options);
           break;
       }
@@ -595,9 +593,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       $replacements += \Drupal::token()->generate('url', $url_tokens, $account->urlInfo(), $options);
     }
     if ($role_tokens = \Drupal::token()->findWithPrefix($tokens, 'roles')) {
-      // The roles array may be set from checkbox values so ensure it always
-      // has 'proper' data with the role names.
-      $roles = array_intersect_key(user_roles(), $account->getRoles());
+      $roles = drupal_map_assoc($account->getRoles());
       $replacements += \Drupal::token()->generate('array', $role_tokens, array('array' => $roles), $options);
     }
   }
-- 
1.9.3 (Apple Git-50)


From abdc341e65118f623e77e805215c5018446fc707 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Sun, 16 Feb 2014 14:14:24 +1300
Subject: [PATCH 099/230] Issue #1962358 by grom358: Fixed TokenUserTestCase

---
 lib/Drupal/token/Tests/TokenUserTestCase.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenUserTestCase.php b/lib/Drupal/token/Tests/TokenUserTestCase.php
index a95c14a..c2013af 100644
--- a/lib/Drupal/token/Tests/TokenUserTestCase.php
+++ b/lib/Drupal/token/Tests/TokenUserTestCase.php
@@ -24,8 +24,8 @@ class TokenUserTestCase extends TokenTestBase {
     );
   }
 
-  public function setUp($modules = array()) {
-    parent::setUp($modules);
+  public function setUp() {
+    parent::setUp();
 
     // Enable user pictures.
     \Drupal::state()->set('user_pictures', 1);
-- 
1.9.3 (Apple Git-50)


From 8990130db3dc3a740b5ecebbfe8e8f1a4530adf2 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Sun, 16 Feb 2014 14:41:26 +1300
Subject: [PATCH 100/230] Issue #1962358 by grom358: Fixed TokenURLTestCase

---
 lib/Drupal/token/Tests/TokenURLTestCase.php | 23 +++++++++++++----------
 token.tokens.inc                            |  6 +++++-
 2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenURLTestCase.php b/lib/Drupal/token/Tests/TokenURLTestCase.php
index e2f37b1..c411ac7 100644
--- a/lib/Drupal/token/Tests/TokenURLTestCase.php
+++ b/lib/Drupal/token/Tests/TokenURLTestCase.php
@@ -10,6 +10,8 @@ namespace Drupal\token\Tests;
  * Tests url tokens.
  */
 class TokenURLTestCase extends TokenTestBase {
+  protected static $modules = array('path', 'token', 'token_test', 'node');
+
   public static function getInfo() {
     return array(
       'name' => 'URL token tests',
@@ -18,30 +20,31 @@ class TokenURLTestCase extends TokenTestBase {
     );
   }
 
-  public function setUp($modules = array()) {
-    parent::setUp($modules);
+  public function setUp() {
+    parent::setUp();
     $this->saveAlias('node/1', 'first-node');
   }
 
   function testURLTokens() {
+    $host = \Drupal::request()->getHttpHost();
     $tokens = array(
-      'absolute' => 'http://example.com/first-node',
+      'absolute' => "http://{$host}/first-node",
       'relative' => base_path() . 'first-node',
-      'path' => 'first-node',
-      'brief' => 'example.com/first-node',
+      'path' => '/first-node',
+      'brief' => "{$host}/first-node",
       'args:value:0' => 'first-node',
       'args:value:1' => NULL,
       'args:value:N' => NULL,
-      'unaliased' => 'http://example.com/node/1',
+      'unaliased' => "http://{$host}/node/1",
       'unaliased:relative' => base_path() . 'node/1',
-      'unaliased:path' => 'node/1',
-      'unaliased:brief' => 'example.com/node/1',
+      'unaliased:path' => '/node/1',
+      'unaliased:brief' => "{$host}/node/1",
       'unaliased:args:value:0' => 'node',
       'unaliased:args:value:1' => '1',
       'unaliased:args:value:2' => NULL,
       // Deprecated tokens.
-      'alias' => 'first-node',
+      'alias' => '/first-node',
     );
-    $this->assertTokens('url', array('path' => 'node/1', 'options' => array('base_url' => 'http://example.com')), $tokens);
+    $this->assertTokens('url', array('route_name' => 'node.view', 'route_parameters' => array('node' => 1)), $tokens);
   }
 }
diff --git a/token.tokens.inc b/token.tokens.inc
index 3b27920..e77fe30 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -726,7 +726,8 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     if (isset($data['route_parameters'])) {
       $route_param = $data['route_parameters'];
     }
-    $path = \Drupal::url($route, $route_param);
+    $options = isset($data['options']) ? $data['options'] : array();
+    $path = \Drupal::url($route, $route_param, $options);
 
     if (isset($data['options'])) {
       // Merge in the URL options if available.
@@ -766,11 +767,14 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     // [url:arg:*] chained tokens.
     if ($arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'args')) {
       $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getPathAlias($path, $language_code) : $path;
+      $value = ltrim($value, '/');
       $replacements += \Drupal::token()->generate('array', $arg_tokens, array('array' => arg(NULL, $value)), $options);
     }
 
     // [url:unaliased:*] chained tokens.
     if ($unaliased_tokens = \Drupal::token()->findWithPrefix($tokens, 'unaliased')) {
+      $unaliased_token_data['route_name'] = $route;
+      $unaliased_token_data['route_parameters'] = $route_param;
       $unaliased_token_data['path'] = $path;
       $unaliased_token_data['options'] = isset($data['options']) ? $data['options'] : array();
       $unaliased_token_data['options']['alias'] = TRUE;
-- 
1.9.3 (Apple Git-50)


From fd25e6bb11ae1942bcecc1699d9e2bf06f8b757c Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Sun, 16 Feb 2014 15:11:42 +1300
Subject: [PATCH 101/230] Issue #1962358 by grom358: Fixed TokenNodeTestCase

---
 lib/Drupal/token/Tests/TokenTaxonomyTestCase.php | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php b/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php
index b1b69e6..ebcb70d 100644
--- a/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php
+++ b/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php
@@ -23,8 +23,8 @@ class TokenTaxonomyTestCase extends TokenTestBase {
     );
   }
 
-  public function setUp($modules = array()) {
-    parent::setUp($modules);
+  public function setUp() {
+    parent::setUp();
 
     // Create the default tags vocabulary.
     $vocabulary = entity_create('taxonomy_vocabulary', array(
@@ -44,15 +44,15 @@ class TokenTaxonomyTestCase extends TokenTestBase {
       'url' => url("taxonomy/term/{$root_term->id()}", array('absolute' => TRUE)),
       'url:absolute' => url("taxonomy/term/{$root_term->id()}", array('absolute' => TRUE)),
       'url:relative' => url("taxonomy/term/{$root_term->id()}", array('absolute' => FALSE)),
-      'url:path' => 'root-term',
-      'url:unaliased:path' => "taxonomy/term/{$root_term->id()}",
+      'url:path' => '/root-term',
+      'url:unaliased:path' => "/taxonomy/term/{$root_term->id()}",
       'edit-url' => url("taxonomy/term/{$root_term->id()}/edit", array('absolute' => TRUE)),
       'parents' => NULL,
       'parents:count' => NULL,
       'parents:keys' => NULL,
       'root' => NULL,
       // Deprecated tokens
-      'url:alias' => 'root-term',
+      'url:alias' => '/root-term',
     );
     $this->assertTokens('term', array('term' => $root_term), $tokens);
 
@@ -61,8 +61,8 @@ class TokenTaxonomyTestCase extends TokenTestBase {
       'url' => url("taxonomy/term/{$parent_term->id()}", array('absolute' => TRUE)),
       'url:absolute' => url("taxonomy/term/{$parent_term->id()}", array('absolute' => TRUE)),
       'url:relative' => url("taxonomy/term/{$parent_term->id()}", array('absolute' => FALSE)),
-      'url:path' => "taxonomy/term/{$parent_term->id()}",
-      'url:unaliased:path' => "taxonomy/term/{$parent_term->id()}",
+      'url:path' => "/taxonomy/term/{$parent_term->id()}",
+      'url:unaliased:path' => "/taxonomy/term/{$parent_term->id()}",
       'edit-url' => url("taxonomy/term/{$parent_term->id()}/edit", array('absolute' => TRUE)),
       'parents' => 'Root term',
       'parents:count' => 1,
@@ -70,7 +70,7 @@ class TokenTaxonomyTestCase extends TokenTestBase {
       'root' => String::checkPlain($root_term->label()),
       'root:tid' => $root_term->id(),
       // Deprecated tokens
-      'url:alias' => "taxonomy/term/{$parent_term->id()}",
+      'url:alias' => "/taxonomy/term/{$parent_term->id()}",
     );
     $this->assertTokens('term', array('term' => $parent_term), $tokens);
 
-- 
1.9.3 (Apple Git-50)


From 974cdd0c45c18d4301574eaedf649a383ac16e04 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Sun, 16 Feb 2014 15:12:38 +1300
Subject: [PATCH 102/230] Issue #1962358 by grom358: Fixed TokenNodeTestCase

---
 lib/Drupal/token/Tests/TokenNodeTestCase.php | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenNodeTestCase.php b/lib/Drupal/token/Tests/TokenNodeTestCase.php
index 70444c0..68aea6f 100644
--- a/lib/Drupal/token/Tests/TokenNodeTestCase.php
+++ b/lib/Drupal/token/Tests/TokenNodeTestCase.php
@@ -25,11 +25,11 @@ class TokenNodeTestCase extends TokenTestBase {
     $tokens = array(
       'source' => NULL,
       'source:nid' => NULL,
-      'log' => $source_node->log,
-      'url:path' => 'content/source-node',
+      'log' => $source_node->log->value,
+      'url:path' => '/content/source-node',
       'url:absolute' => url("node/{$source_node->id()}", array('absolute' => TRUE)),
       'url:relative' => url("node/{$source_node->id()}", array('absolute' => FALSE)),
-      'url:unaliased:path' => "node/{$source_node->id()}",
+      'url:unaliased:path' => "/node/{$source_node->id()}",
       'content-type' => 'Basic page',
       'content-type:name' => 'Basic page',
       'content-type:machine-name' => 'page',
@@ -37,10 +37,9 @@ class TokenNodeTestCase extends TokenTestBase {
       'content-type:node-count' => 1,
       'content-type:edit-url' => url('admin/structure/types/manage/page', array('absolute' => TRUE)),
       // Deprecated tokens.
-      'tnid' => 0,
       'type' => 'page',
       'type-name' => 'Basic page',
-      'url:alias' => 'content/source-node',
+      'url:alias' => '/content/source-node',
     );
     $this->assertTokens('node', array('node' => $source_node), $tokens);
 
@@ -49,10 +48,10 @@ class TokenNodeTestCase extends TokenTestBase {
       'source' => $source_node->label(),
       'source:nid' => $source_node->id(),
       'log' => '',
-      'url:path' => "node/{$translated_node->id()}",
+      'url:path' => "/node/{$translated_node->id()}",
       'url:absolute' => url("node/{$translated_node->id()}", array('absolute' => TRUE)),
       'url:relative' => url("node/{$translated_node->id()}", array('absolute' => FALSE)),
-      'url:unaliased:path' => "node/{$translated_node->id()}",
+      'url:unaliased:path' => "/node/{$translated_node->id()}",
       'content-type' => 'Article',
       'content-type:name' => 'Article',
       'content-type:machine-name' => 'article',
@@ -62,8 +61,7 @@ class TokenNodeTestCase extends TokenTestBase {
       // Deprecated tokens.
       'type' => 'article',
       'type-name' => 'Article',
-      'tnid' => $source_node->id(),
-      'url:alias' => "node/{$translated_node->id()}",
+      'url:alias' => "/node/{$translated_node->id()}",
     );
     $this->assertTokens('node', array('node' => $translated_node), $tokens);
   }
-- 
1.9.3 (Apple Git-50)


From afe40baf6716df4f6c8e8aebe5e17d1d18e39370 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Sun, 16 Feb 2014 16:14:14 +1300
Subject: [PATCH 103/230] Issue #1962358 by grom358: Fixed TokenEntityTestCase

---
 lib/Drupal/token/Tests/TokenEntityTestCase.php | 18 ++++++++++--------
 token.tokens.inc                               |  4 ++--
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenEntityTestCase.php b/lib/Drupal/token/Tests/TokenEntityTestCase.php
index 295ab8a..8d67c22 100644
--- a/lib/Drupal/token/Tests/TokenEntityTestCase.php
+++ b/lib/Drupal/token/Tests/TokenEntityTestCase.php
@@ -11,6 +11,8 @@ use Drupal\taxonomy\VocabularyInterface;
  * Tests entity tokens.
  */
 class TokenEntityTestCase extends TokenTestBase {
+  protected static $modules = array('path', 'token', 'token_test', 'node', 'taxonomy');
+
   public static function getInfo() {
     return array(
       'name' => 'Entity token tests',
@@ -20,15 +22,14 @@ class TokenEntityTestCase extends TokenTestBase {
   }
 
   public function setUp($modules = array()) {
-    $modules[] = 'taxonomy';
-    parent::setUp($modules);
+    parent::setUp();
 
     // Create the default tags vocabulary.
     $vocabulary = entity_create('taxonomy_vocabulary', array(
       'name' => 'Tags',
-      'machine_name' => 'tags',
+      'vid' => 'tags',
     ));
-    taxonomy_vocabulary_save($vocabulary);
+    $vocabulary->save();
     $this->vocab = $vocabulary;
   }
 
@@ -44,10 +45,10 @@ class TokenEntityTestCase extends TokenTestBase {
 
     // Test that when we send the mis-matched entity type into token_replace()
     // that we still get the tokens replaced.
-    $vocabulary = taxonomy_vocabulary_machine_name_load('tags');
+    $vocabulary = entity_load('taxonomy_vocabulary', 'tags');
     $term = $this->addTerm($vocabulary);
-    $this->assertIdentical(\Drupal::token()->replace('[vocabulary:name]', array('taxonomy_vocabulary' => $vocabulary)), $vocabulary->name);
-    $this->assertIdentical(\Drupal::token()->replace('[term:name][term:vocabulary:name]', array('taxonomy_term' => $term)), $term->name . $vocabulary->name);
+    $this->assertIdentical(\Drupal::token()->replace('[vocabulary:name]', array('taxonomy_vocabulary' => $vocabulary)), $vocabulary->label());
+    $this->assertIdentical(\Drupal::token()->replace('[term:name][term:vocabulary:name]', array('taxonomy_term' => $term)), $term->label() . $vocabulary->label());
   }
 
   function addTerm(VocabularyInterface $vocabulary, array $term = array()) {
@@ -55,7 +56,8 @@ class TokenEntityTestCase extends TokenTestBase {
       'name' => drupal_strtolower($this->randomName(5)),
       'vid' => $vocabulary->id(),
     );
-    $term = entity_create('taxonomy_term', $term)->save();
+    $term = entity_create('taxonomy_term', $term);
+    $term->save();
     return $term;
   }
 
diff --git a/token.tokens.inc b/token.tokens.inc
index e77fe30..64c7d57 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -54,11 +54,11 @@ function token_token_info_alter(&$info) {
   $entities = \Drupal::entityManager()->getDefinitions();
   foreach ($entities as $entity => $entity_info) {
     /* @var \Drupal\Core\Entity\EntityType $entity_info */
-    if (!$entity_info->hasKey('token type')) {
+    if (!$entity_info->get('token type')) {
       continue;
     }
 
-    $token_type = $entity_info['token type'];
+    $token_type = $entity_info->get('token type');
     if (!isset($info['types'][$token_type]) || !isset($info['tokens'][$token_type])) {
       continue;
     }
-- 
1.9.3 (Apple Git-50)


From d2ce7d9b5bd40a8a7b1001d83f07f56bbe0ac383 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Sun, 16 Feb 2014 16:18:09 +1300
Subject: [PATCH 104/230] Issue #1962358 by grom358: Fixed TokenUnitTestCase

---
 lib/Drupal/token/Tests/TokenUnitTestCase.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/Drupal/token/Tests/TokenUnitTestCase.php b/lib/Drupal/token/Tests/TokenUnitTestCase.php
index 1d25b62..127b1be 100644
--- a/lib/Drupal/token/Tests/TokenUnitTestCase.php
+++ b/lib/Drupal/token/Tests/TokenUnitTestCase.php
@@ -10,7 +10,7 @@ namespace Drupal\token\Tests;
  * Token unit tests.
  */
 class TokenUnitTestCase extends TokenTestBase {
-  protected static $modules = array('path', 'token', 'token_test', 'file');
+  protected static $modules = array('path', 'token', 'token_test', 'file', 'node');
 
   public static function getInfo() {
     return array(
-- 
1.9.3 (Apple Git-50)


From 0f3392bd092e9067bacc17f25e96cb814bc48b53 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Mon, 17 Feb 2014 09:16:58 +1000
Subject: [PATCH 105/230] Issue #1962358 by grom358: Fixed TokenCommentTestCase

---
 lib/Drupal/token/Tests/TokenCommentTestCase.php | 17 ++++++++---------
 token.tokens.inc                                |  9 +++++----
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenCommentTestCase.php b/lib/Drupal/token/Tests/TokenCommentTestCase.php
index a97ac73..6c15ae0 100644
--- a/lib/Drupal/token/Tests/TokenCommentTestCase.php
+++ b/lib/Drupal/token/Tests/TokenCommentTestCase.php
@@ -10,6 +10,8 @@ namespace Drupal\token\Tests;
  * Tests comment tokens.
  */
 class TokenCommentTestCase extends TokenTestBase {
+  protected static $modules = array('path', 'token', 'token_test', 'node', 'comment');
+
   public static function getInfo() {
     return array(
       'name' => 'Comment token tests',
@@ -18,11 +20,6 @@ class TokenCommentTestCase extends TokenTestBase {
     );
   }
 
-  public function setUp($modules = array()) {
-    $modules[] = 'comment';
-    parent::setUp($modules);
-  }
-
   function testCommentTokens() {
     \Drupal::service('comment.manager')->addDefaultField('node', 'page');
     $node = $this->drupalCreateNode();
@@ -35,13 +32,14 @@ class TokenCommentTestCase extends TokenTestBase {
       'mail' => 'anonymous@example.com',
       'subject' => $this->randomName(),
       'body' => $this->randomName(),
-    ))->save();
+    ));
+    $parent_comment->save();
 
     $tokens = array(
       'url' => url('comment/' . $parent_comment->id(), array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
       'url:absolute' => url('comment/' . $parent_comment->id(), array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
       'url:relative' => url('comment/' . $parent_comment->id(), array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => FALSE)),
-      'url:path' => 'comment/' . $parent_comment->id(),
+      'url:path' => '/comment/' . $parent_comment->id(),
       'parent:url:absolute' => NULL,
     );
     $this->assertTokens('comment', array('comment' => $parent_comment), $tokens);
@@ -56,13 +54,14 @@ class TokenCommentTestCase extends TokenTestBase {
       'mail' => 'anonymous@example.com',
       'subject' => $this->randomName(),
       'body' => $this->randomName(),
-    ))->save();
+    ));
+    $comment->save();
 
     $tokens = array(
       'url' => url('comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id(), 'absolute' => TRUE)),
       'url:absolute' => url('comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id(), 'absolute' => TRUE)),
       'url:relative' => url('comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id(), 'absolute' => FALSE)),
-      'url:path' => 'comment/' . $comment->id(),
+      'url:path' => '/comment/' . $comment->id(),
       'parent:url:absolute' => url('comment/' . $parent_comment->id(), array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
     );
     $this->assertTokens('comment', array('comment' => $comment), $tokens);
diff --git a/token.tokens.inc b/token.tokens.inc
index 64c7d57..01b6d75 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -726,13 +726,14 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     if (isset($data['route_parameters'])) {
       $route_param = $data['route_parameters'];
     }
-    $options = isset($data['options']) ? $data['options'] : array();
-    $path = \Drupal::url($route, $route_param, $options);
-
+    $url_options = array();
     if (isset($data['options'])) {
       // Merge in the URL options if available.
       $url_options = $data['options'] + $url_options;
     }
+    $path_url_options = $url_options;
+    unset($path_url_options['fragment']);
+    $path = \Drupal::url($route, $route_param, $path_url_options);
 
     foreach ($tokens as $name => $original) {
       switch ($name) {
@@ -746,7 +747,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           $replacements[$original] = $sanitize ? String::checkPlain($alias) : $alias;
           break;
         case 'absolute':
-          $replacements[$original] = \Drupal::url($route, $route_param, $url_options);
+          $replacements[$original] = \Drupal::url($route, $route_param, array('absolute' => TRUE) + $url_options);
           break;
         case 'relative':
           $replacements[$original] = \Drupal::url($route, $route_param, array('absolute' => FALSE) + $url_options);
-- 
1.9.3 (Apple Git-50)


From 17656ce0511de4b19dffa7cd1bfc3cebfc75cde4 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Mon, 17 Feb 2014 09:47:07 +1000
Subject: [PATCH 106/230] Issue #1962358 by grom358: Removed leading / from
 path

---
 lib/Drupal/token/Tests/TokenCommentTestCase.php  |  4 ++--
 lib/Drupal/token/Tests/TokenNodeTestCase.php     | 12 ++++++------
 lib/Drupal/token/Tests/TokenTaxonomyTestCase.php | 12 ++++++------
 lib/Drupal/token/Tests/TokenURLTestCase.php      |  6 +++---
 token.tokens.inc                                 |  3 +++
 5 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenCommentTestCase.php b/lib/Drupal/token/Tests/TokenCommentTestCase.php
index 6c15ae0..8ee1e07 100644
--- a/lib/Drupal/token/Tests/TokenCommentTestCase.php
+++ b/lib/Drupal/token/Tests/TokenCommentTestCase.php
@@ -39,7 +39,7 @@ class TokenCommentTestCase extends TokenTestBase {
       'url' => url('comment/' . $parent_comment->id(), array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
       'url:absolute' => url('comment/' . $parent_comment->id(), array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
       'url:relative' => url('comment/' . $parent_comment->id(), array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => FALSE)),
-      'url:path' => '/comment/' . $parent_comment->id(),
+      'url:path' => 'comment/' . $parent_comment->id(),
       'parent:url:absolute' => NULL,
     );
     $this->assertTokens('comment', array('comment' => $parent_comment), $tokens);
@@ -61,7 +61,7 @@ class TokenCommentTestCase extends TokenTestBase {
       'url' => url('comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id(), 'absolute' => TRUE)),
       'url:absolute' => url('comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id(), 'absolute' => TRUE)),
       'url:relative' => url('comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id(), 'absolute' => FALSE)),
-      'url:path' => '/comment/' . $comment->id(),
+      'url:path' => 'comment/' . $comment->id(),
       'parent:url:absolute' => url('comment/' . $parent_comment->id(), array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
     );
     $this->assertTokens('comment', array('comment' => $comment), $tokens);
diff --git a/lib/Drupal/token/Tests/TokenNodeTestCase.php b/lib/Drupal/token/Tests/TokenNodeTestCase.php
index 68aea6f..1b14173 100644
--- a/lib/Drupal/token/Tests/TokenNodeTestCase.php
+++ b/lib/Drupal/token/Tests/TokenNodeTestCase.php
@@ -26,10 +26,10 @@ class TokenNodeTestCase extends TokenTestBase {
       'source' => NULL,
       'source:nid' => NULL,
       'log' => $source_node->log->value,
-      'url:path' => '/content/source-node',
+      'url:path' => 'content/source-node',
       'url:absolute' => url("node/{$source_node->id()}", array('absolute' => TRUE)),
       'url:relative' => url("node/{$source_node->id()}", array('absolute' => FALSE)),
-      'url:unaliased:path' => "/node/{$source_node->id()}",
+      'url:unaliased:path' => "node/{$source_node->id()}",
       'content-type' => 'Basic page',
       'content-type:name' => 'Basic page',
       'content-type:machine-name' => 'page',
@@ -39,7 +39,7 @@ class TokenNodeTestCase extends TokenTestBase {
       // Deprecated tokens.
       'type' => 'page',
       'type-name' => 'Basic page',
-      'url:alias' => '/content/source-node',
+      'url:alias' => 'content/source-node',
     );
     $this->assertTokens('node', array('node' => $source_node), $tokens);
 
@@ -48,10 +48,10 @@ class TokenNodeTestCase extends TokenTestBase {
       'source' => $source_node->label(),
       'source:nid' => $source_node->id(),
       'log' => '',
-      'url:path' => "/node/{$translated_node->id()}",
+      'url:path' => "node/{$translated_node->id()}",
       'url:absolute' => url("node/{$translated_node->id()}", array('absolute' => TRUE)),
       'url:relative' => url("node/{$translated_node->id()}", array('absolute' => FALSE)),
-      'url:unaliased:path' => "/node/{$translated_node->id()}",
+      'url:unaliased:path' => "node/{$translated_node->id()}",
       'content-type' => 'Article',
       'content-type:name' => 'Article',
       'content-type:machine-name' => 'article',
@@ -61,7 +61,7 @@ class TokenNodeTestCase extends TokenTestBase {
       // Deprecated tokens.
       'type' => 'article',
       'type-name' => 'Article',
-      'url:alias' => "/node/{$translated_node->id()}",
+      'url:alias' => "node/{$translated_node->id()}",
     );
     $this->assertTokens('node', array('node' => $translated_node), $tokens);
   }
diff --git a/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php b/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php
index ebcb70d..e597bf9 100644
--- a/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php
+++ b/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php
@@ -44,15 +44,15 @@ class TokenTaxonomyTestCase extends TokenTestBase {
       'url' => url("taxonomy/term/{$root_term->id()}", array('absolute' => TRUE)),
       'url:absolute' => url("taxonomy/term/{$root_term->id()}", array('absolute' => TRUE)),
       'url:relative' => url("taxonomy/term/{$root_term->id()}", array('absolute' => FALSE)),
-      'url:path' => '/root-term',
-      'url:unaliased:path' => "/taxonomy/term/{$root_term->id()}",
+      'url:path' => 'root-term',
+      'url:unaliased:path' => "taxonomy/term/{$root_term->id()}",
       'edit-url' => url("taxonomy/term/{$root_term->id()}/edit", array('absolute' => TRUE)),
       'parents' => NULL,
       'parents:count' => NULL,
       'parents:keys' => NULL,
       'root' => NULL,
       // Deprecated tokens
-      'url:alias' => '/root-term',
+      'url:alias' => 'root-term',
     );
     $this->assertTokens('term', array('term' => $root_term), $tokens);
 
@@ -61,8 +61,8 @@ class TokenTaxonomyTestCase extends TokenTestBase {
       'url' => url("taxonomy/term/{$parent_term->id()}", array('absolute' => TRUE)),
       'url:absolute' => url("taxonomy/term/{$parent_term->id()}", array('absolute' => TRUE)),
       'url:relative' => url("taxonomy/term/{$parent_term->id()}", array('absolute' => FALSE)),
-      'url:path' => "/taxonomy/term/{$parent_term->id()}",
-      'url:unaliased:path' => "/taxonomy/term/{$parent_term->id()}",
+      'url:path' => "taxonomy/term/{$parent_term->id()}",
+      'url:unaliased:path' => "taxonomy/term/{$parent_term->id()}",
       'edit-url' => url("taxonomy/term/{$parent_term->id()}/edit", array('absolute' => TRUE)),
       'parents' => 'Root term',
       'parents:count' => 1,
@@ -70,7 +70,7 @@ class TokenTaxonomyTestCase extends TokenTestBase {
       'root' => String::checkPlain($root_term->label()),
       'root:tid' => $root_term->id(),
       // Deprecated tokens
-      'url:alias' => "/taxonomy/term/{$parent_term->id()}",
+      'url:alias' => "taxonomy/term/{$parent_term->id()}",
     );
     $this->assertTokens('term', array('term' => $parent_term), $tokens);
 
diff --git a/lib/Drupal/token/Tests/TokenURLTestCase.php b/lib/Drupal/token/Tests/TokenURLTestCase.php
index c411ac7..91c5a2c 100644
--- a/lib/Drupal/token/Tests/TokenURLTestCase.php
+++ b/lib/Drupal/token/Tests/TokenURLTestCase.php
@@ -30,20 +30,20 @@ class TokenURLTestCase extends TokenTestBase {
     $tokens = array(
       'absolute' => "http://{$host}/first-node",
       'relative' => base_path() . 'first-node',
-      'path' => '/first-node',
+      'path' => 'first-node',
       'brief' => "{$host}/first-node",
       'args:value:0' => 'first-node',
       'args:value:1' => NULL,
       'args:value:N' => NULL,
       'unaliased' => "http://{$host}/node/1",
       'unaliased:relative' => base_path() . 'node/1',
-      'unaliased:path' => '/node/1',
+      'unaliased:path' => 'node/1',
       'unaliased:brief' => "{$host}/node/1",
       'unaliased:args:value:0' => 'node',
       'unaliased:args:value:1' => '1',
       'unaliased:args:value:2' => NULL,
       // Deprecated tokens.
-      'alias' => '/first-node',
+      'alias' => 'first-node',
     );
     $this->assertTokens('url', array('route_name' => 'node.view', 'route_parameters' => array('node' => 1)), $tokens);
   }
diff --git a/token.tokens.inc b/token.tokens.inc
index 01b6d75..3bda1e2 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -734,6 +734,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     $path_url_options = $url_options;
     unset($path_url_options['fragment']);
     $path = \Drupal::url($route, $route_param, $path_url_options);
+    $path = ltrim($path, '/');
 
     foreach ($tokens as $name => $original) {
       switch ($name) {
@@ -753,9 +754,11 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           $replacements[$original] = \Drupal::url($route, $route_param, array('absolute' => FALSE) + $url_options);
           break;
         case 'brief':
+          $url_options['absolute'] = TRUE;
           $replacements[$original] = preg_replace(array('!^https?://!', '!/$!'), '', \Drupal::url($route, $route_param, $url_options));
           break;
         case 'unaliased':
+          $url_options['absolute'] = TRUE;
           $replacements[$original] = \Drupal::url($route, $route_param, array('alias' => TRUE) + $url_options);
           break;
         case 'args':
-- 
1.9.3 (Apple Git-50)


From ec2893ef2349327af6e476513e294df43b64a048 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Mon, 17 Feb 2014 10:39:50 +1000
Subject: [PATCH 107/230] Issue #1962358 by larowlan: Fixes final test fails

---
 .../token/Tests/TokenCurrentPageTestCase.php       | 22 ++++---
 lib/Drupal/token/Tests/TokenMenuTestCase.php       | 65 ++++++++++++--------
 tests/token_test/token_test.module                 | 18 +-----
 token.module                                       | 48 +++------------
 token.tokens.inc                                   | 71 ++++++++++++----------
 5 files changed, 102 insertions(+), 122 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenCurrentPageTestCase.php b/lib/Drupal/token/Tests/TokenCurrentPageTestCase.php
index c872b37..d67478c 100644
--- a/lib/Drupal/token/Tests/TokenCurrentPageTestCase.php
+++ b/lib/Drupal/token/Tests/TokenCurrentPageTestCase.php
@@ -10,6 +10,9 @@ namespace Drupal\token\Tests;
  * Tests current page tokens.
  */
 class TokenCurrentPageTestCase extends TokenTestBase {
+
+  protected static $modules = array('path', 'token', 'token_test', 'node');
+
   public static function getInfo() {
     return array(
       'name' => 'Current page token tests',
@@ -19,21 +22,22 @@ class TokenCurrentPageTestCase extends TokenTestBase {
   }
 
   function testCurrentPageTokens() {
+    $this->drupalGet('user');
     $tokens = array(
-      '[current-page:title]' => t('Welcome to @site-name', array('@site-name' => \Drupal::config('system.site')->get('name'))),
-      '[current-page:url]' => url('node', array('absolute' => TRUE)),
-      '[current-page:url:absolute]' => url('node', array('absolute' => TRUE)),
-      '[current-page:url:relative]' => url('node', array('absolute' => FALSE)),
-      '[current-page:url:path]' => 'node',
-      '[current-page:url:args:value:0]' => 'node',
+      '[current-page:title]' => t('Log in'),
+      '[current-page:url]' => url('user', array('absolute' => TRUE)),
+      '[current-page:url:absolute]' => url('user', array('absolute' => TRUE)),
+      '[current-page:url:relative]' => url('user', array('absolute' => FALSE)),
+      '[current-page:url:path]' => 'user',
+      '[current-page:url:args:value:0]' => 'user',
       '[current-page:url:args:value:1]' => NULL,
-      '[current-page:url:unaliased]' => url('node', array('absolute' => TRUE, 'alias' => TRUE)),
+      '[current-page:url:unaliased]' => url('user', array('absolute' => TRUE, 'alias' => TRUE)),
       '[current-page:page-number]' => 1,
       '[current-page:query:foo]' => NULL,
       '[current-page:query:bar]' => NULL,
-      '[current-page:query:q]' => 'node',
+      '[current-page:query:q]' => 'user',
       // Deprecated tokens
-      '[current-page:arg:0]' => 'node',
+      '[current-page:arg:0]' => 'user',
       '[current-page:arg:1]' => NULL,
     );
     $this->assertPageTokens('', $tokens);
diff --git a/lib/Drupal/token/Tests/TokenMenuTestCase.php b/lib/Drupal/token/Tests/TokenMenuTestCase.php
index 12fe957..13882f5 100644
--- a/lib/Drupal/token/Tests/TokenMenuTestCase.php
+++ b/lib/Drupal/token/Tests/TokenMenuTestCase.php
@@ -10,7 +10,7 @@ namespace Drupal\token\Tests;
  * Tests menu tokens.
  */
 class TokenMenuTestCase extends TokenTestBase {
-  protected static $modules = array('path', 'token', 'token_test', 'menu');
+  protected static $modules = array('path', 'token', 'token_test', 'menu', 'node');
 
   public static function getInfo() {
     return array(
@@ -21,61 +21,78 @@ class TokenMenuTestCase extends TokenTestBase {
   }
 
   function testMenuTokens() {
+    // Add a menu.
+    $menu = entity_create('menu', array(
+      'id' => 'main-menu',
+      'label' => 'Main menu',
+      'description' => 'The <em>Main</em> menu is used on many sites to show the major sections of the site, often in a top navigation bar.',
+    ));
+    $menu->save();
     // Add a root link.
     $root_link = entity_create('menu_link', array(
-      'link_path' => 'root',
-      'link_title' => 'Root link',
+      'link_path' => 'admin',
+      'link_title' => 'Administration',
       'menu_name' => 'main-menu',
-    ))->save();
+    ));
+    $root_link->save();
 
     // Add another link with the root link as the parent
     $parent_link = entity_create('menu_link', array(
-      'link_path' => 'root/parent',
-      'link_title' => 'Parent link',
+      'link_path' => 'admin/config',
+      'link_title' => 'Configuration',
       'menu_name' => 'main-menu',
       'plid' => $root_link['mlid'],
-    ))->save();
+    ));
+    $parent_link->save();
 
     // Test menu link tokens.
     $tokens = array(
       'mlid' => $parent_link['mlid'],
-      'title' => 'Parent link',
+      'title' => 'Configuration',
       'menu' => 'Main menu',
       'menu:name' => 'Main menu',
       'menu:machine-name' => 'main-menu',
       'menu:description' => 'The <em>Main</em> menu is used on many sites to show the major sections of the site, often in a top navigation bar.',
       'menu:menu-link-count' => 2,
       'menu:edit-url' => url("admin/structure/menu/manage/main-menu", array('absolute' => TRUE)),
-      'url' => url('root/parent', array('absolute' => TRUE)),
-      'url:absolute' => url('root/parent', array('absolute' => TRUE)),
-      'url:relative' => url('root/parent', array('absolute' => FALSE)),
-      'url:path' => 'root/parent',
-      'url:alias' => 'root/parent',
+      'url' => url('admin/config', array('absolute' => TRUE)),
+      'url:absolute' => url('admin/config', array('absolute' => TRUE)),
+      'url:relative' => url('admin/config', array('absolute' => FALSE)),
+      'url:path' => 'admin/config',
+      'url:alias' => 'admin/config',
       'edit-url' => url("admin/structure/menu/item/{$parent_link['mlid']}/edit", array('absolute' => TRUE)),
-      'parent' => 'Root link',
+      'parent' => 'Administration',
       'parent:mlid' => $root_link['mlid'],
-      'parent:title' => 'Root link',
+      'parent:title' => 'Administration',
       'parent:menu' => 'Main menu',
       'parent:parent' => NULL,
-      'parents' => 'Root link',
+      'parents' => 'Administration',
       'parents:count' => 1,
       'parents:keys' => $root_link['mlid'],
-      'root' => 'Root link',
+      'root' => 'Administration',
       'root:mlid' => $root_link['mlid'],
       'root:parent' => NULL,
       'root:root' => NULL,
     );
     $this->assertTokens('menu-link', array('menu-link' => $parent_link), $tokens);
 
+    // Add a node.
+    $node = $this->drupalCreateNode();
+
+    // Allow main menu for this node type.
+    \Drupal::config('menu.entity.node.' . $node->getType())->set('available_menus', array('main-menu'))->save();
+
     // Add a node menu link
-    $node_link = array(
+    $node_link = entity_create('menu_link', array(
       'enabled' => TRUE,
+      'link_path' => 'node/' . $node->id(),
       'link_title' => 'Node link',
       'plid' => $parent_link['mlid'],
       'customized' => 0,
+      'menu_name' => 'main-menu',
       'description' => '',
-    );
-    $node = $this->drupalCreateNode(array('menu' => $node_link));
+    ));
+    $node_link->save();
 
     // Test [node:menu] tokens.
     $tokens = array(
@@ -85,14 +102,14 @@ class TokenMenuTestCase extends TokenTestBase {
       'menu-link:menu' => 'Main menu',
       'menu-link:url' => url('node/' . $node->id(), array('absolute' => TRUE)),
       'menu-link:url:path' => 'node/' . $node->id(),
-      'menu-link:edit-url' => url("admin/structure/menu/item/{$node->menu['mlid']}/edit", array('absolute' => TRUE)),
-      'menu-link:parent' => 'Parent link',
+      'menu-link:edit-url' => url("admin/structure/menu/item/{$node_link->id()}/edit", array('absolute' => TRUE)),
+      'menu-link:parent' => 'Configuration',
       'menu-link:parent:mlid' => $node->menu['plid'],
       'menu-link:parent:mlid' => $parent_link['mlid'],
-      'menu-link:parents' => 'Root link, Parent link',
+      'menu-link:parents' => 'Administration, Configuration',
       'menu-link:parents:count' => 2,
       'menu-link:parents:keys' => $root_link['mlid'] . ', ' . $parent_link['mlid'],
-      'menu-link:root' => 'Root link',
+      'menu-link:root' => 'Administration',
       'menu-link:root:mlid' => $root_link['mlid'],
     );
     $this->assertTokens('node', array('node' => $node), $tokens);
diff --git a/tests/token_test/token_test.module b/tests/token_test/token_test.module
index 8af0b8d..5736b8d 100644
--- a/tests/token_test/token_test.module
+++ b/tests/token_test/token_test.module
@@ -6,9 +6,9 @@
  */
 
 /**
- * Implements hook_exit().
+ * Implements hook_page_alter().
  */
-function token_test_exit() {
+function token_test_page_alter() {
   if ($debug = \Drupal::state()->get('token_page_tokens', array())) {
     $debug += array('tokens' => array(), 'data' => array(), 'options' => array());
     foreach (array_keys($debug['tokens']) as $token) {
@@ -17,17 +17,3 @@ function token_test_exit() {
     \Drupal::state()->set('token_page_tokens', $debug);
   }
 }
-
-/**
- * Implements hook_date_format_types().
- *
- * @todo Remove when http://drupal.org/node/1173706 is fixed.
- */
-function token_test_date_format_types() {
-  $info['token_test'] = t('Token test date format');
-
-  // Explicitly set the variable here as well.
-  \Drupal::state()->set('date_format_token_test', 'Y');
-
-  return $info;
-}
diff --git a/token.module b/token.module
index 848a8ff..6bc9698 100644
--- a/token.module
+++ b/token.module
@@ -207,7 +207,8 @@ function token_form_alter(&$form, $form_state, $form_id) {
  * Implements hook_block_view_alter().
  */
 function token_block_view_alter(&$data, \Drupal\block\BlockPluginInterface $block) {
-  $label = $block->getConfiguration()['label'];
+  $config = $block->getConfiguration();
+  $label = $config['label'];
   if ($label != '<none>') {
     //$block->setConfigurationValue('label', \Drupal::token()->replace($label, array(), array('sanitize' => TRUE)));
     $data['#configuration']['label'] = \Drupal::token()->replace($label, array(), array('sanitize' => TRUE));
@@ -949,40 +950,6 @@ function _token_build_tree($token_type, array $options) {
 }
 
 /**
- * Get a translated menu link by its mlid, without access checking.
- *
- * This function is a copy of menu_link_load() but with its own cache and a
- * simpler query to load the link. This also skips normal menu link access
- * checking by using _token_menu_link_translate().
- *
- * @param $mlid
- *   The mlid of the menu item.
- *
- * @return
- *   A menu link translated for rendering.
- *
- * @see menu_link_load()
- * @see _token_menu_link_translate()
- */
-function token_menu_link_load($mlid) {
-  $cache = &drupal_static(__FUNCTION__, array());
-
-  if (!is_numeric($mlid)) {
-    return FALSE;
-  }
-
-  if (!isset($cache[$mlid])) {
-    $item = db_query("SELECT * FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path WHERE ml.mlid = :mlid", array(':mlid' => $mlid))->fetchAssoc();
-    if (!empty($item)) {
-      _token_menu_link_translate($item);
-    }
-    $cache[$mlid] = $item;
-  }
-
-  return $cache[$mlid];
-}
-
-/**
  * Get a translated book menu link by its mlid, without access checking.
  *
  * This function is a copy of book_link_load() but with its own cache and a
@@ -1155,7 +1122,7 @@ function token_menu_link_load_all_parents($mlid) {
   if (!isset($cache[$mlid])) {
     $cache[$mlid] = array();
     $plid = db_query("SELECT plid FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $mlid))->fetchField();
-    while ($plid && $parent = token_menu_link_load($plid)) {
+    while ($plid && $parent = menu_link_load($plid)) {
       $cache[$mlid] = array($plid => $parent['title']) + $cache[$mlid];
       $plid = $parent['plid'];
     }
@@ -1200,7 +1167,7 @@ function token_taxonomy_term_load_all_parents($tid) {
 function token_node_menu_link_load($node) {
   $cache = &drupal_static(__FUNCTION__, array());
 
-  if (!isset($cache[$node->nid])) {
+  if (!isset($cache[$node->id()])) {
     $mlid = FALSE;
 
     // Nodes do not have their menu links loaded via menu_node_load().
@@ -1208,17 +1175,18 @@ function token_node_menu_link_load($node) {
       // We need to clone the node as menu_node_prepare() may cause data loss.
       // @see http://drupal.org/node/1317926
       $menu_node = clone $node;
-      menu_node_prepare($menu_node);
+      $form_state = array();
+      menu_node_prepare_form($menu_node, NULL, NULL, $form_state);
       $mlid = !empty($menu_node->menu['mlid']) ? $menu_node->menu['mlid'] : FALSE;
     }
     else {
       $mlid = !empty($node->menu['mlid']) ? $node->menu['mlid'] : FALSE;
     }
 
-    $cache[$node->nid] = $mlid;
+    $cache[$node->id()] = $mlid;
   }
 
-  return $cache[$node->nid] ? token_menu_link_load($cache[$node->nid]) : FALSE;
+  return $cache[$node->id()] ? menu_link_load($cache[$node->id()]) : FALSE;
 }
 
 function token_element_children(&$elements, $sort = FALSE) {
diff --git a/token.tokens.inc b/token.tokens.inc
index 3bda1e2..dc8f3dc 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -612,58 +612,54 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
   // Menu link tokens.
   if ($type == 'menu-link' && !empty($data['menu-link'])) {
-    $link = (array) $data['menu-link'];
-
-    if (!isset($link['title'])) {
-      // Re-load the link if it was not loaded via token_menu_link_load().
-      $link = token_menu_link_load($link['mlid']);
-    }
+    $link = $data['menu-link'];
 
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'mlid':
-          $replacements[$original] = $link['mlid'];
+          $replacements[$original] = $link->id();
           break;
         case 'title':
-          $replacements[$original] = $sanitize ? String::checkPlain($link['title']) : $link['title'];
+          $replacements[$original] = $sanitize ? String::checkPlain($link->label()) : $link->label();
           break;
         case 'url':
-          $replacements[$original] = url($link['href'], $url_options);
+          $replacements[$original] = \Drupal::url($link->route_name, $link->route_parameters, !empty($link->localized_options) ? $link->localized_options : array('absolute' => TRUE));
           break;
         case 'parent':
-          if (!empty($link['plid']) && $parent = token_menu_link_load($link['plid'])) {
-            $replacements[$original] = $sanitize ? String::checkPlain($parent['title']) : $parent['title'];
+          if (!empty($link->plid) && $parent = menu_link_load($link->plid)) {
+            $replacements[$original] = $sanitize ? String::checkPlain($parent->label()) : $parent->label();
           }
           break;
         case 'parents':
-          if ($parents = token_menu_link_load_all_parents($link['mlid'])) {
+          if ($parents = token_menu_link_load_all_parents($link->id())) {
             $replacements[$original] = token_render_array($parents, $options);
           }
           break;
         case 'root';
-          if (!empty($link['p1']) && $link['p1'] != $link['mlid'] && $root = token_menu_link_load($link['p1'])) {
-            $replacements[$original] = $sanitize ? String::checkPlain($root['title']) : $root['title'];
+          if (!empty($link->p1) && $link->p1 != $link->id() && $root = menu_link_load($link->p1)) {
+            $replacements[$original] = $sanitize ? String::checkPlain($root->label()) : $root->label();
           }
           break;
       }
     }
 
     // Chained token relationships.
-    if (!empty($link['plid']) && ($source_tokens = \Drupal::token()->findWithPrefix($tokens, 'parent')) && $parent = token_menu_link_load($link['plid'])) {
+    if (!empty($link->plid) && ($source_tokens = \Drupal::token()->findWithPrefix($tokens, 'parent')) && $parent = menu_link_load($link->plid)) {
       $replacements += \Drupal::token()->generate('menu-link', $source_tokens, array('menu-link' => $parent), $options);
     }
     // [menu-link:parents:*] chained tokens.
     if ($parents_tokens = \Drupal::token()->findWithPrefix($tokens, 'parents')) {
-      if ($parents = token_menu_link_load_all_parents($link['mlid'])) {
+      if ($parents = token_menu_link_load_all_parents($link->id())) {
         $replacements += \Drupal::token()->generate('array', $parents_tokens, array('array' => $parents), $options);
       }
     }
-    if (!empty($link['p1']) && $link['p1'] != $link['mlid'] && ($root_tokens = \Drupal::token()->findWithPrefix($tokens, 'root')) && $root = token_menu_link_load($link['p1'])) {
+    if (!empty($link->p1) && $link->p1 != $link->id() && ($root_tokens = \Drupal::token()->findWithPrefix($tokens, 'root')) && $root = menu_link_load($link->p1)) {
       $replacements += \Drupal::token()->generate('menu-link', $root_tokens, array('menu-link' => $root), $options);
     }
     if ($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, array('path' => $link['href']), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, array('route_name' => $link->route_name, 'route_parameters' => $link->route_parameters), $options);
     }
+
   }
 
   // Current page tokens.
@@ -682,7 +678,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           $replacements[$original] = url($current_path, $url_options);
           break;
         case 'page-number':
-          if ($page = filter_input(INPUT_GET, 'page')) {
+          if ($page = \Drupal::request()->query->get('page')) {
             // @see PagerDefault::execute()
             $pager_page_array = explode(',', $page);
             $page = $pager_page_array[0];
@@ -695,8 +691,11 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     // @deprecated
     // [current-page:arg] dynamic tokens.
     if ($arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'arg')) {
+      $path = \Drupal::request()->attributes->get('_system_path');
+      // Make sure its a system path.
+      $path = \Drupal::service('path.alias_manager')->getSystemPath($path);
       foreach ($arg_tokens as $name => $original) {
-        if (is_numeric($name) && ($arg = arg($name)) && isset($arg)) {
+        if (is_numeric($name) && ($arg = arg($name, $path)) && isset($arg)) {
           $replacements[$original] = $sanitize ? String::checkPlain($arg) : $arg;
         }
       }
@@ -710,12 +709,18 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           $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')) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, array('path' => $current_path), $options);
+      $request = \Drupal::request();
+      $url_data['route_name'] = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT);
+      $url_data['route_parameters'] = $request->attributes->get('_raw_variables')->all();
+      $replacements += \Drupal::token()->generate('url', $url_tokens, $url_data, $options);
     }
   }
 
@@ -1117,7 +1122,7 @@ function menu_tokens($type, $tokens, array $data = array(), array $options = arr
       switch ($name) {
         case 'menu-link':
           if ($link = token_node_menu_link_load($node)) {
-            $replacements[$original] = $sanitize ? String::checkPlain($link['title']) : $link['title'];
+            $replacements[$original] = $sanitize ? String::checkPlain($link->label()) : $link->label();
           }
           break;
       }
@@ -1133,52 +1138,52 @@ function menu_tokens($type, $tokens, array $data = array(), array $options = arr
 
   // Menu link tokens.
   if ($type == 'menu-link' && !empty($data['menu-link'])) {
-    $link = (array) $data['menu-link'];
+    $link = $data['menu-link'];
 
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'menu':
-          if ($menu = menu_load($link['menu_name'])) {
-            $replacements[$original] = $sanitize ? String::checkPlain($menu['title']) : $menu['title'];
+          if ($menu = menu_load($link->bundle())) {
+            $replacements[$original] = $sanitize ? String::checkPlain($menu->label()) : $menu->label();
           }
           break;
         case 'edit-url':
-          $replacements[$original] = url("admin/structure/menu/item/{$link['mlid']}/edit", $url_options);
+          $replacements[$original] = url("admin/structure/menu/item/{$link->id()}/edit", $url_options);
           break;
       }
     }
 
     // Chained token relationships.
-    if (($menu_tokens = \Drupal::token()->findWithPrefix($tokens, 'menu')) && $menu = menu_load($link['menu_name'])) {
+    if (($menu_tokens = \Drupal::token()->findWithPrefix($tokens, 'menu')) && $menu = menu_load($link->bundle())) {
       $replacements += \Drupal::token()->generate('menu', $menu_tokens, array('menu' => $menu), $options);
     }
   }
 
   // Menu tokens.
   if ($type == 'menu' && !empty($data['menu'])) {
-    $menu = (array) $data['menu'];
+    $menu = $data['menu'];
 
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'name':
-          $replacements[$original] = $sanitize ? String::checkPlain($menu['title']) : $menu['title'];
+          $replacements[$original] = $sanitize ? String::checkPlain($menu->label()) : $menu->label();
           break;
         case 'machine-name':
           // This is a machine name so does not ever need to be sanitized.
-          $replacements[$original] = $menu['menu_name'];
+          $replacements[$original] = $menu->id();
           break;
         case 'description':
-          $replacements[$original] = $sanitize ? filter_xss($menu['description']) : $menu['description'];
+          $replacements[$original] = $sanitize ? filter_xss($menu->description) : $menu->description;
           break;
         case 'menu-link-count':
           $query = db_select('menu_links');
-          $query->condition('menu_name', $menu['menu_name']);
+          $query->condition('menu_name', $menu->id());
           $query->addTag('menu_menu_link_count');
           $count = $query->countQuery()->execute()->fetchField();
           $replacements[$original] = (int) $count;
           break;
         case 'edit-url':
-          $replacements[$original] = url("admin/structure/menu/manage/" . $menu['menu_name'], $url_options);
+          $replacements[$original] = url("admin/structure/menu/manage/" . $menu->id(), $url_options);
           break;
       }
     }
-- 
1.9.3 (Apple Git-50)


From f9fc6dc660dd5b9c62020183d0df64277c503cb9 Mon Sep 17 00:00:00 2001
From: Cameron Zemek <cameron.zemek@previousnext.com.au>
Date: Tue, 18 Feb 2014 09:43:44 +1000
Subject: [PATCH 108/230] Issue #1962358 by grom358: Removed unneeded
 parentheses

---
 token.tokens.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index dc8f3dc..3ecd7bb 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -792,7 +792,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
   }
 
   // Entity tokens.
-  if (!empty($data[$type]) && ($entity_type = token_get_entity_mapping('token', $type))) {
+  if (!empty($data[$type]) && $entity_type = token_get_entity_mapping('token', $type)) {
     /* @var \Drupal\Core\Entity\EntityInterface $entity */
     $entity = $data[$type];
 
-- 
1.9.3 (Apple Git-50)


From da13188685a2a263ee9175714800fa466ad3e1ae Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Tue, 25 Feb 2014 18:46:20 +0100
Subject: [PATCH 109/230] Issue #1962358 by penyaskito: Changed
 hook_entity_info_alter to hook_entity_type_alter. See
 https://drupal.org/node/2196275

---
 token.module | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/token.module b/token.module
index 6bc9698..c136220 100644
--- a/token.module
+++ b/token.module
@@ -359,7 +359,7 @@ function token_get_entity_mapping($value_type = 'token', $value = NULL) {
 }
 
 /**
- * Implements hook_entity_info_alter().
+ * Implements hook_entity_type_alter().
  *
  * Because some token types to do not match their entity type names, we have to
  * map them to the proper type. This is purely for other modules' benefit.
@@ -367,9 +367,10 @@ function token_get_entity_mapping($value_type = 'token', $value = NULL) {
  * @see token_get_entity_mapping()
  * @see http://drupal.org/node/737726
  */
-function token_entity_info_alter(&$info) {
-  foreach (array_keys($info) as $entity_type) {
-    if ($info[$entity_type]->get('token type')) {
+function token_entity_type_alter(array &$entity_types) {
+  /* @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
+  foreach (array_keys($entity_types) as $entity_type) {
+    if ($entity_types[$entity_type]->get('token type')) {
       // If the entity's token type is already defined, great!
       continue;
     }
@@ -379,12 +380,12 @@ function token_entity_info_alter(&$info) {
       case 'taxonomy_term':
       case 'taxonomy_vocabulary':
         // Stupid taxonomy token types...
-        $info[$entity_type]->set('token type', str_replace('taxonomy_', '', $entity_type));
+        $entity_types[$entity_type]->set('token type', str_replace('taxonomy_', '', $entity_type));
         break;
 
       default:
         // By default the token type is the same as the entity type.
-        $info[$entity_type]->set('token type', $entity_type);
+        $entity_types[$entity_type]->set('token type', $entity_type);
         break;
     }
   }
-- 
1.9.3 (Apple Git-50)


From 7fe76601770255161cd75f16e3f6ea9be89d6ced Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Tue, 25 Feb 2014 18:51:08 +0100
Subject: [PATCH 110/230] Issue #1962358 by penyaskito: Changed theme() calls
 to _theme(), for making tests green before converting to render arrays. See
 https://drupal.org/node/2195739

---
 lib/Drupal/token/Tests/TokenUserTestCase.php | 3 ++-
 token.install                                | 3 ++-
 token.module                                 | 3 ++-
 token.pages.inc                              | 3 ++-
 token.tokens.inc                             | 3 ++-
 5 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenUserTestCase.php b/lib/Drupal/token/Tests/TokenUserTestCase.php
index c2013af..fae58d1 100644
--- a/lib/Drupal/token/Tests/TokenUserTestCase.php
+++ b/lib/Drupal/token/Tests/TokenUserTestCase.php
@@ -52,7 +52,8 @@ class TokenUserTestCase extends TokenTestBase {
     $this->assertTrue(!empty($this->account->user_picture->target_id), 'User picture uploaded.');
 
     $user_tokens = array(
-      'picture' => theme('user_picture', array('account' => $this->account)),
+      // ToDo: Use render arrays. See https://drupal.org/node/2195739
+      'picture' => _theme('user_picture', array('account' => $this->account)),
       'picture:fid' => $this->account->user_picture->target_id,
       'picture:size-raw' => 125,
       'ip-address' => NULL,
diff --git a/token.install b/token.install
index 5b0286f..21c907c 100644
--- a/token.install
+++ b/token.install
@@ -19,7 +19,8 @@ function token_requirements($phase = 'runtime') {
       if (!empty($problem['problems'])) {
         $problems = array_unique($problem['problems']);
         $problems = array_map('check_plain', $problems);
-        $token_problems[$problem_key] = $problem['label'] . theme('item_list', array('items' => $problems));
+        // ToDo: Use render arrays. See https://drupal.org/node/2195739
+        $token_problems[$problem_key] = $problem['label'] . _theme('item_list', array('items' => $problems));
       }
       else {
         unset($token_problems[$problem_key]);
diff --git a/token.module b/token.module
index c136220..6d5b015 100644
--- a/token.module
+++ b/token.module
@@ -25,7 +25,8 @@ function token_help($path, $arg) {
     }
     $output = '<dl>';
     $output .= '<dt>' . t('List of the currently available tokens on this site') . '</dt>';
-    $output .= '<dd>' . theme('token_tree', array('token_types' => 'all', 'click_insert' => FALSE, 'show_restricted' => TRUE)) . '</dd>';
+    // ToDo: Use render arrays. See https://drupal.org/node/2195739
+    $output .= '<dd>' . _theme('token_tree', array('token_types' => 'all', 'click_insert' => FALSE, 'show_restricted' => TRUE)) . '</dd>';
     $output .= '</dl>';
     return $output;
   }
diff --git a/token.pages.inc b/token.pages.inc
index ef47d03..e5ed6f0 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -23,7 +23,8 @@ function theme_tree_table($variables) {
     drupal_add_library('token', 'treeTable');
   }
 
-  return theme('table', $variables);
+  // ToDo: Use render arrays. See https://drupal.org/node/2195739
+  return _theme('table', $variables);
 }
 
 /**
diff --git a/token.tokens.inc b/token.tokens.inc
index 3ecd7bb..97f8e5e 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -575,7 +575,8 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'picture':
-          $replacements[$original] = theme('user_picture', array('account' => $account));
+          // ToDo: Use render arrays. See https://drupal.org/node/2195739
+          $replacements[$original] = _theme('user_picture', array('account' => $account));
           break;
 
         case 'roles':
-- 
1.9.3 (Apple Git-50)


From 9f996c7e7dfd70673920bb0b2177cb28ad14d80f Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Tue, 25 Feb 2014 23:41:27 +0100
Subject: [PATCH 111/230] Issue #1962358 by penyaskito: token_info() was
 changed to a service. See https://drupal.org/node/1973488

---
 token.install | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.install b/token.install
index 21c907c..65353e0 100644
--- a/token.install
+++ b/token.install
@@ -248,7 +248,7 @@ function token_get_token_problems() {
   //  }
   //}
 
-  $token_info = token_info();
+  $token_info = \Drupal::token()->getInfo();
   $token_problems = array(
     'not-array' => array(
       'label' => t('The following tokens or token types are not defined as arrays:'),
-- 
1.9.3 (Apple Git-50)


From eefee116555d726f6d34fb204f84f8beb6bc8657 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Wed, 26 Feb 2014 00:52:16 +0100
Subject: [PATCH 112/230] Issue #1962358 by penyaskito: Convert
 token/autocomplete to a controller.

---
 .../Controller/TokenAutocompleteController.php     | 76 ++++++++++++++++++++++
 token.module                                       |  8 +--
 token.pages.inc                                    | 30 ---------
 token.routing.yml                                  | 60 +++++++++++++++++
 4 files changed, 137 insertions(+), 37 deletions(-)
 create mode 100644 lib/Drupal/token/Controller/TokenAutocompleteController.php
 create mode 100644 token.routing.yml

diff --git a/lib/Drupal/token/Controller/TokenAutocompleteController.php b/lib/Drupal/token/Controller/TokenAutocompleteController.php
new file mode 100644
index 0000000..4af2ee0
--- /dev/null
+++ b/lib/Drupal/token/Controller/TokenAutocompleteController.php
@@ -0,0 +1,76 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Controller\TokenAutocompleteController.
+ */
+
+namespace Drupal\token\Controller;
+
+use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\HttpFoundation\JsonResponse;
+use Symfony\Component\HttpFoundation\Request;
+
+/**
+ * Returns autocomplete responses for tokens.
+ */
+class TokenAutocompleteController implements ContainerInjectionInterface {
+
+  /**
+   * Constructs a new TokenAutocompleteController.
+   */
+  public function __construct() {
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container) {
+    return new static(
+
+    );
+  }
+
+  /**
+   * Retrieves suggestions for block category autocompletion.
+   *
+   * @param \Symfony\Component\HttpFoundation\Request $request
+   *   The current request.
+   * @param string $token_type
+   *   The token type.
+   * @param string $filter
+   *   The autocomplete filter.
+   *
+   * @return \Symfony\Component\HttpFoundation\JsonResponse
+   *   A JSON response containing autocomplete suggestions.
+   */
+  public function autocomplete($token_type, $filter, Request $request) {
+    $filter = substr($filter, strrpos($filter, '['));
+
+    $matches = array();
+
+    if (!drupal_strlen($filter)) {
+      $matches["[{$token_type}:"] = 0;
+    }
+    else {
+      $depth = max(1, substr_count($filter, ':'));
+      $tree = token_build_tree($token_type, array('flat' => TRUE, 'depth' => $depth));
+      foreach (array_keys($tree) as $token) {
+        if (strpos($token, $filter) === 0) {
+          $matches[$token] = levenshtein($token, $filter);
+          if (isset($tree[$token]['children'])) {
+            $token = rtrim($token, ':]') . ':';
+            $matches[$token] = levenshtein($token, $filter);
+          }
+        }
+      }
+    }
+
+    asort($matches);
+    $matches = drupal_map_assoc(array_keys($matches));
+
+    return new JsonResponse($matches);
+  }
+
+}
\ No newline at end of file
diff --git a/token.module b/token.module
index 6d5b015..65802ac 100644
--- a/token.module
+++ b/token.module
@@ -61,13 +61,7 @@ function token_menu() {
     'type' => MENU_CALLBACK,
     'file' => 'token.pages.inc',
   );*/
-  $items['token/autocomplete/%token_type'] = array(
-    'page callback' => 'token_autocomplete_token',
-    'page arguments' => array(2),
-    'access callback' => TRUE,
-    'type' => MENU_CALLBACK,
-    'file' => 'token.pages.inc',
-  );
+
   /*$items['token/autocomplete/%token_type/%menu_tail'] = array(
     'page callback' => 'token_autocomplete_token',
     'page arguments' => array(2, 3),
diff --git a/token.pages.inc b/token.pages.inc
index e5ed6f0..5d4c94f 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -269,33 +269,3 @@ function token_autocomplete_type($string = '') {
   drupal_json_output($matches);
 }
 
-function token_autocomplete_token($token_type) {
-  $args = func_get_args();
-  array_shift($args);
-  $string = trim(implode('/', $args));
-  $string = substr($string, strrpos($string, '['));
-
-  $token_type = $token_type['type'];
-  $matches = array();
-
-  if (!drupal_strlen($string)) {
-    $matches["[{$token_type}:"] = 0;
-  }
-  else {
-    $depth = max(1, substr_count($string, ':'));
-    $tree = token_build_tree($token_type, array('flat' => TRUE, 'depth' => $depth));
-    foreach (array_keys($tree) as $token) {
-      if (strpos($token, $string) === 0) {
-        $matches[$token] = levenshtein($token, $string);
-        if (isset($tree[$token]['children'])) {
-          $token = rtrim($token, ':]') . ':';
-          $matches[$token] = levenshtein($token, $string);
-        }
-      }
-    }
-  }
-
-  asort($matches);
-  $matches = drupal_map_assoc(array_keys($matches));
-  drupal_json_output($matches);
-}
diff --git a/token.routing.yml b/token.routing.yml
new file mode 100644
index 0000000..57bee0c
--- /dev/null
+++ b/token.routing.yml
@@ -0,0 +1,60 @@
+token.autocomplete:
+  path: /token/autocomplete/{token_type}/{filter}
+  defaults:
+    _controller: '\Drupal\token\Controller\TokenAutocompleteController::autocomplete'
+  requirements:
+    _access: 'TRUE'
+
+#
+#  $items['token/autocomplete/%token_type'] = array(
+#    'page callback' => 'token_autocomplete_token',
+#    'page arguments' => array(2),
+#    'access callback' => TRUE,
+#    'type' => MENU_CALLBACK,
+#    'file' => 'token.pages.inc',
+#  );
+#    $items['token/flush-cache'] = array(
+#      'page callback' => 'token_flush_cache_callback',
+#      'access arguments' => array('flush caches'),
+#      'type' => MENU_CALLBACK,
+#      'file' => 'token.pages.inc',
+#    );
+#
+#  if (\Drupal::moduleHandler()->moduleExists('devel')) {
+#    $items['node/%node/devel/token'] = array(
+#      'title' => 'Tokens',
+#      'page callback' => 'token_devel_token_object',
+#      'page arguments' => array('node', 1),
+#      'access arguments' => array('access devel information'),
+#      'type' => MENU_LOCAL_TASK,
+#      'file' => 'token.pages.inc',
+#      'weight' => 5,
+#    );
+#    $items['comment/%comment/devel/token'] = array(
+#      'title' => 'Tokens',
+#      'page callback' => 'token_devel_token_object',
+#      'page arguments' => array('comment', 1),
+#      'access arguments' => array('access devel information'),
+#      'type' => MENU_LOCAL_TASK,
+#      'file' => 'token.pages.inc',
+#      'weight' => 5,
+#    );
+#    $items['taxonomy/term/%taxonomy_term/devel/token'] = array(
+#      'title' => 'Tokens',
+#      'page callback' => 'token_devel_token_object',
+#      'page arguments' => array('taxonomy_term', 2),
+#      'access arguments' => array('access devel information'),
+#      'type' => MENU_LOCAL_TASK,
+#      'file' => 'token.pages.inc',
+#      'weight' => 5,
+#    );
+#    $items['user/%user/devel/token'] = array(
+#      'title' => 'Tokens',
+#      'page callback' => 'token_devel_token_object',
+#      'page arguments' => array('user', 1),
+#      'access arguments' => array('access devel information'),
+#      'type' => MENU_LOCAL_TASK,
+#      'file' => 'token.pages.inc',
+#      'weight' => 5,
+#    );
+#  }
-- 
1.9.3 (Apple Git-50)


From c1c84773ca0b85b31b95e9f5f002f62a9377a328 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Wed, 26 Feb 2014 01:31:55 +0100
Subject: [PATCH 113/230] Issue #1962358 by penyaskito: Convert
 token/flush-cache to a controller.

---
 .../token/Controller/TokenCacheController.php      | 50 ++++++++++++++++++++++
 token.pages.inc                                    | 13 ------
 token.routing.yml                                  | 23 +++-------
 3 files changed, 57 insertions(+), 29 deletions(-)
 create mode 100644 lib/Drupal/token/Controller/TokenCacheController.php

diff --git a/lib/Drupal/token/Controller/TokenCacheController.php b/lib/Drupal/token/Controller/TokenCacheController.php
new file mode 100644
index 0000000..c101928
--- /dev/null
+++ b/lib/Drupal/token/Controller/TokenCacheController.php
@@ -0,0 +1,50 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Controller\TokenCacheController.
+ */
+
+namespace Drupal\token\Controller;
+
+use Symfony\Cmf\Component\Routing\RouteObjectInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\HttpFoundation\Request;
+
+/**
+ * Clears cache for tokens.
+ */
+class TokenCacheController implements ContainerInjectionInterface{
+
+  /**
+   * @var \Drupal\Core\Access\CsrfTokenGenerator
+   */
+  private $csrfToken;
+
+  /**
+   * Constructs a new TokenAutocompleteController.
+   */
+  public function __construct($csrf_token) {
+    $this->csrfToken = $csrf_token;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container) {
+    return new static(
+      $container->get('csrf_token')
+    );
+  }
+
+  public function flush(Request $request) {
+    if (!$request->query->has('token') || ! $this->csrfToken->validate($request->query->get('token'), current_path())) {
+      return MENU_NOT_FOUND;
+    }
+
+    token_clear_cache();
+    drupal_set_message(t('Token registry caches cleared.'));
+    return $this->redirect($request->attributes->get(RouteObjectInterface::ROUTE_NAME), $request->attributes->get('_raw_variables', array()));
+  }
+
+}
diff --git a/token.pages.inc b/token.pages.inc
index 5d4c94f..027a476 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -212,19 +212,6 @@ function token_devel_token_object($entity_type, $entity) {
   return $build;
 }
 
-/**
- * Page callback to clear the token registry caches.
- */
-function token_flush_cache_callback() {
-  if (!\Drupal::request()->query->has('token') || !\Drupal::csrfToken()->validate(\Drupal::request()->query->get('token'), current_path())) {
-    return MENU_NOT_FOUND;
-  }
-
-  token_clear_cache();
-  drupal_set_message(t('Token registry caches cleared.'));
-  drupal_goto();
-}
-
 function token_autocomplete() {
   $args = func_get_args();
   $string = implode('/', $args);
diff --git a/token.routing.yml b/token.routing.yml
index 57bee0c..f5b60bf 100644
--- a/token.routing.yml
+++ b/token.routing.yml
@@ -1,24 +1,15 @@
 token.autocomplete:
-  path: /token/autocomplete/{token_type}/{filter}
+  path: '/token/autocomplete/{token_type}/{filter}'
   defaults:
     _controller: '\Drupal\token\Controller\TokenAutocompleteController::autocomplete'
   requirements:
     _access: 'TRUE'
-
-#
-#  $items['token/autocomplete/%token_type'] = array(
-#    'page callback' => 'token_autocomplete_token',
-#    'page arguments' => array(2),
-#    'access callback' => TRUE,
-#    'type' => MENU_CALLBACK,
-#    'file' => 'token.pages.inc',
-#  );
-#    $items['token/flush-cache'] = array(
-#      'page callback' => 'token_flush_cache_callback',
-#      'access arguments' => array('flush caches'),
-#      'type' => MENU_CALLBACK,
-#      'file' => 'token.pages.inc',
-#    );
+token.flush_cache:
+  path: '/token/flush-cache'
+  defaults:
+    _controller: '\Drupal\token\Controller\TokenCacheController::flush'
+  requirements:
+    _permission: 'flush caches'
 #
 #  if (\Drupal::moduleHandler()->moduleExists('devel')) {
 #    $items['node/%node/devel/token'] = array(
-- 
1.9.3 (Apple Git-50)


From 3de4cc2e15011302f72e4e5ca1e7c23f220862c4 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Wed, 26 Feb 2014 18:05:00 +0100
Subject: [PATCH 114/230] Issue #1962358 by penyaskito: Convert devel token
 integrations to a controller.

---
 .../token/Controller/TokenDevelController.php      | 90 ++++++++++++++++++++++
 token.routing.yml                                  | 83 ++++++++++----------
 token.tokens.inc                                   |  6 +-
 3 files changed, 137 insertions(+), 42 deletions(-)
 create mode 100644 lib/Drupal/token/Controller/TokenDevelController.php

diff --git a/lib/Drupal/token/Controller/TokenDevelController.php b/lib/Drupal/token/Controller/TokenDevelController.php
new file mode 100644
index 0000000..eb8c138
--- /dev/null
+++ b/lib/Drupal/token/Controller/TokenDevelController.php
@@ -0,0 +1,90 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Controller\TokenDevelController.
+ */
+
+namespace Drupal\token\Controller;
+
+use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
+use Drupal\Core\Extension\ModuleHandler;
+use Drupal\Core\Extension\ModuleHandlerInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\HttpFoundation\Request;
+
+/**
+ * Devel integration for tokens.
+ */
+class TokenDevelController implements ContainerInjectionInterface {
+
+  /**
+   * The module handler to invoke the alter hook.
+   *
+   * @var \Drupal\Core\Extension\ModuleHandlerInterface
+   */
+  protected $moduleHandler;
+
+  /**
+   * Constructs a new TokenDevelController.
+   *
+   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
+   *   The module handler.
+   */
+  public function __construct(ModuleHandlerInterface $module_handler) {
+    $this->moduleHandler = $module_handler;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container) {
+    return new static(
+      $container->get('module_handler')
+    );
+  }
+
+  public function devel_token_object($entity_type, $entity_id, Request $request) {
+    $this->moduleHandler->loadInclude('token', 'pages.inc');
+    $entity = entity_load($entity_type, $entity_id);
+
+    $header = array(
+      t('Token'),
+      t('Value'),
+    );
+    $rows = array();
+
+    $options = array(
+      'flat' => TRUE,
+      'values' => TRUE,
+      'data' => array($entity_type => $entity),
+    );
+    $tree = token_build_tree($entity_type, $options);
+    foreach ($tree as $token => $token_info) {
+      if (!empty($token_info['restricted'])) {
+        continue;
+      }
+      if (!isset($token_info['value']) && !empty($token_info['parent']) && !isset($tree[$token_info['parent']]['value'])) {
+        continue;
+      }
+      $row = _token_token_tree_format_row($token, $token_info);
+      unset($row['data']['description']);
+      unset($row['data']['name']);
+      $rows[] = $row;
+    }
+
+    $build['tokens'] = array(
+      '#theme' => 'tree_table',
+      '#header' => $header,
+      '#rows' => $rows,
+      '#attributes' => array('class' => array('token-tree')),
+      '#empty' => t('No tokens available.'),
+      '#attached' => array(
+        'js' => array(drupal_get_path('module', 'token') . '/token.js'),
+        'css' => array(drupal_get_path('module', 'token') . '/token.css'),
+      ),
+    );
+
+    return $build;
+  }
+}
diff --git a/token.routing.yml b/token.routing.yml
index f5b60bf..9f1e843 100644
--- a/token.routing.yml
+++ b/token.routing.yml
@@ -10,42 +10,47 @@ token.flush_cache:
     _controller: '\Drupal\token\Controller\TokenCacheController::flush'
   requirements:
     _permission: 'flush caches'
-#
-#  if (\Drupal::moduleHandler()->moduleExists('devel')) {
-#    $items['node/%node/devel/token'] = array(
-#      'title' => 'Tokens',
-#      'page callback' => 'token_devel_token_object',
-#      'page arguments' => array('node', 1),
-#      'access arguments' => array('access devel information'),
-#      'type' => MENU_LOCAL_TASK,
-#      'file' => 'token.pages.inc',
-#      'weight' => 5,
-#    );
-#    $items['comment/%comment/devel/token'] = array(
-#      'title' => 'Tokens',
-#      'page callback' => 'token_devel_token_object',
-#      'page arguments' => array('comment', 1),
-#      'access arguments' => array('access devel information'),
-#      'type' => MENU_LOCAL_TASK,
-#      'file' => 'token.pages.inc',
-#      'weight' => 5,
-#    );
-#    $items['taxonomy/term/%taxonomy_term/devel/token'] = array(
-#      'title' => 'Tokens',
-#      'page callback' => 'token_devel_token_object',
-#      'page arguments' => array('taxonomy_term', 2),
-#      'access arguments' => array('access devel information'),
-#      'type' => MENU_LOCAL_TASK,
-#      'file' => 'token.pages.inc',
-#      'weight' => 5,
-#    );
-#    $items['user/%user/devel/token'] = array(
-#      'title' => 'Tokens',
-#      'page callback' => 'token_devel_token_object',
-#      'page arguments' => array('user', 1),
-#      'access arguments' => array('access devel information'),
-#      'type' => MENU_LOCAL_TASK,
-#      'file' => 'token.pages.inc',
-#      'weight' => 5,
-#    );
-#  }
+token.devel_node_token:
+  path: '/node/{entity_id}/devel/token'
+  defaults:
+    _content: '\Drupal\token\Controller\TokenDevelController::devel_token_object'
+    _title: 'Tokens'
+    entity_type: 'node'
+  options:
+    _access_mode: 'ALL'
+  requirements:
+    _permission: 'access devel information'
+    _module_dependencies: 'devel'
+token.devel_comment_token:
+  path: '/comment/{entity_id}/devel/token'
+  defaults:
+    _content: '\Drupal\token\Controller\TokenDevelController::devel_token_object'
+    _title: 'Tokens'
+    entity_type: 'comment'
+  options:
+    _access_mode: 'ALL'
+  requirements:
+    _permission: 'access devel information'
+    _module_dependencies: 'devel'
+token.devel_term_token:
+  path: '/taxonomy/term/{entity_id}/devel/token'
+  defaults:
+    _content: '\Drupal\token\Controller\TokenDevelController::devel_token_object'
+    _title: 'Tokens'
+    entity_type: 'taxonomy_term'
+  options:
+    _access_mode: 'ALL'
+  requirements:
+    _permission: 'access devel information'
+    _module_dependencies: 'devel'
+token.devel_user_token:
+  path: '/user/{entity_id}/devel/token'
+  defaults:
+    _content: '\Drupal\token\Controller\TokenDevelController::devel_token_object'
+    _title: 'Tokens'
+    entity_type: 'user'
+  options:
+    _access_mode: 'ALL'
+  requirements:
+    _permission: 'access devel information'
+    _module_dependencies: 'devel'
diff --git a/token.tokens.inc b/token.tokens.inc
index 97f8e5e..81470ce 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -961,7 +961,7 @@ function token_tokens_alter(array &$replacements, array $context) {
         case 'author':
           // @todo Remove when http://drupal.org/node/920056 is fixed.
           if (!empty($comment->uid)) {
-            $account = user_load($comment->uid);
+            $account = user_load($comment->uid->value);
           }
           else {
             $account = drupal_anonymous_user();
@@ -981,7 +981,7 @@ function token_tokens_alter(array &$replacements, array $context) {
     foreach ($context['tokens'] as $name => $original) {
       switch ($name) {
         case 'author':
-          $account = user_load($node->uid);
+          $account = user_load($node->uid->value);
           $name = $account->getUsername();
           $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
           break;
@@ -996,7 +996,7 @@ function token_tokens_alter(array &$replacements, array $context) {
     foreach ($context['tokens'] as $name => $original) {
       switch ($name) {
         case 'owner':
-          $account = user_load($file->uid);
+          $account = user_load($file->uid->value);
           $name = $account->getUsername();
           $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
           break;
-- 
1.9.3 (Apple Git-50)


From 125773b0560143f7e1bbcdd50ad96276be8f86e1 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Sat, 1 Mar 2014 16:47:20 +0100
Subject: [PATCH 115/230] Issue #1962358 by penyaskito: routing params must
 have the same name than the core ones.

---
 token.routing.yml | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/token.routing.yml b/token.routing.yml
index 9f1e843..a2bd32c 100644
--- a/token.routing.yml
+++ b/token.routing.yml
@@ -11,44 +11,48 @@ token.flush_cache:
   requirements:
     _permission: 'flush caches'
 token.devel_node_token:
-  path: '/node/{entity_id}/devel/token'
+  path: '/node/{node}/devel/token'
   defaults:
     _content: '\Drupal\token\Controller\TokenDevelController::devel_token_object'
     _title: 'Tokens'
     entity_type: 'node'
+    entity_id: %node
   options:
     _access_mode: 'ALL'
   requirements:
     _permission: 'access devel information'
     _module_dependencies: 'devel'
 token.devel_comment_token:
-  path: '/comment/{entity_id}/devel/token'
+  path: '/comment/{comment}/devel/token'
   defaults:
     _content: '\Drupal\token\Controller\TokenDevelController::devel_token_object'
     _title: 'Tokens'
     entity_type: 'comment'
+    entity_id: %comment
   options:
     _access_mode: 'ALL'
   requirements:
     _permission: 'access devel information'
     _module_dependencies: 'devel'
-token.devel_term_token:
-  path: '/taxonomy/term/{entity_id}/devel/token'
+token.devel_taxonomy_term_token:
+  path: '/taxonomy/term/{taxonomy_term}/devel/token'
   defaults:
     _content: '\Drupal\token\Controller\TokenDevelController::devel_token_object'
     _title: 'Tokens'
     entity_type: 'taxonomy_term'
+    entity_id: %taxonomy_term
   options:
     _access_mode: 'ALL'
   requirements:
     _permission: 'access devel information'
     _module_dependencies: 'devel'
 token.devel_user_token:
-  path: '/user/{entity_id}/devel/token'
+  path: '/user/{user}/devel/token'
   defaults:
     _content: '\Drupal\token\Controller\TokenDevelController::devel_token_object'
     _title: 'Tokens'
     entity_type: 'user'
+    entity_id: %user
   options:
     _access_mode: 'ALL'
   requirements:
-- 
1.9.3 (Apple Git-50)


From 8c3032e76e92a3cce807aaec7000e08aec489341 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Sat, 1 Mar 2014 16:48:23 +0100
Subject: [PATCH 116/230] Issue #1962358 by penyaskito: Added
 token.local_tasks.yml. See https://drupal.org/node/2044515. Depends on
 https://drupal.org/node/2208323

---
 token.local_tasks.yml | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 token.local_tasks.yml

diff --git a/token.local_tasks.yml b/token.local_tasks.yml
new file mode 100644
index 0000000..48b23ed
--- /dev/null
+++ b/token.local_tasks.yml
@@ -0,0 +1,20 @@
+token.devel_node_tab:
+  route_name: token.devel_node_token
+  title: 'Tokens'
+  parent_id: devel.devel_node_tab
+  weight: 20
+token.devel_comment_tab:
+  route_name: token.devel_comment_token
+  title: 'Tokens'
+  parent_id: devel.devel_comment_tab
+  weight: 20
+token.devel_term_tab:
+  route_name: token.devel_taxonomy_term_token
+  title: 'Tokens'
+  parent_id: devel.devel_taxonomy_term_tab
+  weight: 20
+token.devel_user_tab:
+  route_name: token.devel_user_token
+  title: 'Tokens'
+  parent_id: devel.devel_user_tab
+  weight: 20
-- 
1.9.3 (Apple Git-50)


From 204d22fb1a91e37081ad83b7a6f2898230878315 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Sat, 1 Mar 2014 16:54:16 +0100
Subject: [PATCH 117/230] Issue #1962358 by penyaskito: Remove hook_library and
 use token.libraries.yml instead. See https://drupal.org/node/2201089

---
 token.libraries.yml | 10 ++++++++++
 token.module        | 20 --------------------
 token.pages.inc     |  5 +++--
 3 files changed, 13 insertions(+), 22 deletions(-)
 create mode 100644 token.libraries.yml

diff --git a/token.libraries.yml b/token.libraries.yml
new file mode 100644
index 0000000..8353af6
--- /dev/null
+++ b/token.libraries.yml
@@ -0,0 +1,10 @@
+jquery.treeTable:
+  remote: 'http://plugins.jquery.com/project/treetable'
+  version: 2.3.0
+  js:
+    js/jquery.treeTable.js: {}
+  css:
+    component:
+      css/jquery.treeTable.css: {}
+  dependencies:
+    - core/jquery
\ No newline at end of file
diff --git a/token.module b/token.module
index 65802ac..ca66b76 100644
--- a/token.module
+++ b/token.module
@@ -156,26 +156,6 @@ function token_theme() {
 }
 
 /**
- * Implements hook_library().
- */
-function token_library() {
-  // jQuery treeTable plugin.
-  $libraries['treeTable'] = array(
-    'title' => 'jQuery treeTable',
-    'website' => 'http://plugins.jquery.com/project/treetable',
-    'version' => '2.3.0',
-    'js' => array(
-      drupal_get_path('module', 'token') . '/jquery.treeTable.js' => array(),
-    ),
-    'css' => array(
-      drupal_get_path('module', 'token') . '/jquery.treeTable.css' => array(),
-    ),
-  );
-
-  return $libraries;
-}
-
-/**
  * Implements hook_form_alter().
  *
  * Adds a submit handler to forms which could affect the tokens available on
diff --git a/token.pages.inc b/token.pages.inc
index 027a476..e16a3eb 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -20,7 +20,8 @@ function theme_tree_table($variables) {
   }
 
   if (!empty($variables['rows'])) {
-    drupal_add_library('token', 'treeTable');
+    $attached['#attached']['library'][] = array('token', 'jquery.treeTable');
+    drupal_render($attached);
   }
 
   // ToDo: Use render arrays. See https://drupal.org/node/2195739
@@ -99,7 +100,7 @@ function theme_token_tree($variables) {
     '#attached' => array(
       'js' => array(drupal_get_path('module', 'token') . '/token.js'),
       'css' => array(drupal_get_path('module', 'token') . '/token.css'),
-      'library' => array(array('token', 'treeTable')),
+      'library' => array(array('token', 'jquery.treeTable')),
     ),
   );
 
-- 
1.9.3 (Apple Git-50)


From 3b16018e51864c7723ae6b94a139df540dc50d78 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Sat, 1 Mar 2014 17:17:25 +0100
Subject: [PATCH 118/230] Issue #1962358 by penyaskito: One method per entity.

---
 lib/Drupal/token/Controller/TokenDevelController.php | 18 +++++++++++++++++-
 token.routing.yml                                    | 16 ++++------------
 2 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/lib/Drupal/token/Controller/TokenDevelController.php b/lib/Drupal/token/Controller/TokenDevelController.php
index eb8c138..7afb9cc 100644
--- a/lib/Drupal/token/Controller/TokenDevelController.php
+++ b/lib/Drupal/token/Controller/TokenDevelController.php
@@ -44,7 +44,23 @@ class TokenDevelController implements ContainerInjectionInterface {
     );
   }
 
-  public function devel_token_object($entity_type, $entity_id, Request $request) {
+  public function devel_token_node($node, Request $request) {
+    return $this->devel_token_object('node', $node, $request);
+  }
+
+  public function devel_token_comment($comment, Request $request) {
+    return $this->devel_token_object('comment', $comment, $request);
+  }
+
+  public function devel_token_user($user, Request $request) {
+    return $this->devel_token_object('user', $user, $request);
+  }
+
+  public function devel_token_taxonomy_term($taxonomy_term, Request $request) {
+    return $this->devel_token_object('taxonomy_term', $taxonomy_term, $request);
+  }
+
+  private function devel_token_object($entity_type, $entity_id, Request $request) {
     $this->moduleHandler->loadInclude('token', 'pages.inc');
     $entity = entity_load($entity_type, $entity_id);
 
diff --git a/token.routing.yml b/token.routing.yml
index a2bd32c..d1ea305 100644
--- a/token.routing.yml
+++ b/token.routing.yml
@@ -13,10 +13,8 @@ token.flush_cache:
 token.devel_node_token:
   path: '/node/{node}/devel/token'
   defaults:
-    _content: '\Drupal\token\Controller\TokenDevelController::devel_token_object'
+    _content: '\Drupal\token\Controller\TokenDevelController::devel_token_node'
     _title: 'Tokens'
-    entity_type: 'node'
-    entity_id: %node
   options:
     _access_mode: 'ALL'
   requirements:
@@ -25,10 +23,8 @@ token.devel_node_token:
 token.devel_comment_token:
   path: '/comment/{comment}/devel/token'
   defaults:
-    _content: '\Drupal\token\Controller\TokenDevelController::devel_token_object'
+    _content: '\Drupal\token\Controller\TokenDevelController::devel_token_comment'
     _title: 'Tokens'
-    entity_type: 'comment'
-    entity_id: %comment
   options:
     _access_mode: 'ALL'
   requirements:
@@ -37,10 +33,8 @@ token.devel_comment_token:
 token.devel_taxonomy_term_token:
   path: '/taxonomy/term/{taxonomy_term}/devel/token'
   defaults:
-    _content: '\Drupal\token\Controller\TokenDevelController::devel_token_object'
+    _content: '\Drupal\token\Controller\TokenDevelController::devel_token_taxonomy_term'
     _title: 'Tokens'
-    entity_type: 'taxonomy_term'
-    entity_id: %taxonomy_term
   options:
     _access_mode: 'ALL'
   requirements:
@@ -49,10 +43,8 @@ token.devel_taxonomy_term_token:
 token.devel_user_token:
   path: '/user/{user}/devel/token'
   defaults:
-    _content: '\Drupal\token\Controller\TokenDevelController::devel_token_object'
+    _content: '\Drupal\token\Controller\TokenDevelController::devel_token_user'
     _title: 'Tokens'
-    entity_type: 'user'
-    entity_id: %user
   options:
     _access_mode: 'ALL'
   requirements:
-- 
1.9.3 (Apple Git-50)


From b5e35ce9e311d22d5160a5db417268f5991fef61 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Sat, 1 Mar 2014 17:22:39 +0100
Subject: [PATCH 119/230] Issue #1962358 by penyaskito: Removed cache() usage.
 See https://drupal.org/node/2198339.

---
 token.module     | 10 +++++-----
 token.tokens.inc |  4 ++--
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/token.module b/token.module
index ca66b76..4163f7a 100644
--- a/token.module
+++ b/token.module
@@ -290,7 +290,7 @@ function token_field_delete_instance($instance) {
  */
 function token_clear_cache() {
   if (db_table_exists('cache_token')) {
-    cache('cache_token')->flush();
+    \Drupal::cache('cache_token')->flush();
   }
   drupal_static_reset('token_get_info');
   drupal_static_reset('token_get_global_token_types');
@@ -427,7 +427,7 @@ function token_get_info($token_type = NULL, $token = NULL) {
     $langcode = \Drupal::languageManager()->getCurrentLanguage()->id;
     $cid = "info:{$langcode}";
 
-    if ($cache = cache('cache_token')->get($cid)) {
+    if ($cache = \Drupal::cache('cache_token')->get($cid)) {
       $token_info = $cache->data;
     }
     else {
@@ -457,7 +457,7 @@ function token_get_info($token_type = NULL, $token = NULL) {
       }
 
       // Store info in cache for future use.
-      cache('cache_token')->set($cid, $token_info);
+      \Drupal::cache('cache_token')->set($cid, $token_info);
     }
   }
 
@@ -813,13 +813,13 @@ function token_build_tree($token_type, array $options = array()) {
   // If we do not have this base tree in the static cache, check {cache_token}
   // otherwise generate and store it in the cache.
   if (!isset($trees[$tree_cid])) {
-    if ($cache = cache('cache_token')->get($tree_cid)) {
+    if ($cache = \Drupal::cache('cache_token')->get($tree_cid)) {
       $trees[$tree_cid] = $cache->data;
     }
     else {
       $options['parents'] = array();
       $trees[$tree_cid] = _token_build_tree($token_type, $options);
-      cache('cache_token')->set($tree_cid, $trees[$tree_cid]);
+      \Drupal::cache('cache_token')->set($tree_cid, $trees[$tree_cid]);
     }
   }
 
diff --git a/token.tokens.inc b/token.tokens.inc
index 81470ce..ba1b8d1 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -1200,7 +1200,7 @@ function _token_field_info($field_name = NULL) {
   $info = &drupal_static(__FUNCTION__);
 
   if (!isset($fields)) {
-    if ($cached = cache('cache_token')->get('field:info')) {
+    if ($cached = \Drupal::cache('cache_token')->get('field:info')) {
       $info = $cached->data;
     }
     else {
@@ -1253,7 +1253,7 @@ function _token_field_info($field_name = NULL) {
       }
 
       \Drupal::moduleHandler()->alter('token_field_info', $info);
-      cache('cache_token')->set('field:info', $info);
+      \Drupal::cache('cache_token')->set('field:info', $info);
     }
   }
 
-- 
1.9.3 (Apple Git-50)


From 8a485d469d9327b6767588a6eb5b23451f01885e Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Sat, 1 Mar 2014 17:28:11 +0100
Subject: [PATCH 120/230] Issue #1962358 by penyaskito: Removed
 drupal_map_assoc() usage. See https://drupal.org/node/2207453

---
 lib/Drupal/token/Controller/TokenAutocompleteController.php |  4 +++-
 token.pages.inc                                             |  3 ++-
 token.tokens.inc                                            | 10 ++++++----
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/lib/Drupal/token/Controller/TokenAutocompleteController.php b/lib/Drupal/token/Controller/TokenAutocompleteController.php
index 4af2ee0..87efca1 100644
--- a/lib/Drupal/token/Controller/TokenAutocompleteController.php
+++ b/lib/Drupal/token/Controller/TokenAutocompleteController.php
@@ -68,7 +68,9 @@ class TokenAutocompleteController implements ContainerInjectionInterface {
     }
 
     asort($matches);
-    $matches = drupal_map_assoc(array_keys($matches));
+
+    $keys = array_keys($matches);
+    $matches = array_combine($keys, $keys);
 
     return new JsonResponse($matches);
   }
diff --git a/token.pages.inc b/token.pages.inc
index e16a3eb..82bfdb8 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -253,7 +253,8 @@ function token_autocomplete_type($string = '') {
     ksort($matches);
   }
 
-  $matches = drupal_map_assoc(array_keys($matches));
+  $keys = array_keys($matches);
+  $matches = array_combine($keys, $keys);
   drupal_json_output($matches);
 }
 
diff --git a/token.tokens.inc b/token.tokens.inc
index ba1b8d1..a5ab3d5 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -580,8 +580,9 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           break;
 
         case 'roles':
-          $roles = drupal_map_assoc($account->getRoles());
-          $replacements[$original] = token_render_array($roles, $options);
+          $roles = $account->getRoles();
+          $roles_names = array_combine($roles, $roles);
+          $replacements[$original] = token_render_array($roles_names, $options);
           break;
       }
     }
@@ -594,8 +595,9 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       $replacements += \Drupal::token()->generate('url', $url_tokens, $account->urlInfo(), $options);
     }
     if ($role_tokens = \Drupal::token()->findWithPrefix($tokens, 'roles')) {
-      $roles = drupal_map_assoc($account->getRoles());
-      $replacements += \Drupal::token()->generate('array', $role_tokens, array('array' => $roles), $options);
+      $roles = $account->getRoles();
+      $roles_names = array_combine($roles, $roles);
+      $replacements += \Drupal::token()->generate('array', $role_tokens, array('array' => $roles_names), $options);
     }
   }
 
-- 
1.9.3 (Apple Git-50)


From 7f277068ac5909d2353e1e15364e053c33ffe041 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Tue, 4 Mar 2014 01:59:30 +0100
Subject: [PATCH 121/230] Issue #1962358 by penyaskito: Added token.js to
 libraries and #attach it properly.

---
 token.libraries.yml | 9 ++++++++-
 token.pages.inc     | 8 +++-----
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/token.libraries.yml b/token.libraries.yml
index 8353af6..9e4c950 100644
--- a/token.libraries.yml
+++ b/token.libraries.yml
@@ -7,4 +7,11 @@ jquery.treeTable:
     component:
       css/jquery.treeTable.css: {}
   dependencies:
-    - core/jquery
\ No newline at end of file
+    - core/jquery
+token:
+  version: VERSION
+  js:
+    js/token.js: {}
+  dependencies:
+    - core/jquery
+    - core/drupal
diff --git a/token.pages.inc b/token.pages.inc
index 82bfdb8..5ddd9fe 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -18,12 +18,11 @@ function theme_tree_table($variables) {
       unset($row['parent']);
     }
   }
-
+  $attached['#attached']['library'][] = array('token', 'token');
   if (!empty($variables['rows'])) {
     $attached['#attached']['library'][] = array('token', 'jquery.treeTable');
-    drupal_render($attached);
   }
-
+  drupal_render($attached);
   // ToDo: Use render arrays. See https://drupal.org/node/2195739
   return _theme('table', $variables);
 }
@@ -98,9 +97,8 @@ function theme_token_tree($variables) {
     '#attributes' => array('class' => array('token-tree')),
     '#empty' => t('No tokens available'),
     '#attached' => array(
-      'js' => array(drupal_get_path('module', 'token') . '/token.js'),
       'css' => array(drupal_get_path('module', 'token') . '/token.css'),
-      'library' => array(array('token', 'jquery.treeTable')),
+      'library' => array(array('token', 'token'), array('token', 'jquery.treeTable')),
     ),
   );
 
-- 
1.9.3 (Apple Git-50)


From 3872a27b7dddace33dda6c116b219ddee7e7a1f4 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Wed, 5 Mar 2014 10:37:32 +0100
Subject: [PATCH 122/230] Issue #1962358 by penyaskito: Removed pending cache()
 usage. See https://drupal.org/node/2198339

---
 token.module | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.module b/token.module
index 4163f7a..bc0338a 100644
--- a/token.module
+++ b/token.module
@@ -1061,7 +1061,7 @@ function token_render_cache_get($elements) {
   }
   $bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache';
 
-  if (!empty($cid) && $cache = cache($bin)->get($cid)) {
+  if (!empty($cid) && $cache = \Drupal::cache($bin)->get($cid)) {
     // Add additional libraries, JavaScript, CSS and other data attached
     // to this element.
     if (isset($cache->data['#attached'])) {
-- 
1.9.3 (Apple Git-50)


From a3eecc3e0f4ee586c118715fde7c72b46dbd72f1 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Wed, 5 Mar 2014 10:38:14 +0100
Subject: [PATCH 123/230] Issue #1962358 by penyaskito: Fixed css path.

---
 token.pages.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.pages.inc b/token.pages.inc
index 5ddd9fe..bfb37ad 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -97,7 +97,7 @@ function theme_token_tree($variables) {
     '#attributes' => array('class' => array('token-tree')),
     '#empty' => t('No tokens available'),
     '#attached' => array(
-      'css' => array(drupal_get_path('module', 'token') . '/token.css'),
+      'css' => array(drupal_get_path('module', 'token') . '/css/token.css'),
       'library' => array(array('token', 'token'), array('token', 'jquery.treeTable')),
     ),
   );
-- 
1.9.3 (Apple Git-50)


From f3dbd89c82b616de606c08f82e7f3976f4a6ecd5 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Sat, 29 Mar 2014 15:09:51 +0100
Subject: [PATCH 124/230] Issue #1962358 by penyaskito:
 field_ui_field_edit_form become field_ui_field_instance_edit_form per
 https://drupal.org/node/1986552

---
 token.module | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/token.module b/token.module
index bc0338a..86e5367 100644
--- a/token.module
+++ b/token.module
@@ -669,8 +669,12 @@ function token_element_validate_token_context(&$element, &$form_state) {
 /**
  * Implements hook_form_FORM_ID_alter().
  */
-function token_form_field_ui_field_edit_form_alter(&$form, $form_state) {
-  if (($form['#field']['type'] == 'file' || $form['#field']['type'] == 'image') && isset($form['instance']['settings']['file_directory']) && !\Drupal::moduleHandler()->moduleExists('filefield_paths')) {
+function token_form_field_ui_field_instance_edit_form_alter(&$form, $form_state) {
+  if (!isset($form['instance']) || $form['#field']->isLocked()) {
+    return;
+  }
+  $field_type = $form['#field']->getType();
+  if (($field_type == 'file' || $field_type == 'image') && isset($form['instance']['settings']['file_directory']) {
     // GAH! We can only support global tokens in the upload file directory path.
     $form['instance']['settings']['file_directory']['#element_validate'][] = 'token_element_validate';
     $form['instance']['settings']['file_directory']['#token_types'] = array();
-- 
1.9.3 (Apple Git-50)


From 7e06910529767e7c5c44114ae62757987f256521 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Sat, 29 Mar 2014 15:15:11 +0100
Subject: [PATCH 125/230] Issue #1962358 by penyaskito: Replace #attached
 library array values with provider-namespaced strings per
 https://drupal.org/node/1764252

---
 token.pages.inc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/token.pages.inc b/token.pages.inc
index bfb37ad..1d446c3 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -18,9 +18,9 @@ function theme_tree_table($variables) {
       unset($row['parent']);
     }
   }
-  $attached['#attached']['library'][] = array('token', 'token');
+  $attached['#attached']['library'][] = 'token/token';
   if (!empty($variables['rows'])) {
-    $attached['#attached']['library'][] = array('token', 'jquery.treeTable');
+    $attached['#attached']['library'][] = 'token/jquery.treeTable';
   }
   drupal_render($attached);
   // ToDo: Use render arrays. See https://drupal.org/node/2195739
@@ -98,7 +98,7 @@ function theme_token_tree($variables) {
     '#empty' => t('No tokens available'),
     '#attached' => array(
       'css' => array(drupal_get_path('module', 'token') . '/css/token.css'),
-      'library' => array(array('token', 'token'), array('token', 'jquery.treeTable')),
+      'library' => array('token/token', 'token/jquery.treeTable'),
     ),
   );
 
-- 
1.9.3 (Apple Git-50)


From 107af822083a69a85e6c4521f13897bc46e0c360 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Sat, 29 Mar 2014 15:22:58 +0100
Subject: [PATCH 126/230] Revert "Issue #1962358 by penyaskito:
 field_ui_field_edit_form become field_ui_field_instance_edit_form per
 https://drupal.org/node/1986552"

This reverts commit f3dbd89c82b616de606c08f82e7f3976f4a6ecd5.
---
 token.module | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/token.module b/token.module
index 86e5367..bc0338a 100644
--- a/token.module
+++ b/token.module
@@ -669,12 +669,8 @@ function token_element_validate_token_context(&$element, &$form_state) {
 /**
  * Implements hook_form_FORM_ID_alter().
  */
-function token_form_field_ui_field_instance_edit_form_alter(&$form, $form_state) {
-  if (!isset($form['instance']) || $form['#field']->isLocked()) {
-    return;
-  }
-  $field_type = $form['#field']->getType();
-  if (($field_type == 'file' || $field_type == 'image') && isset($form['instance']['settings']['file_directory']) {
+function token_form_field_ui_field_edit_form_alter(&$form, $form_state) {
+  if (($form['#field']['type'] == 'file' || $form['#field']['type'] == 'image') && isset($form['instance']['settings']['file_directory']) && !\Drupal::moduleHandler()->moduleExists('filefield_paths')) {
     // GAH! We can only support global tokens in the upload file directory path.
     $form['instance']['settings']['file_directory']['#element_validate'][] = 'token_element_validate';
     $form['instance']['settings']['file_directory']['#token_types'] = array();
-- 
1.9.3 (Apple Git-50)


From f84399a28c4fe992130afb2b9d348ac2e8811ef8 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Sat, 29 Mar 2014 15:23:21 +0100
Subject: [PATCH 127/230] Issue #1962358 by penyaskito:
 field_ui_field_edit_form become field_ui_field_instance_edit_form per
 https://drupal.org/node/1986552

---
 token.module | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/token.module b/token.module
index bc0338a..86e5367 100644
--- a/token.module
+++ b/token.module
@@ -669,8 +669,12 @@ function token_element_validate_token_context(&$element, &$form_state) {
 /**
  * Implements hook_form_FORM_ID_alter().
  */
-function token_form_field_ui_field_edit_form_alter(&$form, $form_state) {
-  if (($form['#field']['type'] == 'file' || $form['#field']['type'] == 'image') && isset($form['instance']['settings']['file_directory']) && !\Drupal::moduleHandler()->moduleExists('filefield_paths')) {
+function token_form_field_ui_field_instance_edit_form_alter(&$form, $form_state) {
+  if (!isset($form['instance']) || $form['#field']->isLocked()) {
+    return;
+  }
+  $field_type = $form['#field']->getType();
+  if (($field_type == 'file' || $field_type == 'image') && isset($form['instance']['settings']['file_directory']) {
     // GAH! We can only support global tokens in the upload file directory path.
     $form['instance']['settings']['file_directory']['#element_validate'][] = 'token_element_validate';
     $form['instance']['settings']['file_directory']['#token_types'] = array();
-- 
1.9.3 (Apple Git-50)


From 718405d7ce43d07543eb1352423bcf394f672815 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Sat, 29 Mar 2014 15:35:22 +0100
Subject: [PATCH 128/230] Issue #1962358 by penyaskito: Fixed syntax error.

---
 token.module | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.module b/token.module
index 86e5367..202ee10 100644
--- a/token.module
+++ b/token.module
@@ -674,7 +674,7 @@ function token_form_field_ui_field_instance_edit_form_alter(&$form, $form_state)
     return;
   }
   $field_type = $form['#field']->getType();
-  if (($field_type == 'file' || $field_type == 'image') && isset($form['instance']['settings']['file_directory']) {
+  if (($field_type == 'file' || $field_type == 'image') && isset($form['instance']['settings']['file_directory'])) {
     // GAH! We can only support global tokens in the upload file directory path.
     $form['instance']['settings']['file_directory']['#element_validate'][] = 'token_element_validate';
     $form['instance']['settings']['file_directory']['#token_types'] = array();
-- 
1.9.3 (Apple Git-50)


From f5ff5f0e3f80686a8c68339c4e3709e062f53167 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Sat, 29 Mar 2014 15:39:18 +0100
Subject: [PATCH 129/230] Issue #1962358 by penyaskito: Renamed
 Drupal::getStorageController() to Drupal::getstorage() per
 https://drupal.org/node/1976158

---
 token.install    | 6 +++---
 token.tokens.inc | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/token.install b/token.install
index 65353e0..0007c61 100644
--- a/token.install
+++ b/token.install
@@ -51,10 +51,10 @@ function token_install() {
       continue;
     }
     // Try to find a token view mode for that entity type.
-    $storage_controller = \Drupal::entityManager()->getStorageController('view_mode');
+    $storage = \Drupal::entityManager()->getStorage('view_mode');
     // Add a token view mode if it does not already exist.
-    if (!$storage_controller->load("$entity_type.token")) {
-      $storage_controller->create(array(
+    if (!$storage->load("$entity_type.token")) {
+      $storage->create(array(
         'targetEntityType' => $entity_type,
         'id' => "$entity_type.token",
         'status' => TRUE,
diff --git a/token.tokens.inc b/token.tokens.inc
index a5ab3d5..2401c10 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -87,7 +87,7 @@ function token_token_info_alter(&$info) {
 
   // Add support for custom date formats.
   // @todo Remove when http://drupal.org/node/1173706 is fixed.
-  $date_format_types = \Drupal::entityManager()->getStorageController('date_format')->loadMultiple();
+  $date_format_types = \Drupal::entityManager()->getStorage('date_format')->loadMultiple();
   foreach ($date_format_types as $date_format_type => $date_format_type_info) {
     /* @var \Drupal\system\Entity\DateFormat $date_format_type_info */
     if (!isset($info['tokens']['date'][$date_format_type])) {
@@ -393,7 +393,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
     $date = !empty($data['date']) ? $data['date'] : REQUEST_TIME;
 
     // @todo Remove when http://drupal.org/node/1173706 is fixed.
-    $date_format_types = \Drupal::entityManager()->getStorageController('date_format')->loadMultiple();
+    $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);
@@ -435,7 +435,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           $replacements[$original] = $sanitize ? filter_xss($node->log->value) : $node->log->value;
           break;
         case 'content-type':
-          $type_name = \Drupal::entityManager()->getStorageController('node_type')->load($node->getType())->label();
+          $type_name = \Drupal::entityManager()->getStorage('node_type')->load($node->getType())->label();
           $replacements[$original] = $sanitize ? String::checkPlain($type_name) : $type_name;
           break;
       }
-- 
1.9.3 (Apple Git-50)


From 1a921c4b18b79513ea5a20f626ef99f89bff7bce Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Sat, 29 Mar 2014 15:46:09 +0100
Subject: [PATCH 130/230] Issue #1962358 by penyaskito: Sorting functions have
 moved to SortArray. See https://drupal.org/node/2181331

---
 token.module | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.module b/token.module
index 202ee10..7c730b9 100644
--- a/token.module
+++ b/token.module
@@ -1186,7 +1186,7 @@ function token_element_children(&$elements, $sort = FALSE) {
   }
   // Sort the children if necessary.
   if ($sort && $sortable) {
-    uasort($children, 'element_sort');
+    uasort($children, 'Drupal\Component\Utility\SortArray::sortByWeightProperty');
     // Put the sorted children back into $elements in the correct order, to
     // preserve sorting if the same element is passed through
     // element_children() twice.
-- 
1.9.3 (Apple Git-50)


From 7830e292866a8ad90c86d3612ebaa19e12a04963 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Sun, 30 Mar 2014 22:25:04 +0200
Subject: [PATCH 131/230] Issue #1962358 by penyaskito:
 Crypt::randomStringHashed() was removed. See https://drupal.org/node/1984806

---
 token.tokens.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index 2401c10..64ba4ca 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -915,7 +915,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       $algos = hash_algos();
       foreach ($hash_tokens as $name => $original) {
         if (in_array($name, $algos)) {
-          $replacements[$original] = hash($name, Crypt::randomStringHashed(55));
+          $replacements[$original] = hash($name, Crypt::randomBytes(55));
         }
       }
     }
-- 
1.9.3 (Apple Git-50)


From 37420c24dc12ecf0678a6c87d6b6c960b17aa5a2 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Sun, 30 Mar 2014 22:26:33 +0200
Subject: [PATCH 132/230] Issue #1962358 by penyaskito: Added @group token to
 tests.

---
 lib/Drupal/token/Tests/TokenArrayTestCase.php       | 2 ++
 lib/Drupal/token/Tests/TokenBlockTestCase.php       | 2 ++
 lib/Drupal/token/Tests/TokenCommentTestCase.php     | 2 ++
 lib/Drupal/token/Tests/TokenCurrentPageTestCase.php | 2 ++
 lib/Drupal/token/Tests/TokenDateTestCase.php        | 2 ++
 lib/Drupal/token/Tests/TokenEntityTestCase.php      | 2 ++
 lib/Drupal/token/Tests/TokenFileTestCase.php        | 2 ++
 lib/Drupal/token/Tests/TokenMenuTestCase.php        | 2 ++
 lib/Drupal/token/Tests/TokenNodeTestCase.php        | 2 ++
 lib/Drupal/token/Tests/TokenRandomTestCase.php      | 2 ++
 lib/Drupal/token/Tests/TokenTaxonomyTestCase.php    | 2 ++
 lib/Drupal/token/Tests/TokenURLTestCase.php         | 2 ++
 lib/Drupal/token/Tests/TokenUnitTestCase.php        | 2 ++
 lib/Drupal/token/Tests/TokenUserTestCase.php        | 2 ++
 14 files changed, 28 insertions(+)

diff --git a/lib/Drupal/token/Tests/TokenArrayTestCase.php b/lib/Drupal/token/Tests/TokenArrayTestCase.php
index ebc627f..4249296 100644
--- a/lib/Drupal/token/Tests/TokenArrayTestCase.php
+++ b/lib/Drupal/token/Tests/TokenArrayTestCase.php
@@ -8,6 +8,8 @@ namespace Drupal\token\Tests;
 
 /**
  * Tests array tokens.
+ *
+ * @group Token
  */
 class TokenArrayTestCase extends TokenTestBase {
   public static function getInfo() {
diff --git a/lib/Drupal/token/Tests/TokenBlockTestCase.php b/lib/Drupal/token/Tests/TokenBlockTestCase.php
index 7245d7f..cb607e7 100644
--- a/lib/Drupal/token/Tests/TokenBlockTestCase.php
+++ b/lib/Drupal/token/Tests/TokenBlockTestCase.php
@@ -8,6 +8,8 @@ namespace Drupal\token\Tests;
 
 /**
  * Tests block tokens.
+ *
+ * @group Token
  */
 class TokenBlockTestCase extends TokenTestBase {
   protected static $modules = array('path', 'token', 'token_test', 'block', 'node', 'views', 'custom_block');
diff --git a/lib/Drupal/token/Tests/TokenCommentTestCase.php b/lib/Drupal/token/Tests/TokenCommentTestCase.php
index 8ee1e07..8895405 100644
--- a/lib/Drupal/token/Tests/TokenCommentTestCase.php
+++ b/lib/Drupal/token/Tests/TokenCommentTestCase.php
@@ -8,6 +8,8 @@ namespace Drupal\token\Tests;
 
 /**
  * Tests comment tokens.
+ *
+ * @group Token
  */
 class TokenCommentTestCase extends TokenTestBase {
   protected static $modules = array('path', 'token', 'token_test', 'node', 'comment');
diff --git a/lib/Drupal/token/Tests/TokenCurrentPageTestCase.php b/lib/Drupal/token/Tests/TokenCurrentPageTestCase.php
index d67478c..8fb26fe 100644
--- a/lib/Drupal/token/Tests/TokenCurrentPageTestCase.php
+++ b/lib/Drupal/token/Tests/TokenCurrentPageTestCase.php
@@ -8,6 +8,8 @@ namespace Drupal\token\Tests;
 
 /**
  * Tests current page tokens.
+ *
+ * @group Token
  */
 class TokenCurrentPageTestCase extends TokenTestBase {
 
diff --git a/lib/Drupal/token/Tests/TokenDateTestCase.php b/lib/Drupal/token/Tests/TokenDateTestCase.php
index 675c0df..58624b7 100644
--- a/lib/Drupal/token/Tests/TokenDateTestCase.php
+++ b/lib/Drupal/token/Tests/TokenDateTestCase.php
@@ -8,6 +8,8 @@ namespace Drupal\token\Tests;
 
 /**
  * Tests date tokens.
+ *
+ * @group Token
  */
 class TokenDateTestCase extends TokenTestBase {
   public static function getInfo() {
diff --git a/lib/Drupal/token/Tests/TokenEntityTestCase.php b/lib/Drupal/token/Tests/TokenEntityTestCase.php
index 8d67c22..cb07033 100644
--- a/lib/Drupal/token/Tests/TokenEntityTestCase.php
+++ b/lib/Drupal/token/Tests/TokenEntityTestCase.php
@@ -9,6 +9,8 @@ use Drupal\taxonomy\VocabularyInterface;
 
 /**
  * Tests entity tokens.
+ *
+ * @group Token
  */
 class TokenEntityTestCase extends TokenTestBase {
   protected static $modules = array('path', 'token', 'token_test', 'node', 'taxonomy');
diff --git a/lib/Drupal/token/Tests/TokenFileTestCase.php b/lib/Drupal/token/Tests/TokenFileTestCase.php
index 84b47ef..7bbda18 100644
--- a/lib/Drupal/token/Tests/TokenFileTestCase.php
+++ b/lib/Drupal/token/Tests/TokenFileTestCase.php
@@ -8,6 +8,8 @@ namespace Drupal\token\Tests;
 
 /**
  * Tests file tokens.
+ *
+ * @group Token
  */
 class TokenFileTestCase extends TokenTestBase {
   protected static $modules = array('path', 'token', 'token_test', 'file');
diff --git a/lib/Drupal/token/Tests/TokenMenuTestCase.php b/lib/Drupal/token/Tests/TokenMenuTestCase.php
index 13882f5..08b4ab3 100644
--- a/lib/Drupal/token/Tests/TokenMenuTestCase.php
+++ b/lib/Drupal/token/Tests/TokenMenuTestCase.php
@@ -8,6 +8,8 @@ namespace Drupal\token\Tests;
 
 /**
  * Tests menu tokens.
+ *
+ * @group Token
  */
 class TokenMenuTestCase extends TokenTestBase {
   protected static $modules = array('path', 'token', 'token_test', 'menu', 'node');
diff --git a/lib/Drupal/token/Tests/TokenNodeTestCase.php b/lib/Drupal/token/Tests/TokenNodeTestCase.php
index 1b14173..d16a6e4 100644
--- a/lib/Drupal/token/Tests/TokenNodeTestCase.php
+++ b/lib/Drupal/token/Tests/TokenNodeTestCase.php
@@ -8,6 +8,8 @@ namespace Drupal\token\Tests;
 
 /**
  * Tests node tokens.
+ *
+ * @group Token
  */
 class TokenNodeTestCase extends TokenTestBase {
   protected $profile = 'standard';
diff --git a/lib/Drupal/token/Tests/TokenRandomTestCase.php b/lib/Drupal/token/Tests/TokenRandomTestCase.php
index e214a13..4e8760b 100644
--- a/lib/Drupal/token/Tests/TokenRandomTestCase.php
+++ b/lib/Drupal/token/Tests/TokenRandomTestCase.php
@@ -8,6 +8,8 @@ namespace Drupal\token\Tests;
 
 /**
  * Tests random tokens.
+ *
+ * @group Token
  */
 class TokenRandomTestCase extends TokenTestBase {
   public static function getInfo() {
diff --git a/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php b/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php
index e597bf9..96c8e20 100644
--- a/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php
+++ b/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php
@@ -9,6 +9,8 @@ use Drupal\Component\Utility\String;
 
 /**
  * Tests taxonomy tokens.
+ *
+ * @group Token
  */
 class TokenTaxonomyTestCase extends TokenTestBase {
   protected $vocab;
diff --git a/lib/Drupal/token/Tests/TokenURLTestCase.php b/lib/Drupal/token/Tests/TokenURLTestCase.php
index 91c5a2c..b5dbbd5 100644
--- a/lib/Drupal/token/Tests/TokenURLTestCase.php
+++ b/lib/Drupal/token/Tests/TokenURLTestCase.php
@@ -8,6 +8,8 @@ namespace Drupal\token\Tests;
 
 /**
  * Tests url tokens.
+ *
+ * @group Token
  */
 class TokenURLTestCase extends TokenTestBase {
   protected static $modules = array('path', 'token', 'token_test', 'node');
diff --git a/lib/Drupal/token/Tests/TokenUnitTestCase.php b/lib/Drupal/token/Tests/TokenUnitTestCase.php
index 127b1be..d017494 100644
--- a/lib/Drupal/token/Tests/TokenUnitTestCase.php
+++ b/lib/Drupal/token/Tests/TokenUnitTestCase.php
@@ -8,6 +8,8 @@ namespace Drupal\token\Tests;
 
 /**
  * Token unit tests.
+ *
+ * @group Token
  */
 class TokenUnitTestCase extends TokenTestBase {
   protected static $modules = array('path', 'token', 'token_test', 'file', 'node');
diff --git a/lib/Drupal/token/Tests/TokenUserTestCase.php b/lib/Drupal/token/Tests/TokenUserTestCase.php
index fae58d1..fe7c151 100644
--- a/lib/Drupal/token/Tests/TokenUserTestCase.php
+++ b/lib/Drupal/token/Tests/TokenUserTestCase.php
@@ -9,6 +9,8 @@ use Drupal\field\Field;
 
 /**
  * Tests user tokens.
+ *
+ * @group Token
  */
 class TokenUserTestCase extends TokenTestBase {
   protected $account = NULL;
-- 
1.9.3 (Apple Git-50)


From 4b073dcd288c3571763185739a93d5610470d384 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Sun, 30 Mar 2014 22:35:03 +0200
Subject: [PATCH 133/230] Issue #1962358 by penyaskito: Entity::urlInfo()
 returns a Drupal\Core\Url object. See http://drupal.org/node/2215961

---
 token.tokens.inc | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index 64ba4ca..3555ccf 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -414,7 +414,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
     // Chained token relationships.
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, $comment->urlInfo(), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, (array) $comment->urlInfo(), $options);
     }
   }
 
@@ -449,7 +449,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
       $replacements += \Drupal::token()->generate('content-type', $node_type_tokens, array('node_type' => $node_type), $options);
     }
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, $node->urlInfo(), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, (array) $node->urlInfo(), $options);
     }
   }
 
@@ -512,7 +512,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
     // Chained token relationships.
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, $term->urlInfo(), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, (array) $term->urlInfo(), $options);
     }
     // [term:parents:*] chained tokens.
     if ($parents_tokens = \Drupal::token()->findWithPrefix($tokens, 'parents')) {
@@ -818,7 +818,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
 
     // [entity:url:*] chained tokens.
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) && _token_module($type, 'url') == 'token') {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, $entity->urlInfo(), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, (array) $entity->urlInfo(), $options);
     }
 
     // [entity:original:*] chained tokens.
-- 
1.9.3 (Apple Git-50)


From 96267546e805219b9c9fd55d96f1cbd41445ead7 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Sun, 30 Mar 2014 22:37:45 +0200
Subject: [PATCH 134/230] Issue #1962358 by penyaskito: Menu links have been
 converted to entities. See http://drupal.org/node/1914008

---
 token.module | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/token.module b/token.module
index 7c730b9..816e711 100644
--- a/token.module
+++ b/token.module
@@ -1103,8 +1103,8 @@ function token_menu_link_load_all_parents($mlid) {
     $cache[$mlid] = array();
     $plid = db_query("SELECT plid FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $mlid))->fetchField();
     while ($plid && $parent = menu_link_load($plid)) {
-      $cache[$mlid] = array($plid => $parent['title']) + $cache[$mlid];
-      $plid = $parent['plid'];
+      $cache[$mlid] = array($plid => $parent->label()) + $cache[$mlid];
+      $plid = $parent->plid;
     }
   }
 
-- 
1.9.3 (Apple Git-50)


From f6172946746e2fc5bcb5a1cc61a4b48ce834ea46 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Sun, 30 Mar 2014 22:38:42 +0200
Subject: [PATCH 135/230] Issue #1962358 by penyaskito: Added type hinting to
 token_tokens implementation.

---
 token.tokens.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index 3555ccf..65674bb 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -374,7 +374,7 @@ function token_token_info() {
 /**
  * Implements hook_tokens().
  */
-function token_tokens($type, $tokens, array $data = array(), array $options = array()) {
+function token_tokens($type, array $tokens, array $data = array(), array $options = array()) {
   $replacements = array();
 
   $url_options = array('absolute' => TRUE);
-- 
1.9.3 (Apple Git-50)


From e6127b52aa40e78d3b0a699b3b4fbd86e88a01b3 Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Sun, 30 Mar 2014 22:59:36 +0200
Subject: [PATCH 136/230] Issue #1962358 by penyaskito: Test requires to create
 the page content type.

---
 lib/Drupal/token/Tests/TokenCommentTestCase.php | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/Drupal/token/Tests/TokenCommentTestCase.php b/lib/Drupal/token/Tests/TokenCommentTestCase.php
index 8895405..6ddb0b2 100644
--- a/lib/Drupal/token/Tests/TokenCommentTestCase.php
+++ b/lib/Drupal/token/Tests/TokenCommentTestCase.php
@@ -23,6 +23,7 @@ class TokenCommentTestCase extends TokenTestBase {
   }
 
   function testCommentTokens() {
+    $this->drupalCreateContentType(array('type' => 'page', 'name' => t('Page')));
     \Drupal::service('comment.manager')->addDefaultField('node', 'page');
     $node = $this->drupalCreateNode();
 
-- 
1.9.3 (Apple Git-50)


From a9ec786061a6deb1471abc5dedcfabf3bb9bd6df Mon Sep 17 00:00:00 2001
From: Christian Lopez Espinola <penyaskito@computer.org>
Date: Mon, 31 Mar 2014 00:38:25 +0200
Subject: [PATCH 137/230] Issue #1962358 by penyaskito: hook_node_prepare_form
 has 3 args now.

---
 token.module | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/token.module b/token.module
index 816e711..58c49a9 100644
--- a/token.module
+++ b/token.module
@@ -4,6 +4,7 @@
  * @file
  * Enhances the token API in core: adds a browseable UI, missing tokens, etc.
  */
+
 use Drupal\Component\Utility\String;
 use Drupal\Core\Render\Element;
 
@@ -1156,7 +1157,7 @@ function token_node_menu_link_load($node) {
       // @see http://drupal.org/node/1317926
       $menu_node = clone $node;
       $form_state = array();
-      menu_node_prepare_form($menu_node, NULL, NULL, $form_state);
+      menu_node_prepare_form($menu_node, NULL, $form_state);
       $mlid = !empty($menu_node->menu['mlid']) ? $menu_node->menu['mlid'] : FALSE;
     }
     else {
-- 
1.9.3 (Apple Git-50)


From 0d11e03216a377cd5523504cb0b9e53281f118e5 Mon Sep 17 00:00:00 2001
From: "tien.xuan.vo" <tien.xuan.vo@gmail.com>
Date: Fri, 23 May 2014 21:14:47 +0700
Subject: [PATCH 138/230] Replace filter_xss by Xss::filter.

---
 token.tokens.inc | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index 65674bb..2902953 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -9,6 +9,7 @@ use Drupal\Component\Utility\String;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Render\Element;
 use Drupal\field\Field;
+use Drupal\Component\Utility\Xss;
 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
 
 /**
@@ -428,11 +429,11 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
         case 'source':
           if (!empty($node->tnid) && $source_node = node_load($node->tnid)) {
             $title = $source_node->label();
-            $replacements[$original] = $sanitize ? filter_xss($title) : $title;
+            $replacements[$original] = $sanitize ? Xss::filter($title) : $title;
           }
           break;
         case 'log':
-          $replacements[$original] = $sanitize ? filter_xss($node->log->value) : $node->log->value;
+          $replacements[$original] = $sanitize ? Xss::filter($node->log->value) : $node->log->value;
           break;
         case 'content-type':
           $type_name = \Drupal::entityManager()->getStorage('node_type')->load($node->getType())->label();
@@ -467,7 +468,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
           $replacements[$original] = $node_type->type;
           break;
         case 'description':
-          $replacements[$original] = $sanitize ? filter_xss($node_type->description) : $node_type->description;
+          $replacements[$original] = $sanitize ? Xss::filter($node_type->description) : $node_type->description;
           break;
         case 'node-count':
           $query = db_select('node');
@@ -1176,7 +1177,7 @@ function menu_tokens($type, $tokens, array $data = array(), array $options = arr
           $replacements[$original] = $menu->id();
           break;
         case 'description':
-          $replacements[$original] = $sanitize ? filter_xss($menu->description) : $menu->description;
+          $replacements[$original] = $sanitize ? Xss::filter($menu->description) : $menu->description;
           break;
         case 'menu-link-count':
           $query = db_select('menu_links');
-- 
1.9.3 (Apple Git-50)


From 50d5501d6336f38e27ccee65ac4193f963e9bc3d Mon Sep 17 00:00:00 2001
From: "tien.xuan.vo" <tien.xuan.vo@gmail.com>
Date: Fri, 23 May 2014 22:05:18 +0700
Subject: [PATCH 139/230] Convert urlInfo object to array.

---
 lib/Drupal/token/Tests/TokenTestBase.php |  2 +-
 token.tokens.inc                         | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenTestBase.php b/lib/Drupal/token/Tests/TokenTestBase.php
index dbcbb92..11bdb62 100644
--- a/lib/Drupal/token/Tests/TokenTestBase.php
+++ b/lib/Drupal/token/Tests/TokenTestBase.php
@@ -73,7 +73,7 @@ class TokenTestBase extends WebTestBase {
   }
 
   function saveEntityAlias($entity_type, EntityInterface $entity, $alias, $language = Language::LANGCODE_NOT_SPECIFIED) {
-    $uri = $entity->urlInfo();
+    $uri = $entity->urlInfo()->toArray();
     return $this->saveAlias($uri['path'], $alias, $language);
   }
 
diff --git a/token.tokens.inc b/token.tokens.inc
index 65674bb..8a8e838 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -414,7 +414,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
 
     // Chained token relationships.
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, (array) $comment->urlInfo(), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, $comment->urlInfo()->toArray(), $options);
     }
   }
 
@@ -449,7 +449,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
       $replacements += \Drupal::token()->generate('content-type', $node_type_tokens, array('node_type' => $node_type), $options);
     }
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, (array) $node->urlInfo(), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, $node->urlInfo()->toArray(), $options);
     }
   }
 
@@ -512,7 +512,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
 
     // Chained token relationships.
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, (array) $term->urlInfo(), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, $term->urlInfo()->toArray(), $options);
     }
     // [term:parents:*] chained tokens.
     if ($parents_tokens = \Drupal::token()->findWithPrefix($tokens, 'parents')) {
@@ -592,7 +592,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
       $replacements += \Drupal::token()->generate('file', $picture_tokens, array('file' => $account->user_picture->entity), $options);
     }
     if ($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, $account->urlInfo(), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, $account->urlInfo()->toArray(), $options);
     }
     if ($role_tokens = \Drupal::token()->findWithPrefix($tokens, 'roles')) {
       $roles = $account->getRoles();
@@ -802,7 +802,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'url':
-          if (_token_module($type, 'url') == 'token' && $uri = $entity->urlInfo()) {
+          if (_token_module($type, 'url') == 'token' && $uri = $entity->urlInfo()->toArray()) {
             $replacements[$original] = url($uri['path'], $uri['options']);
           }
           break;
@@ -818,7 +818,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
 
     // [entity:url:*] chained tokens.
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) && _token_module($type, 'url') == 'token') {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, (array) $entity->urlInfo(), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, $entity->urlInfo()->toArray(), $options);
     }
 
     // [entity:original:*] chained tokens.
-- 
1.9.3 (Apple Git-50)


From 2051554b6e67dd29fa29ed0f618cb4592936ce08 Mon Sep 17 00:00:00 2001
From: "tien.xuan.vo" <tien.xuan.vo@gmail.com>
Date: Fri, 23 May 2014 22:16:12 +0700
Subject: [PATCH 140/230] Replace getPathAlias by getAliasByPath.

---
 token.tokens.inc | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index 65674bb..b9f3ca8 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -747,12 +747,12 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'path':
-          $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getPathAlias($path, $language_code) : $path;
+          $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $language_code) : $path;
           $replacements[$original] = $sanitize ? String::checkPlain($value) : $value;
           break;
         case 'alias':
           // @deprecated
-          $alias = \Drupal::service('path.alias_manager')->getPathAlias($path, $language_code);
+          $alias = \Drupal::service('path.alias_manager')->getAliasByPath($path, $language_code);
           $replacements[$original] = $sanitize ? String::checkPlain($alias) : $alias;
           break;
         case 'absolute':
@@ -770,7 +770,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
           $replacements[$original] = \Drupal::url($route, $route_param, array('alias' => TRUE) + $url_options);
           break;
         case 'args':
-          $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getPathAlias($path, $language_code) : $path;
+          $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $language_code) : $path;
           $replacements[$original] = token_render_array(arg(NULL, $value), $options);
           break;
       }
@@ -778,7 +778,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
 
     // [url:arg:*] chained tokens.
     if ($arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'args')) {
-      $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getPathAlias($path, $language_code) : $path;
+      $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $language_code) : $path;
       $value = ltrim($value, '/');
       $replacements += \Drupal::token()->generate('array', $arg_tokens, array('array' => arg(NULL, $value)), $options);
     }
-- 
1.9.3 (Apple Git-50)


From 43a2540d031b30549bb9c608b849de87b1dc4e43 Mon Sep 17 00:00:00 2001
From: "tien.xuan.vo" <tien.xuan.vo@gmail.com>
Date: Fri, 23 May 2014 22:21:59 +0700
Subject: [PATCH 141/230] Fix asset path error.

---
 lib/Drupal/token/Controller/TokenDevelController.php | 4 ++--
 token.pages.inc                                      | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/Drupal/token/Controller/TokenDevelController.php b/lib/Drupal/token/Controller/TokenDevelController.php
index 7afb9cc..f2daf86 100644
--- a/lib/Drupal/token/Controller/TokenDevelController.php
+++ b/lib/Drupal/token/Controller/TokenDevelController.php
@@ -96,8 +96,8 @@ class TokenDevelController implements ContainerInjectionInterface {
       '#attributes' => array('class' => array('token-tree')),
       '#empty' => t('No tokens available.'),
       '#attached' => array(
-        'js' => array(drupal_get_path('module', 'token') . '/token.js'),
-        'css' => array(drupal_get_path('module', 'token') . '/token.css'),
+        'js' => array(drupal_get_path('module', 'token') . '/js/token.js'),
+        'css' => array(drupal_get_path('module', 'token') . '/css/token.css'),
       ),
     );
 
diff --git a/token.pages.inc b/token.pages.inc
index 1d446c3..2605d4c 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -203,8 +203,8 @@ function token_devel_token_object($entity_type, $entity) {
     '#attributes' => array('class' => array('token-tree')),
     '#empty' => t('No tokens available.'),
     '#attached' => array(
-      'js' => array(drupal_get_path('module', 'token') . '/token.js'),
-      'css' => array(drupal_get_path('module', 'token') . '/token.css'),
+      'js' => array(drupal_get_path('module', 'token') . '/js/token.js'),
+      'css' => array(drupal_get_path('module', 'token') . '/css/token.css'),
     ),
   );
 
-- 
1.9.3 (Apple Git-50)


From 924aff246ea56e372b48b2f207270764ef24cfd7 Mon Sep 17 00:00:00 2001
From: "tien.xuan.vo" <tien.xuan.vo@gmail.com>
Date: Fri, 23 May 2014 23:03:00 +0700
Subject: [PATCH 142/230] Attach library instead of files.

---
 lib/Drupal/token/Controller/TokenDevelController.php | 3 +--
 token.libraries.yml                                  | 3 +++
 token.pages.inc                                      | 3 +--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/lib/Drupal/token/Controller/TokenDevelController.php b/lib/Drupal/token/Controller/TokenDevelController.php
index f2daf86..964bcb5 100644
--- a/lib/Drupal/token/Controller/TokenDevelController.php
+++ b/lib/Drupal/token/Controller/TokenDevelController.php
@@ -96,8 +96,7 @@ class TokenDevelController implements ContainerInjectionInterface {
       '#attributes' => array('class' => array('token-tree')),
       '#empty' => t('No tokens available.'),
       '#attached' => array(
-        'js' => array(drupal_get_path('module', 'token') . '/js/token.js'),
-        'css' => array(drupal_get_path('module', 'token') . '/css/token.css'),
+        'library' => array('token/token'),
       ),
     );
 
diff --git a/token.libraries.yml b/token.libraries.yml
index 9e4c950..603e429 100644
--- a/token.libraries.yml
+++ b/token.libraries.yml
@@ -12,6 +12,9 @@ token:
   version: VERSION
   js:
     js/token.js: {}
+  css:
+    component:
+      css/token.css: {}
   dependencies:
     - core/jquery
     - core/drupal
diff --git a/token.pages.inc b/token.pages.inc
index 2605d4c..4fa5293 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -203,8 +203,7 @@ function token_devel_token_object($entity_type, $entity) {
     '#attributes' => array('class' => array('token-tree')),
     '#empty' => t('No tokens available.'),
     '#attached' => array(
-      'js' => array(drupal_get_path('module', 'token') . '/js/token.js'),
-      'css' => array(drupal_get_path('module', 'token') . '/css/token.css'),
+      'library' => array('token/token'),
     ),
   );
 
-- 
1.9.3 (Apple Git-50)


From b752d9e1f31cff316be7742da2b9cb4826e4d972 Mon Sep 17 00:00:00 2001
From: "tien.xuan.vo" <tien.xuan.vo@gmail.com>
Date: Sun, 25 May 2014 14:34:36 +0700
Subject: [PATCH 143/230] Make all comment testcases pass.

---
 lib/Drupal/token/Tests/TokenCommentTestCase.php | 12 ++++++++++--
 token.tokens.inc                                |  5 ++++-
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/lib/Drupal/token/Tests/TokenCommentTestCase.php b/lib/Drupal/token/Tests/TokenCommentTestCase.php
index 6ddb0b2..e3a6ac0 100644
--- a/lib/Drupal/token/Tests/TokenCommentTestCase.php
+++ b/lib/Drupal/token/Tests/TokenCommentTestCase.php
@@ -38,11 +38,15 @@ class TokenCommentTestCase extends TokenTestBase {
     ));
     $parent_comment->save();
 
+    // Fix http://example.com/index.php/comment/1 fails 'url:path' test.
+    $parent_comment_path = \Drupal::url('comment.permalink', array('comment' => $parent_comment->id()));
+    $parent_comment_path = ltrim($parent_comment_path, '/');
+
     $tokens = array(
       'url' => url('comment/' . $parent_comment->id(), array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
       'url:absolute' => url('comment/' . $parent_comment->id(), array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
       'url:relative' => url('comment/' . $parent_comment->id(), array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => FALSE)),
-      'url:path' => 'comment/' . $parent_comment->id(),
+      'url:path' => $parent_comment_path,
       'parent:url:absolute' => NULL,
     );
     $this->assertTokens('comment', array('comment' => $parent_comment), $tokens);
@@ -60,11 +64,15 @@ class TokenCommentTestCase extends TokenTestBase {
     ));
     $comment->save();
 
+    // Fix http://example.com/index.php/comment/1 fails 'url:path' test.
+    $comment_path = \Drupal::url('comment.permalink', array('comment' => $comment->id()));
+    $comment_path = ltrim($comment_path, '/');
+
     $tokens = array(
       'url' => url('comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id(), 'absolute' => TRUE)),
       'url:absolute' => url('comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id(), 'absolute' => TRUE)),
       'url:relative' => url('comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id(), 'absolute' => FALSE)),
-      'url:path' => 'comment/' . $comment->id(),
+      'url:path' => $comment_path,
       'parent:url:absolute' => url('comment/' . $parent_comment->id(), array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
     );
     $this->assertTokens('comment', array('comment' => $comment), $tokens);
diff --git a/token.tokens.inc b/token.tokens.inc
index e40c599..2219caa 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -415,7 +415,10 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
 
     // Chained token relationships.
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, $comment->urlInfo()->toArray(), $options);
+      // Add fragment to url options.
+      $comment_data = $comment->urlInfo()->toArray();
+      $comment_data['options'] += array('fragment' => 'comment-' . $comment->id());
+      $replacements += \Drupal::token()->generate('url', $url_tokens, $comment_data, $options);
     }
   }
 
-- 
1.9.3 (Apple Git-50)


From a4c2093ab3bc87f888319a6ca5d57f7e3c930448 Mon Sep 17 00:00:00 2001
From: "tien.xuan.vo" <tien.xuan.vo@gmail.com>
Date: Sun, 25 May 2014 14:36:29 +0700
Subject: [PATCH 144/230] Fix typo in assertTokens().

---
 lib/Drupal/token/Tests/TokenTestBase.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/Drupal/token/Tests/TokenTestBase.php b/lib/Drupal/token/Tests/TokenTestBase.php
index 11bdb62..198b28b 100644
--- a/lib/Drupal/token/Tests/TokenTestBase.php
+++ b/lib/Drupal/token/Tests/TokenTestBase.php
@@ -28,7 +28,7 @@ class TokenTestBase extends WebTestBase {
     foreach ($tokens as $name => $expected) {
       $token = $input[$name];
       if (!isset($expected)) {
-        $this->assertTrue(!isset($values[$token]), t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token)));
+        $this->assertTrue(!isset($replacements[$token]), t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token)));
       }
       elseif (!isset($replacements[$token])) {
         $this->fail(t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token)));
-- 
1.9.3 (Apple Git-50)


From 589448ff18e13968335ad9b90b40b4517047103c Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 28 May 2014 12:11:57 +0200
Subject: [PATCH 145/230] Fixed field token implementation.

---
 token.tokens.inc | 153 +++++++++++++++++++++++++------------------------------
 1 file changed, 68 insertions(+), 85 deletions(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index e40c599..bcac08d 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -6,10 +6,12 @@
  */
 use Drupal\Component\Utility\Crypt;
 use Drupal\Component\Utility\String;
-use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Entity\ContentEntityInterface;
 use Drupal\Core\Render\Element;
-use Drupal\field\Field;
 use Drupal\Component\Utility\Xss;
+use Drupal\field\Entity\FieldConfig;
+use Drupal\field\FieldConfigInterface;
+use Drupal\field\FieldInstanceConfigInterface;
 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
 
 /**
@@ -1197,88 +1199,31 @@ function menu_tokens($type, $tokens, array $data = array(), array $options = arr
 }
 
 /**
- * Fetch an array of field data used for tokens.
- */
-function _token_field_info($field_name = NULL) {
-  $info = &drupal_static(__FUNCTION__);
-
-  if (!isset($fields)) {
-    if ($cached = \Drupal::cache('cache_token')->get('field:info')) {
-      $info = $cached->data;
-    }
-    else {
-      $info = array();
-
-      $fields = field_info_fields();
-      $instances = Field::fieldInfo()->getInstances();
-      $type_info = \Drupal::service('plugin.manager.field.field_type')->getDefinitions();
-      $entity_info = \Drupal::entityManager()->getDefinitions();
-
-      foreach ($fields as $field) {
-        /* @var \Drupal\field\FieldInterface $field */
-        $key = $field->getName();
-        foreach (array_keys($field->getBundles()) as $entity) {
-          // Make sure a token type exists for this entity.
-          $token_type = token_get_entity_mapping('entity', $entity);
-          if (empty($token_type)) {
-            continue;
-          }
-
-          $info[$key]['token types'][] = $token_type;
-          $info[$key] += array('labels' => array(), 'bundles' => array());
-
-          // Find which label is most commonly used.
-          foreach ($field['bundles'][$entity] as $bundle) {
-            // Field information will included fields attached to disabled
-            // bundles, so check that the bundle exists before provided a
-            // token for it.
-            // @see http://drupal.org/node/1252566
-            if (!isset($entity_info[$entity]['bundles'][$bundle])) {
-              continue;
-            }
-
-            $info[$key]['labels'][] = $instances[$entity][$bundle][$key]['label'];
-            $info[$key]['bundles'][$token_type][$bundle] = $entity_info[$entity]['bundles'][$bundle]['label'];
-          }
-        }
-
-        if (isset($info[$key])) {
-          $labels = array_count_values($info[$key]['labels']);
-          arsort($labels);
-          $info[$key]['label'] = String::checkPlain(key($labels));
-
-          // Generate a description for the token.
-          $info[$key]['description'] = t('@type field.', array('@type' => $type_info[$field['type']]['label']));
-          if ($also_known_as = array_unique(array_diff($info[$key]['labels'], array($info[$key]['label'])))) {
-            $info[$key]['description'] .= ' ' . t('Also known as %labels.', array('%labels' => implode(', ', $also_known_as)));
-          }
-        }
-      }
-
-      \Drupal::moduleHandler()->alter('token_field_info', $info);
-      \Drupal::cache('cache_token')->set('field:info', $info);
-    }
-  }
-
-  if (isset($field_name)) {
-    return isset($info[$field_name]) ? $info[$field_name] : FALSE;
-  }
-
-  return $info;
-}
-
-/**
  * Implements hook_token_info_alter() on behalf of field.module.
  *
  * We use hook_token_info_alter() rather than hook_token_info() as other
  * modules may already have defined some field tokens.
  */
 function field_token_info_alter(&$info) {
-  $fields = _token_field_info();
+  $type_info = \Drupal::service('plugin.manager.field.field_type')->getDefinitions();
 
   // Attach field tokens to their respecitve entity tokens.
-  foreach ($fields as $field_name => $field) {
-    foreach (array_keys($field['bundles']) as $token_type) {
+  foreach (\Drupal::entityManager()->getDefinitions() as $entity_type_id => $entity_type) {
+    if (!$entity_type->isFieldable()) {
+      continue;
+    }
+
+    // Make sure a token type exists for this entity.
+    $token_type = token_get_entity_mapping('entity', $entity_type_id);
+    if (empty($token_type)) {
+      continue;
+    }
+
+    $fields = \Drupal::entityManager()->getFieldStorageDefinitions($entity_type_id);
+    foreach ($fields as $field_name => $field) {
+      if (!($field instanceof FieldConfigInterface)) {
+        continue;
+      }
       // If a token already exists for this field, then don't add it.
       if (isset($info['tokens'][$token_type][$field_name])) {
         continue;
@@ -1294,10 +1239,18 @@ function field_token_info_alter(&$info) {
         continue;
       }
 
+      // Generate a description for the token.
+
+      list($label, $labels) = _token_field_label($entity_type_id, $field_name);
+      $description = t('@type field.', array('@type' => $type_info[$field->getType()]['label']));
+      if (count($labels) > 1) {
+        unset($labels[$label]);
+        $description .= ' ' . t('Also known as %labels.', array('%labels' => implode(', ', $labels)));
+      }
+
       $info['tokens'][$token_type][$field_name] = array(
-        // Note that label and description have already been sanitized by _token_field_info().
-        'name' => $field['label'],
-        'description' => $field['description'],
+        'name' => String::checkPlain($label),
+        'description' => $description,
         'module' => 'token',
       );
     }
@@ -1305,6 +1258,37 @@ function field_token_info_alter(&$info) {
 }
 
 /**
+ * Returns the label of a certain field.
+ *
+ * Therefore it looks up in all bundles to find the most used instance.
+ *
+ * Based on field_views_field_label().
+ */
+function _token_field_label($entity_type, $field_name) {
+  $label_counter = array();
+  $all_labels = array();
+  // Count the amount of instances per label per field.
+  foreach (array_keys(\Drupal::entityManager()->getBundleInfo($entity_type)) as $bundle) {
+    $bundle_instances = array_filter(\Drupal::entityManager()->getFieldDefinitions($entity_type, $bundle), function ($field_definition) {
+        return $field_definition instanceof FieldInstanceConfigInterface;
+      });
+    if (isset($bundle_instances[$field_name])) {
+      $instance = $bundle_instances[$field_name];
+      $label = $instance->getLabel();
+      $label_counter[$label] = isset($label_counter[$label]) ? ++$label_counter[$label] : 1;
+      $all_labels[$label] = TRUE;
+    }
+  }
+  if (empty($label_counter)) {
+    return array($field_name, $all_labels);
+  }
+  // Sort the field labels by it most used label and return the most used one.
+  arsort($label_counter);
+  $label_counter = array_keys($label_counter);
+  return array($label_counter[0], $all_labels);
+}
+
+/**
  * Implements hook_tokens() on behalf of field.module.
  */
 function field_tokens($type, $tokens, array $data = array(), array $options = array()) {
@@ -1319,7 +1303,7 @@ function field_tokens($type, $tokens, array $data = array(), array $options = ar
     // The field API does weird stuff to the entity, so let's clone it.
     /* @var \Drupal\Core\Entity\EntityInterface $entity */
     $entity = clone $data['entity'];
-    if (!($entity instanceof EntityInterface)) {
+    if (!($entity instanceof ContentEntityInterface)) {
       return $replacements;
     }
 
@@ -1327,12 +1311,11 @@ function field_tokens($type, $tokens, array $data = array(), array $options = ar
     // inside field_attach_view().
     unset($entity->_field_view_prepared);
 
-    $bundle = $entity->bundle();
-    $fields = Field::fieldInfo()->getBundleInstances($entity_type, $bundle);
+    $fields = $entity->getFieldDefinitions();
 
     foreach (array_keys($fields) as $field_name) {
-      // Do not continue if the field is empty.
-      if (empty($entity->{$field_name})) {
+      // Do not continue if the field is empty or not a configurable field.
+      if (empty($entity->{$field_name}) || !($fields[$field_name] instanceof FieldInstanceConfigInterface)) {
         continue;
       }
 
@@ -1346,7 +1329,7 @@ function field_tokens($type, $tokens, array $data = array(), array $options = ar
           continue;
         }
 
-        $field_output = field_view_field($entity_type, $entity, $field_name, 'token', $langcode);
+        $field_output = $entity->$field_name->view('token');
         $field_output['#token_options'] = $options;
         $field_output['#pre_render'][] = 'token_pre_render_field_token';
         $replacements[$original] = drupal_render($field_output);
-- 
1.9.3 (Apple Git-50)


From fcc3597d3bc5c53dd39d525ff059775a6a8c29ce Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Tue, 3 Jun 2014 15:01:06 +0200
Subject: [PATCH 146/230] Converted to PSR-4

---
 {lib/Drupal/token => src}/Controller/TokenAutocompleteController.php | 0
 {lib/Drupal/token => src}/Controller/TokenCacheController.php        | 0
 {lib/Drupal/token => src}/Controller/TokenDevelController.php        | 0
 {lib/Drupal/token => src}/Tests/TokenArrayTestCase.php               | 0
 {lib/Drupal/token => src}/Tests/TokenBlockTestCase.php               | 0
 {lib/Drupal/token => src}/Tests/TokenCommentTestCase.php             | 0
 {lib/Drupal/token => src}/Tests/TokenCurrentPageTestCase.php         | 0
 {lib/Drupal/token => src}/Tests/TokenDateTestCase.php                | 0
 {lib/Drupal/token => src}/Tests/TokenEntityTestCase.php              | 0
 {lib/Drupal/token => src}/Tests/TokenFileTestCase.php                | 0
 {lib/Drupal/token => src}/Tests/TokenMenuTestCase.php                | 0
 {lib/Drupal/token => src}/Tests/TokenNodeTestCase.php                | 0
 {lib/Drupal/token => src}/Tests/TokenRandomTestCase.php              | 0
 {lib/Drupal/token => src}/Tests/TokenTaxonomyTestCase.php            | 0
 {lib/Drupal/token => src}/Tests/TokenTestBase.php                    | 0
 {lib/Drupal/token => src}/Tests/TokenURLTestCase.php                 | 0
 {lib/Drupal/token => src}/Tests/TokenUnitTestCase.php                | 0
 {lib/Drupal/token => src}/Tests/TokenUserTestCase.php                | 0
 18 files changed, 0 insertions(+), 0 deletions(-)
 rename {lib/Drupal/token => src}/Controller/TokenAutocompleteController.php (100%)
 rename {lib/Drupal/token => src}/Controller/TokenCacheController.php (100%)
 rename {lib/Drupal/token => src}/Controller/TokenDevelController.php (100%)
 rename {lib/Drupal/token => src}/Tests/TokenArrayTestCase.php (100%)
 rename {lib/Drupal/token => src}/Tests/TokenBlockTestCase.php (100%)
 rename {lib/Drupal/token => src}/Tests/TokenCommentTestCase.php (100%)
 rename {lib/Drupal/token => src}/Tests/TokenCurrentPageTestCase.php (100%)
 rename {lib/Drupal/token => src}/Tests/TokenDateTestCase.php (100%)
 rename {lib/Drupal/token => src}/Tests/TokenEntityTestCase.php (100%)
 rename {lib/Drupal/token => src}/Tests/TokenFileTestCase.php (100%)
 rename {lib/Drupal/token => src}/Tests/TokenMenuTestCase.php (100%)
 rename {lib/Drupal/token => src}/Tests/TokenNodeTestCase.php (100%)
 rename {lib/Drupal/token => src}/Tests/TokenRandomTestCase.php (100%)
 rename {lib/Drupal/token => src}/Tests/TokenTaxonomyTestCase.php (100%)
 rename {lib/Drupal/token => src}/Tests/TokenTestBase.php (100%)
 rename {lib/Drupal/token => src}/Tests/TokenURLTestCase.php (100%)
 rename {lib/Drupal/token => src}/Tests/TokenUnitTestCase.php (100%)
 rename {lib/Drupal/token => src}/Tests/TokenUserTestCase.php (100%)

diff --git a/lib/Drupal/token/Controller/TokenAutocompleteController.php b/src/Controller/TokenAutocompleteController.php
similarity index 100%
rename from lib/Drupal/token/Controller/TokenAutocompleteController.php
rename to src/Controller/TokenAutocompleteController.php
diff --git a/lib/Drupal/token/Controller/TokenCacheController.php b/src/Controller/TokenCacheController.php
similarity index 100%
rename from lib/Drupal/token/Controller/TokenCacheController.php
rename to src/Controller/TokenCacheController.php
diff --git a/lib/Drupal/token/Controller/TokenDevelController.php b/src/Controller/TokenDevelController.php
similarity index 100%
rename from lib/Drupal/token/Controller/TokenDevelController.php
rename to src/Controller/TokenDevelController.php
diff --git a/lib/Drupal/token/Tests/TokenArrayTestCase.php b/src/Tests/TokenArrayTestCase.php
similarity index 100%
rename from lib/Drupal/token/Tests/TokenArrayTestCase.php
rename to src/Tests/TokenArrayTestCase.php
diff --git a/lib/Drupal/token/Tests/TokenBlockTestCase.php b/src/Tests/TokenBlockTestCase.php
similarity index 100%
rename from lib/Drupal/token/Tests/TokenBlockTestCase.php
rename to src/Tests/TokenBlockTestCase.php
diff --git a/lib/Drupal/token/Tests/TokenCommentTestCase.php b/src/Tests/TokenCommentTestCase.php
similarity index 100%
rename from lib/Drupal/token/Tests/TokenCommentTestCase.php
rename to src/Tests/TokenCommentTestCase.php
diff --git a/lib/Drupal/token/Tests/TokenCurrentPageTestCase.php b/src/Tests/TokenCurrentPageTestCase.php
similarity index 100%
rename from lib/Drupal/token/Tests/TokenCurrentPageTestCase.php
rename to src/Tests/TokenCurrentPageTestCase.php
diff --git a/lib/Drupal/token/Tests/TokenDateTestCase.php b/src/Tests/TokenDateTestCase.php
similarity index 100%
rename from lib/Drupal/token/Tests/TokenDateTestCase.php
rename to src/Tests/TokenDateTestCase.php
diff --git a/lib/Drupal/token/Tests/TokenEntityTestCase.php b/src/Tests/TokenEntityTestCase.php
similarity index 100%
rename from lib/Drupal/token/Tests/TokenEntityTestCase.php
rename to src/Tests/TokenEntityTestCase.php
diff --git a/lib/Drupal/token/Tests/TokenFileTestCase.php b/src/Tests/TokenFileTestCase.php
similarity index 100%
rename from lib/Drupal/token/Tests/TokenFileTestCase.php
rename to src/Tests/TokenFileTestCase.php
diff --git a/lib/Drupal/token/Tests/TokenMenuTestCase.php b/src/Tests/TokenMenuTestCase.php
similarity index 100%
rename from lib/Drupal/token/Tests/TokenMenuTestCase.php
rename to src/Tests/TokenMenuTestCase.php
diff --git a/lib/Drupal/token/Tests/TokenNodeTestCase.php b/src/Tests/TokenNodeTestCase.php
similarity index 100%
rename from lib/Drupal/token/Tests/TokenNodeTestCase.php
rename to src/Tests/TokenNodeTestCase.php
diff --git a/lib/Drupal/token/Tests/TokenRandomTestCase.php b/src/Tests/TokenRandomTestCase.php
similarity index 100%
rename from lib/Drupal/token/Tests/TokenRandomTestCase.php
rename to src/Tests/TokenRandomTestCase.php
diff --git a/lib/Drupal/token/Tests/TokenTaxonomyTestCase.php b/src/Tests/TokenTaxonomyTestCase.php
similarity index 100%
rename from lib/Drupal/token/Tests/TokenTaxonomyTestCase.php
rename to src/Tests/TokenTaxonomyTestCase.php
diff --git a/lib/Drupal/token/Tests/TokenTestBase.php b/src/Tests/TokenTestBase.php
similarity index 100%
rename from lib/Drupal/token/Tests/TokenTestBase.php
rename to src/Tests/TokenTestBase.php
diff --git a/lib/Drupal/token/Tests/TokenURLTestCase.php b/src/Tests/TokenURLTestCase.php
similarity index 100%
rename from lib/Drupal/token/Tests/TokenURLTestCase.php
rename to src/Tests/TokenURLTestCase.php
diff --git a/lib/Drupal/token/Tests/TokenUnitTestCase.php b/src/Tests/TokenUnitTestCase.php
similarity index 100%
rename from lib/Drupal/token/Tests/TokenUnitTestCase.php
rename to src/Tests/TokenUnitTestCase.php
diff --git a/lib/Drupal/token/Tests/TokenUserTestCase.php b/src/Tests/TokenUserTestCase.php
similarity index 100%
rename from lib/Drupal/token/Tests/TokenUserTestCase.php
rename to src/Tests/TokenUserTestCase.php
-- 
1.9.3 (Apple Git-50)


From 5c7e350bd315d07e0b4c478c61592c3f815c5c4d Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Mon, 9 Jun 2014 00:10:42 +0200
Subject: [PATCH 147/230] Update test date format after intl support removal

---
 tests/token_test/config/system.date_format.token_test.yml | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/tests/token_test/config/system.date_format.token_test.yml b/tests/token_test/config/system.date_format.token_test.yml
index 43e8a62..ca6dd1d 100644
--- a/tests/token_test/config/system.date_format.token_test.yml
+++ b/tests/token_test/config/system.date_format.token_test.yml
@@ -4,6 +4,4 @@ label: 'Token test'
 status: true
 langcode: en
 locked: true
-pattern:
-  php: Y
-  intl: yyyy
+pattern: Y
-- 
1.9.3 (Apple Git-50)


From 66f826296f29120f1998bf4d7ff76ab5da9600e3 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Tue, 10 Jun 2014 23:54:03 +0200
Subject: [PATCH 148/230] Remove unecessary info alter hook.

---
 token.module | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/token.module b/token.module
index 58c49a9..8855958 100644
--- a/token.module
+++ b/token.module
@@ -34,18 +34,6 @@ function token_help($path, $arg) {
 }
 
 /**
- * Implements hook_system_info_alter().
- *
- * Prevent the token_actions module from being enabled since updates may have
- * left the old module files still in the directory.
- */
-function token_system_info_alter(&$info, $file, $type) {
-  if ($type == 'module' && $file->name == 'token_actions') {
-    $info['hidden'] = TRUE;
-  }
-}
-
-/**
  * Return an array of the core modules supported by token.module.
  */
 function _token_core_supported_modules() {
-- 
1.9.3 (Apple Git-50)


From 94b2775e9d50da10be248dbd083d3e659dfb0a49 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 11 Jun 2014 00:05:36 +0200
Subject: [PATCH 149/230] Remove cache flush hook, caches are flushed
 automatically.

---
 token.module | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/token.module b/token.module
index 8855958..df9158a 100644
--- a/token.module
+++ b/token.module
@@ -379,15 +379,6 @@ function token_module_implements_alter(&$implementations, $hook) {
 }
 
 /**
- * Implements hook_flush_caches().
- */
-function token_flush_caches() {
-  if (db_table_exists('cache_token')) {
-    return array('cache_token');
-  }
-}
-
-/**
  * Retrieve, sort, store token info from the cache.
  *
  * @param $token_type
-- 
1.9.3 (Apple Git-50)


From 3ea9d3e10055351609c4d955c71613c29f3f5f5b Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 11 Jun 2014 00:53:49 +0200
Subject: [PATCH 150/230] Fix library call

---
 token.pages.inc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/token.pages.inc b/token.pages.inc
index 1c5f57f..dbc64a2 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -14,7 +14,8 @@ function theme_token_tree_link($variables) {
   }
 
   if (!empty($variables['dialog'])) {
-    drupal_add_library('token', 'dialog');
+    // @todo Move this somewhere it can use #attached.
+    _drupal_add_library('token/token');
     $variables['options']['attributes']['class'][] = 'token-dialog';
   }
 
-- 
1.9.3 (Apple Git-50)


From 27adef07dfa81df8835c3379bc77488e9ee82c7f Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 11 Jun 2014 01:12:46 +0200
Subject: [PATCH 151/230] Fix block label form alter

---
 token.module | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/token.module b/token.module
index 86d3f65..0617f92 100644
--- a/token.module
+++ b/token.module
@@ -212,18 +212,11 @@ function token_block_view_alter(&$data, \Drupal\block\BlockPluginInterface $bloc
 /**
  * Implements hook_form_FORM_ID_alter().
  */
-function token_form_block_add_block_form_alter(&$form, $form_state) {
-  token_form_block_admin_configure_alter($form, $form_state);
-}
-
-/**
- * Implements hook_form_FORM_ID_alter().
- */
-function token_form_block_admin_configure_alter(&$form, $form_state) {
-  $form['settings']['title']['#description'] .= ' ' . t('This field supports tokens.');
+function token_form_block_form_alter(&$form, &$form_state) {
+  $form['settings']['label']['#description'] = t('This field supports tokens.');
   // @todo Figure out why this token validation does not seem to be working here.
-  $form['settings']['title']['#element_validate'][] = 'token_element_validate';
-  $form['settings']['title'] += array('#token_types' => array());
+  $form['settings']['label']['#element_validate'][] = 'token_element_validate';
+  $form['settings']['label'] += array('#token_types' => array());
 }
 
 /**
-- 
1.9.3 (Apple Git-50)


From 2aea5448465d5082c14b93d9955fac9561dd4966 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 11 Jun 2014 01:24:54 +0200
Subject: [PATCH 152/230] Remove token info caching, use render/data cache
 bins, remove cache_token

---
 token.module       | 64 ++++++++++++++++++++++--------------------------------
 token.pages.inc    |  1 -
 token.services.yml |  7 ------
 3 files changed, 26 insertions(+), 46 deletions(-)

diff --git a/token.module b/token.module
index 0617f92..3e93fa2 100644
--- a/token.module
+++ b/token.module
@@ -304,9 +304,7 @@ function token_field_delete_instance($instance) {
  * Clear token caches and static variables.
  */
 function token_clear_cache() {
-  if (db_table_exists('cache_token')) {
-    \Drupal::cache('cache_token')->flush();
-  }
+  \Drupal::token()->resetInfo();
   drupal_static_reset('token_get_info');
   drupal_static_reset('token_get_global_token_types');
   drupal_static_reset('token_get_entity_mapping');
@@ -435,40 +433,30 @@ function token_get_info($token_type = NULL, $token = NULL) {
   $token_info = &$drupal_static_fast['token_info'];
 
   if (empty($token_info)) {
-    $langcode = \Drupal::languageManager()->getCurrentLanguage()->id;
-    $cid = "info:{$langcode}";
-
-    if ($cache = \Drupal::cache('cache_token')->get($cid)) {
-      $token_info = $cache->data;
-    }
-    else {
-      $token_info = \Drupal::token()->getInfo();
-
-      foreach (array_keys($token_info['types']) as $type_key) {
-        if (isset($token_info['types'][$type_key]['type'])) {
-          $base_type = $token_info['types'][$type_key]['type'];
-          // If this token type extends another token type, then merge in
-          // the base token type's tokens.
-          if (isset($token_info['tokens'][$base_type])) {
-            $token_info['tokens'] += array($type_key => array());
-            $token_info['tokens'][$type_key] += $token_info['tokens'][$base_type];
-          }
-        }
-        else {
-          // Add a 'type' value to each token type so we can properly use
-          // token_type_load().
-          $token_info['types'][$type_key]['type'] = $type_key;
+    $token_info = \Drupal::token()->getInfo();
+
+    // @todo: Move this into the token service and deprecate this function.
+    foreach (array_keys($token_info['types']) as $type_key) {
+      if (isset($token_info['types'][$type_key]['type'])) {
+        $base_type = $token_info['types'][$type_key]['type'];
+        // If this token type extends another token type, then merge in
+        // the base token type's tokens.
+        if (isset($token_info['tokens'][$base_type])) {
+          $token_info['tokens'] += array($type_key => array());
+          $token_info['tokens'][$type_key] += $token_info['tokens'][$base_type];
         }
       }
-
-      // Pre-sort tokens.
-      uasort($token_info['types'], 'token_asort_tokens');
-      foreach (array_keys($token_info['tokens']) as $type) {
-        uasort($token_info['tokens'][$type], 'token_asort_tokens');
+      else {
+        // Add a 'type' value to each token type so we can properly use
+        // token_type_load().
+        $token_info['types'][$type_key]['type'] = $type_key;
       }
+    }
 
-      // Store info in cache for future use.
-      \Drupal::cache('cache_token')->set($cid, $token_info);
+    // Pre-sort tokens.
+    uasort($token_info['types'], 'token_asort_tokens');
+    foreach (array_keys($token_info['tokens']) as $type) {
+      uasort($token_info['tokens'][$type], 'token_asort_tokens');
     }
   }
 
@@ -829,18 +817,18 @@ function token_build_tree($token_type, array $options = array()) {
   }
 
   $langcode = \Drupal::languageManager()->getCurrentLanguage()->id;
-  $tree_cid = "tree:{$token_type}:{$langcode}:{$options['depth']}";
+  $tree_cid = "token_tree:{$token_type}:{$langcode}:{$options['depth']}";
 
-  // If we do not have this base tree in the static cache, check {cache_token}
+  // If we do not have this base tree in the static cache, check the cache
   // otherwise generate and store it in the cache.
   if (!isset($trees[$tree_cid])) {
-    if ($cache = \Drupal::cache('cache_token')->get($tree_cid)) {
+    if ($cache = \Drupal::cache('data')->get($tree_cid)) {
       $trees[$tree_cid] = $cache->data;
     }
     else {
       $options['parents'] = array();
       $trees[$tree_cid] = _token_build_tree($token_type, $options);
-      \Drupal::cache('cache_token')->set($tree_cid, $trees[$tree_cid]);
+      \Drupal::cache('data')->set($tree_cid, $trees[$tree_cid]);
     }
   }
 
@@ -1080,7 +1068,7 @@ function token_render_cache_get($elements) {
   if (!$cid = drupal_render_cid_create($elements)) {
     return FALSE;
   }
-  $bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache';
+  $bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'render';
 
   if (!empty($cid) && $cache = \Drupal::cache($bin)->get($cid)) {
     // Add additional libraries, JavaScript, CSS and other data attached
diff --git a/token.pages.inc b/token.pages.inc
index dbc64a2..c48c5aa 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -108,7 +108,6 @@ function theme_token_tree($variables) {
   $element = array(
     '#cache' => array(
       'cid' => 'tree-rendered:' . hash('sha256', serialize(array('token_types' => $token_types, 'global_types' => NULL) + $variables)),
-      'bin' => 'cache_token',
     ),
   );
   if ($cached_output = token_render_cache_get($element)) {
diff --git a/token.services.yml b/token.services.yml
index 71fe59b..0baad47 100644
--- a/token.services.yml
+++ b/token.services.yml
@@ -1,8 +1 @@
 services:
-  cache.cache_token:
-    class: Drupal\Core\Cache\CacheBackendInterface
-    tags:
-      - { name: cache.bin }
-    factory_method: get
-    factory_service: cache_factory
-    arguments: [cache_token]
-- 
1.9.3 (Apple Git-50)


From 48fb666e0edd47f7ad13d8d80d9cc1f6e9a27ce2 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 11 Jun 2014 01:25:13 +0200
Subject: [PATCH 153/230] Fixed hook_help(), avoid notice.

---
 token.module    | 5 +++--
 token.pages.inc | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/token.module b/token.module
index 3e93fa2..d4ddd3e 100644
--- a/token.module
+++ b/token.module
@@ -8,6 +8,7 @@
 use Drupal\Component\Utility\String;
 use Drupal\Component\Utility\Xss;
 use Drupal\Core\Render\Element;
+use Symfony\Component\HttpFoundation\Request;
 
 /**
  * The maximum depth for token tree recursion.
@@ -17,8 +18,8 @@ define('TOKEN_MAX_DEPTH', 9);
 /**
  * Implements hook_help().
  */
-function token_help($path, $arg) {
-  if ($path == 'admin/help#token') {
+function token_help($route_name, Request $request) {
+  if ($route_name == 'help.page.token') {
     if (current_path() != 'admin/help/token') {
       // Because system_modules() executes hook_help() for each module to 'test'
       // if they will return anything, but not actually display it, we want to
diff --git a/token.pages.inc b/token.pages.inc
index c48c5aa..fde63ae 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -194,7 +194,7 @@ function _token_token_tree_format_row($token, array $token_info, $is_group = FAL
   $row = $defaults;
   $row['id'] = _token_clean_css_identifier($token);
   $row['data']['name'] = $token_info['name'];
-  $row['data']['description'] = $token_info['description'];
+  $row['data']['description'] = isset($token_info['description']) ? $token_info['description'] : '';
 
   if ($is_group) {
     // This is a token type/group.
-- 
1.9.3 (Apple Git-50)


From 3a5f0819d99918ab947b6e0fd8fa7f2a9f731be9 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 11 Jun 2014 01:43:10 +0200
Subject: [PATCH 154/230] Fixing tests

---
 src/Tests/TokenBlockTestCase.php                     | 20 ++++++++++----------
 src/Tests/TokenMenuTestCase.php                      |  2 +-
 src/Tests/TokenNodeTestCase.php                      |  2 +-
 src/Tests/TokenTestBase.php                          |  2 +-
 src/Tests/TokenUserTestCase.php                      |  3 ++-
 .../{ => install}/system.date_format.token_test.yml  |  0
 token.module                                         |  4 ++--
 token.tokens.inc                                     | 17 +++++++++--------
 8 files changed, 26 insertions(+), 24 deletions(-)
 rename tests/token_test/config/{ => install}/system.date_format.token_test.yml (100%)

diff --git a/src/Tests/TokenBlockTestCase.php b/src/Tests/TokenBlockTestCase.php
index f656b7a..367c0fe 100644
--- a/src/Tests/TokenBlockTestCase.php
+++ b/src/Tests/TokenBlockTestCase.php
@@ -39,27 +39,27 @@ class TokenBlockTestCase extends TokenTestBase {
     ));
     $bundle->save();
 
-    $block = BlockContent::create(array(
+    $block_content = BlockContent::create(array(
       'type' => $label,
-      'label' => '[user:name]',
+      'label' => '[current-page:title] block title',
       'info' => 'Test token title block',
       'body[value]' => 'This is the test token title block.',
     ));
-    $block->save();
+    $block_content->save();
+
+    $block = $this->drupalPlaceBlock('block_content:' . $block_content->uuid(), array(
+      'label' => '[user:name]',
+    ));
     $this->drupalGet($block->getSystemPath());
     // Ensure token validation is working on the block.
     $this->assertText('The Block title is using the following invalid tokens: [user:name].');
 
     // Create the block for real now with a valid title.
-    $block->label = '[current-page:title] block title';
+    $settings = $block->get('settings');
+    $settings['label'] = '[current-page:title] block title';
+    $block->set('settings', $settings);
     $block->save();
 
-
-
-    $this->drupalPlaceBlock('custom_block:' . $block->uuid(), array(
-      'label' => '[current-page:title] block title',
-    ));
-
     // Ensure that tokens are not double-escaped when output as a block title.
     $node = $this->drupalCreateNode(array('title' => "Site's first node"));
     $this->drupalGet('node/' . $node->id());
diff --git a/src/Tests/TokenMenuTestCase.php b/src/Tests/TokenMenuTestCase.php
index 08b4ab3..19218b7 100644
--- a/src/Tests/TokenMenuTestCase.php
+++ b/src/Tests/TokenMenuTestCase.php
@@ -12,7 +12,7 @@ namespace Drupal\token\Tests;
  * @group Token
  */
 class TokenMenuTestCase extends TokenTestBase {
-  protected static $modules = array('path', 'token', 'token_test', 'menu', 'node');
+  protected static $modules = array('path', 'token', 'token_test', 'menu_ui', 'node');
 
   public static function getInfo() {
     return array(
diff --git a/src/Tests/TokenNodeTestCase.php b/src/Tests/TokenNodeTestCase.php
index d16a6e4..ec7173f 100644
--- a/src/Tests/TokenNodeTestCase.php
+++ b/src/Tests/TokenNodeTestCase.php
@@ -27,7 +27,7 @@ class TokenNodeTestCase extends TokenTestBase {
     $tokens = array(
       'source' => NULL,
       'source:nid' => NULL,
-      'log' => $source_node->log->value,
+      'log' => $source_node->revision_log->value,
       'url:path' => 'content/source-node',
       'url:absolute' => url("node/{$source_node->id()}", array('absolute' => TRUE)),
       'url:relative' => url("node/{$source_node->id()}", array('absolute' => FALSE)),
diff --git a/src/Tests/TokenTestBase.php b/src/Tests/TokenTestBase.php
index 11bdb62..fb90a2b 100644
--- a/src/Tests/TokenTestBase.php
+++ b/src/Tests/TokenTestBase.php
@@ -68,7 +68,7 @@ class TokenTestBase extends WebTestBase {
       'alias' => $alias,
       'language' => $language,
     );
-    \Drupal::service('path.crud')->save($alias['source'], $alias['alias']);
+    \Drupal::service('path.alias_storage')->save($alias['source'], $alias['alias']);
     return $alias;
   }
 
diff --git a/src/Tests/TokenUserTestCase.php b/src/Tests/TokenUserTestCase.php
index fe7c151..0d37571 100644
--- a/src/Tests/TokenUserTestCase.php
+++ b/src/Tests/TokenUserTestCase.php
@@ -5,6 +5,7 @@
  * Contains \Drupal\token\Tests\TokenUserTestCase.
  */
 namespace Drupal\token\Tests;
+use Drupal\field\Entity\FieldConfig;
 use Drupal\field\Field;
 
 /**
@@ -64,7 +65,7 @@ class TokenUserTestCase extends TokenTestBase {
     $this->assertTokens('user', array('user' => $this->account), $user_tokens);
 
     // Remove the user picture field.
-    Field::fieldInfo()->getField('user', 'user_picture')->delete();
+    FieldConfig::loadByName('user', 'user_picture')->delete();
 
     // Remove the simpletest-created user role.
     $roles = $this->account->getRoles();
diff --git a/tests/token_test/config/system.date_format.token_test.yml b/tests/token_test/config/install/system.date_format.token_test.yml
similarity index 100%
rename from tests/token_test/config/system.date_format.token_test.yml
rename to tests/token_test/config/install/system.date_format.token_test.yml
diff --git a/token.module b/token.module
index d4ddd3e..4de9a09 100644
--- a/token.module
+++ b/token.module
@@ -39,7 +39,7 @@ function token_help($route_name, Request $request) {
  * Return an array of the core modules supported by token.module.
  */
 function _token_core_supported_modules() {
-  return array('book', 'field', 'menu', 'profile');
+  return array('book', 'field', 'menu_ui');
 }
 
 /**
@@ -1162,7 +1162,7 @@ function token_node_menu_link_load($node) {
       // @see http://drupal.org/node/1317926
       $menu_node = clone $node;
       $form_state = array();
-      menu_node_prepare_form($menu_node, NULL, $form_state);
+      menu_ui_node_prepare_form($menu_node, NULL, $form_state);
       $mlid = !empty($menu_node->menu['mlid']) ? $menu_node->menu['mlid'] : FALSE;
     }
     else {
diff --git a/token.tokens.inc b/token.tokens.inc
index fb51a35..e3987d3 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -12,6 +12,7 @@ use Drupal\Component\Utility\Xss;
 use Drupal\field\Entity\FieldConfig;
 use Drupal\field\FieldConfigInterface;
 use Drupal\field\FieldInstanceConfigInterface;
+use Drupal\system\Entity\Menu;
 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
 
 /**
@@ -430,7 +431,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
           }
           break;
         case 'log':
-          $replacements[$original] = $sanitize ? Xss::filter($node->log->value) : $node->log->value;
+          $replacements[$original] = $sanitize ? Xss::filter($node->revision_log->value) : $node->revision_log->value;
           break;
         case 'content-type':
           $type_name = \Drupal::entityManager()->getStorage('node_type')->load($node->getType())->label();
@@ -694,7 +695,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
     if ($arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'arg')) {
       $path = \Drupal::request()->attributes->get('_system_path');
       // Make sure its a system path.
-      $path = \Drupal::service('path.alias_manager')->getSystemPath($path);
+      $path = \Drupal::service('path.alias_manager')->getPathByAlias($path);
       foreach ($arg_tokens as $name => $original) {
         if (is_numeric($name) && ($arg = arg($name, $path)) && isset($arg)) {
           $replacements[$original] = $sanitize ? String::checkPlain($arg) : $arg;
@@ -1050,9 +1051,9 @@ function book_tokens($type, $tokens, array $data = array(), array $options = arr
 }
 
 /**
- * Implements hook_token_info() on behalf of menu.module.
+ * Implements hook_token_info() on behalf of menu_ui.module.
  */
-function menu_token_info() {
+function menu_ui_token_info() {
   // Menu tokens.
   $info['types']['menu'] = array(
     'name' => t('Menus'),
@@ -1099,9 +1100,9 @@ function menu_token_info() {
 }
 
 /**
- * Implements hook_tokens() on behalf of menu.module.
+ * Implements hook_tokens() on behalf of menu_ui.module.
  */
-function menu_tokens($type, $tokens, array $data = array(), array $options = array()) {
+function menu_ui_tokens($type, $tokens, array $data = array(), array $options = array()) {
   $replacements = array();
 
   $url_options = array('absolute' => TRUE);
@@ -1144,7 +1145,7 @@ function menu_tokens($type, $tokens, array $data = array(), array $options = arr
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'menu':
-          if ($menu = menu_load($link->bundle())) {
+          if ($menu = Menu::load($link->bundle())) {
             $replacements[$original] = $sanitize ? String::checkPlain($menu->label()) : $menu->label();
           }
           break;
@@ -1155,7 +1156,7 @@ function menu_tokens($type, $tokens, array $data = array(), array $options = arr
     }
 
     // Chained token relationships.
-    if (($menu_tokens = \Drupal::token()->findWithPrefix($tokens, 'menu')) && $menu = menu_load($link->bundle())) {
+    if (($menu_tokens = \Drupal::token()->findWithPrefix($tokens, 'menu')) && $menu = Menu::load($link->bundle())) {
       $replacements += \Drupal::token()->generate('menu', $menu_tokens, array('menu' => $menu), $options);
     }
   }
-- 
1.9.3 (Apple Git-50)


From 7e0b083a21b4d6747ef814847717e673e90df41f Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 11 Jun 2014 02:24:54 +0200
Subject: [PATCH 155/230] Working on the token dialog.

---
 js/token.js                            | 32 -------------------------
 src/Controller/TokenTreeController.php | 37 ++++++++++++++++++++++++++++
 token.libraries.yml                    |  6 +++--
 token.module                           | 22 -----------------
 token.pages.inc                        | 44 ++++++++++------------------------
 token.routing.yml                      |  7 ++++++
 6 files changed, 61 insertions(+), 87 deletions(-)
 create mode 100644 src/Controller/TokenTreeController.php

diff --git a/js/token.js b/js/token.js
index 98d1ac3..59715f4 100644
--- a/js/token.js
+++ b/js/token.js
@@ -9,38 +9,6 @@ Drupal.behaviors.tokenTree = {
   }
 };
 
-Drupal.behaviors.tokenDialog = {
-  attach: function (context, settings) {
-    $('a.token-dialog', context).once('token-dialog').click(function() {
-      var url = $(this).attr('href');
-      var dialog = $('<div style="display: none" class="loading">' + Drupal.t('Loading token browser...') + '</div>').appendTo('body');
-
-      // Emulate the AJAX data sent normally so that we get the same theme.
-      var data = {};
-      data['ajax_page_state[theme]'] = Drupal.settings.ajaxPageState.theme;
-      data['ajax_page_state[theme_token]'] = Drupal.settings.ajaxPageState.theme_token;
-
-      dialog.dialog({
-        title: $(this).attr('title') || Drupal.t('Available tokens'),
-        width: 700,
-        close: function(event, ui) {
-          dialog.remove();
-        }
-      });
-      // Load the token tree using AJAX.
-      dialog.load(
-        url,
-        data,
-        function (responseText, textStatus, XMLHttpRequest) {
-          dialog.removeClass('loading');
-        }
-      );
-      // Prevent browser from following the link.
-      return false;
-    });
-  }
-}
-
 Drupal.behaviors.tokenInsert = {
   attach: function (context, settings) {
     // Keep track of which textfield was last selected/focused.
diff --git a/src/Controller/TokenTreeController.php b/src/Controller/TokenTreeController.php
new file mode 100644
index 0000000..639ad68
--- /dev/null
+++ b/src/Controller/TokenTreeController.php
@@ -0,0 +1,37 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Controller\TokenAutocompleteController.
+ */
+
+namespace Drupal\token\Controller;
+
+use Drupal\Component\Serialization\Json;
+use Drupal\Core\Ajax\AjaxResponse;
+use Drupal\Core\Ajax\OpenModalDialogCommand;
+use Drupal\Core\Controller\ControllerBase;
+use Symfony\Component\HttpFoundation\Response;
+
+/**
+ * Returns tree responses for tokens.
+ */
+class TokenTreeController extends ControllerBase {
+
+  /**
+   * Page callback to output a token tree as an empty page.
+   */
+  function outputTree() {
+    $build['#title'] = $this->t('Available tokens');
+
+    $options = isset($_GET['options']) ? Json::decode($_GET['options']) : array();
+
+    // Force the dialog option to be false so we're not creating a dialog within
+    // a dialog.
+    $options['dialog'] = FALSE;
+    $build['tree']['#markup'] = _theme('token_tree', $options);
+
+    return $build;
+  }
+
+}
diff --git a/token.libraries.yml b/token.libraries.yml
index 65c9c48..603e429 100644
--- a/token.libraries.yml
+++ b/token.libraries.yml
@@ -9,10 +9,12 @@ jquery.treeTable:
   dependencies:
     - core/jquery
 token:
-  version: 1.0
+  version: VERSION
   js:
     js/token.js: {}
+  css:
+    component:
+      css/token.css: {}
   dependencies:
     - core/jquery
     - core/drupal
-    - core/jquery.ui.dialog
diff --git a/token.module b/token.module
index 4de9a09..6c935bc 100644
--- a/token.module
+++ b/token.module
@@ -46,28 +46,6 @@ function _token_core_supported_modules() {
  * Implements hook_menu().
  */
 function token_menu() {
-  /*$items['token/autocomplete/all/%menu_tail'] = array(
-    'page callback' => 'token_autocomplete',
-    'access callback' => TRUE,
-    'type' => MENU_CALLBACK,
-    'file' => 'token.pages.inc',
-  );*/
-
-  /*$items['token/autocomplete/%token_type/%menu_tail'] = array(
-    'page callback' => 'token_autocomplete_token',
-    'page arguments' => array(2, 3),
-    'access callback' => TRUE,
-    'type' => MENU_CALLBACK,
-    'file' => 'token.pages.inc',
-  );*/
-
-  $items['token/tree'] = array(
-    'page callback' => 'token_page_output_tree',
-    'access callback' => TRUE,
-    'type' => MENU_CALLBACK,
-    'file' => 'token.pages.inc',
-    'theme callback' => 'ajax_base_page_theme',
-  );
 
   // Devel token pages.
   if (\Drupal::moduleHandler()->moduleExists('devel')) {
diff --git a/token.pages.inc b/token.pages.inc
index fde63ae..7ac6f4d 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -4,6 +4,7 @@
  * @file
  * User page callbacks for the token module.
  */
+use Drupal\Component\Serialization\Json;
 
 /**
  * Theme a link to a token tree either as a regular link or a dialog.
@@ -15,7 +16,7 @@ function theme_token_tree_link($variables) {
 
   if (!empty($variables['dialog'])) {
     // @todo Move this somewhere it can use #attached.
-    _drupal_add_library('token/token');
+    _drupal_add_library('core/drupal.ajax');
     $variables['options']['attributes']['class'][] = 'token-dialog';
   }
 
@@ -26,41 +27,22 @@ function theme_token_tree_link($variables) {
   // used for this function.
   unset($variables['options']['query']['options']['dialog']);
 
-  // Add a security token so that the tree page should only work when used
-  // when the dialog link is output with theme('token_tree_link').
-  $variables['options']['query']['token'] = drupal_get_token('token-tree:' . serialize($variables['options']['query']['options']));
-
   // Because PHP converts query strings with arrays into a different syntax on
   // the next request, the options have to be encoded with JSON in the query
   // string so that we can reliably decode it for token comparison.
-  $variables['options']['query']['options'] = drupal_json_encode($variables['options']['query']['options']);
+  $variables['options']['query']['options'] = Json::encode($variables['options']['query']['options']);
 
   // Set the token tree to open in a separate window.
-  $variables['options']['attributes'] + array('target' => '_blank');
-
-  return l($variables['text'], 'token/tree', $variables['options']);
-}
-
-/**
- * Page callback to output a token tree as an empty page.
- */
-function token_page_output_tree() {
-  $options = isset($_GET['options']) ? drupal_json_decode($_GET['options']) : array();
-
-  // Check the token against the serialized options to prevent random access to
-  // the token browser page.
-  if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], 'token-tree:' . serialize($options))) {
-    return MENU_ACCESS_DENIED;
-  }
-
-  // Force the dialog option to be false so we're not creating a dialog within
-  // a dialog.
-  $options['dialog'] = FALSE;
-
-  $output = theme('token_tree', $options);
-  print '<html><head>' . drupal_get_css() . drupal_get_js() . '</head>';
-  print '<body class="token-tree">' . $output . '</body></html>';
-  drupal_exit();
+  $variables['options']['attributes'] += array(
+    'data-accepts' => 'application/vnd.drupal-dialog',
+    'data-dialog-options' => json_encode(array(
+      'width' => 400,
+      'draggable' => TRUE,
+    )),
+   );
+  $variables['options']['attributes']['class'][] = 'use-ajax';
+
+  return Drupal::l($variables['text'], 'token.tree', array(), $variables['options']);
 }
 
 /**
diff --git a/token.routing.yml b/token.routing.yml
index d1ea305..467122e 100644
--- a/token.routing.yml
+++ b/token.routing.yml
@@ -1,3 +1,10 @@
+token.tree:
+  path: '/token/tree'
+  defaults:
+    _content: '\Drupal\token\Controller\TokenTreeController::outputTree'
+  requirements:
+    _csrf_token: 'TRUE'
+
 token.autocomplete:
   path: '/token/autocomplete/{token_type}/{filter}'
   defaults:
-- 
1.9.3 (Apple Git-50)


From 36687e5f770dd9f42fad664c301d4dc78fb7ca5e Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 11 Jun 2014 02:35:07 +0200
Subject: [PATCH 156/230] Fix Contains, use Request and use _theme() for the
 theme function.

---
 src/Controller/TokenTreeController.php | 10 ++++------
 token.pages.inc                        |  2 +-
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/src/Controller/TokenTreeController.php b/src/Controller/TokenTreeController.php
index 639ad68..e9d40db 100644
--- a/src/Controller/TokenTreeController.php
+++ b/src/Controller/TokenTreeController.php
@@ -2,16 +2,14 @@
 
 /**
  * @file
- * Contains \Drupal\token\Controller\TokenAutocompleteController.
+ * Contains \Drupal\token\Controller\TokenTreeController.
  */
 
 namespace Drupal\token\Controller;
 
 use Drupal\Component\Serialization\Json;
-use Drupal\Core\Ajax\AjaxResponse;
-use Drupal\Core\Ajax\OpenModalDialogCommand;
 use Drupal\Core\Controller\ControllerBase;
-use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpFoundation\Request;
 
 /**
  * Returns tree responses for tokens.
@@ -21,10 +19,10 @@ class TokenTreeController extends ControllerBase {
   /**
    * Page callback to output a token tree as an empty page.
    */
-  function outputTree() {
+  function outputTree(Request $request) {
     $build['#title'] = $this->t('Available tokens');
 
-    $options = isset($_GET['options']) ? Json::decode($_GET['options']) : array();
+    $options = $request->attributes->has('options') ? Json::decode($request->attributes->get('options')) : array();
 
     // Force the dialog option to be false so we're not creating a dialog within
     // a dialog.
diff --git a/token.pages.inc b/token.pages.inc
index 7ac6f4d..457cbf9 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -74,7 +74,7 @@ function theme_tree_table($variables) {
  */
 function theme_token_tree($variables) {
   if (!empty($variables['dialog'])) {
-    return theme_token_tree_link($variables);
+    return _theme('token_tree_link', $variables);
   }
 
   $token_types = $variables['token_types'];
-- 
1.9.3 (Apple Git-50)


From ed31d0003ea8c0d6fb9528ed6219f02c77f8e0c8 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 11 Jun 2014 03:02:12 +0200
Subject: [PATCH 157/230] Fixed the token clicking.

---
 js/token.js     | 8 ++++----
 token.pages.inc | 8 +++++---
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/js/token.js b/js/token.js
index 59715f4..1045221 100644
--- a/js/token.js
+++ b/js/token.js
@@ -13,16 +13,16 @@ Drupal.behaviors.tokenInsert = {
   attach: function (context, settings) {
     // Keep track of which textfield was last selected/focused.
     $('textarea, input[type="text"]', context).focus(function() {
-      Drupal.settings.tokenFocusedField = this;
+      drupalSettings.tokenFocusedField = this;
     });
 
     $('.token-click-insert .token-key', context).once('token-click-insert', function() {
       var newThis = $('<a href="javascript:void(0);" title="' + Drupal.t('Insert this token into your form') + '">' + $(this).html() + '</a>').click(function(){
-        if (typeof Drupal.settings.tokenFocusedField == 'undefined') {
+        if (typeof drupalSettings.tokenFocusedField == 'undefined') {
           alert(Drupal.t('First click a text field to insert your tokens into.'));
         }
         else {
-          var myField = Drupal.settings.tokenFocusedField;
+          var myField = drupalSettings.tokenFocusedField;
           var myValue = $(this).text();
 
           //IE support
@@ -52,4 +52,4 @@ Drupal.behaviors.tokenInsert = {
   }
 };
 
-})(jQuery);
+})(jQuery, drupalSettings);
diff --git a/token.pages.inc b/token.pages.inc
index 457cbf9..43c7174 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -16,7 +16,8 @@ function theme_token_tree_link($variables) {
 
   if (!empty($variables['dialog'])) {
     // @todo Move this somewhere it can use #attached.
-    _drupal_add_library('core/drupal.ajax');
+    _drupal_add_library('core/drupal.dialog.ajax');
+    _drupal_add_library('token/token');
     $variables['options']['attributes']['class'][] = 'token-dialog';
   }
 
@@ -36,8 +37,9 @@ function theme_token_tree_link($variables) {
   $variables['options']['attributes'] += array(
     'data-accepts' => 'application/vnd.drupal-dialog',
     'data-dialog-options' => json_encode(array(
-      'width' => 400,
-      'draggable' => TRUE,
+      'width' => 600,
+      'height' => 400,
+      'position' => array('my' => 'right bottom', 'at' => 'right bottom'),
     )),
    );
   $variables['options']['attributes']['class'][] = 'use-ajax';
-- 
1.9.3 (Apple Git-50)


From 9eeda5654cb61dc507f6dd3a8af2da636d687276 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 11 Jun 2014 03:07:33 +0200
Subject: [PATCH 158/230] Added cache tags to clear token tree caches when the
 token cache is cleared.

---
 token.module    | 4 +++-
 token.pages.inc | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/token.module b/token.module
index 6c935bc..aebcf80 100644
--- a/token.module
+++ b/token.module
@@ -7,7 +7,9 @@
 
 use Drupal\Component\Utility\String;
 use Drupal\Component\Utility\Xss;
+use Drupal\Core\Cache\Cache;
 use Drupal\Core\Render\Element;
+use Drupal\Core\Utility\Token;
 use Symfony\Component\HttpFoundation\Request;
 
 /**
@@ -807,7 +809,7 @@ function token_build_tree($token_type, array $options = array()) {
     else {
       $options['parents'] = array();
       $trees[$tree_cid] = _token_build_tree($token_type, $options);
-      \Drupal::cache('data')->set($tree_cid, $trees[$tree_cid]);
+      \Drupal::cache('data')->set($tree_cid, $trees[$tree_cid], Cache::PERMANENT, array(Token::TOKEN_INFO_CACHE_TAG => TRUE));
     }
   }
 
diff --git a/token.pages.inc b/token.pages.inc
index 43c7174..02e446f 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -5,6 +5,7 @@
  * User page callbacks for the token module.
  */
 use Drupal\Component\Serialization\Json;
+use Drupal\Core\Utility\Token;
 
 /**
  * Theme a link to a token tree either as a regular link or a dialog.
@@ -92,6 +93,7 @@ function theme_token_tree($variables) {
   $element = 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 => TRUE),
     ),
   );
   if ($cached_output = token_render_cache_get($element)) {
-- 
1.9.3 (Apple Git-50)


From 8a2d9d8284e7e7890780939f2f54d0b3b9db66c5 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 11 Jun 2014 03:13:17 +0200
Subject: [PATCH 159/230] Use #theme for the token tree.

---
 src/Controller/TokenTreeController.php | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/Controller/TokenTreeController.php b/src/Controller/TokenTreeController.php
index e9d40db..de9bddd 100644
--- a/src/Controller/TokenTreeController.php
+++ b/src/Controller/TokenTreeController.php
@@ -27,7 +27,12 @@ class TokenTreeController extends ControllerBase {
     // Force the dialog option to be false so we're not creating a dialog within
     // a dialog.
     $options['dialog'] = FALSE;
-    $build['tree']['#markup'] = _theme('token_tree', $options);
+
+    // Build a render array with the options.
+    foreach ($options as $key => $value) {
+      $build['tree']['#' . $key] = $value;
+    }
+    $build['tree']['#theme'] = 'token_tree';
 
     return $build;
   }
-- 
1.9.3 (Apple Git-50)


From e992a8c91d13cd8438687bf877a992fdec132938 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 11 Jun 2014 08:11:23 +0200
Subject: [PATCH 160/230] Use ->query instead of ->attributes

---
 src/Controller/TokenTreeController.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Controller/TokenTreeController.php b/src/Controller/TokenTreeController.php
index de9bddd..3e2c39c 100644
--- a/src/Controller/TokenTreeController.php
+++ b/src/Controller/TokenTreeController.php
@@ -22,7 +22,7 @@ class TokenTreeController extends ControllerBase {
   function outputTree(Request $request) {
     $build['#title'] = $this->t('Available tokens');
 
-    $options = $request->attributes->has('options') ? Json::decode($request->attributes->get('options')) : array();
+    $options = $request->query->has('options') ? Json::decode($request->query->get('options')) : array();
 
     // Force the dialog option to be false so we're not creating a dialog within
     // a dialog.
-- 
1.9.3 (Apple Git-50)


From ad70053623bf88846a3910fc88d3363948600eb5 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 11 Jun 2014 14:54:49 +0200
Subject: [PATCH 161/230] position and draggable needs autoResize.

---
 token.pages.inc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/token.pages.inc b/token.pages.inc
index 02e446f..1f180a1 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -41,6 +41,8 @@ function theme_token_tree_link($variables) {
       'width' => 600,
       'height' => 400,
       'position' => array('my' => 'right bottom', 'at' => 'right bottom'),
+      'draggable' => TRUE,
+      'autoResize' => FALSE,
     )),
    );
   $variables['options']['attributes']['class'][] = 'use-ajax';
-- 
1.9.3 (Apple Git-50)


From 0e505f56a575e6367df1b6b4cbdaa132d63fb47d Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Thu, 19 Jun 2014 18:40:33 -0500
Subject: [PATCH 162/230] Issue #2289203 by Dave Reid | eojthebrave: Fixed
 theme_token_tree_link did not actually support the same variables as
 theme_token_tree, but should have.

---
 token.module    | 2 +-
 token.pages.inc | 7 ++++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/token.module b/token.module
index 926db6d..ce4495a 100644
--- a/token.module
+++ b/token.module
@@ -180,7 +180,7 @@ function token_theme() {
       'text' => NULL,
       'options' => array(),
       'dialog' => TRUE,
-    ),
+    ) + $info['token_tree']['variables'],
     'file' => 'token.pages.inc',
   );
 
diff --git a/token.pages.inc b/token.pages.inc
index 2341a9f..f761547 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -19,7 +19,12 @@ function theme_token_tree_link($variables) {
   }
 
   $info = token_theme();
-  $variables['options']['query']['options'] = array_intersect_key($variables, $info['token_tree']['variables']);
+  $tree_variables = array_intersect_key($variables, $info['token_tree']['variables']);
+  $tree_variables = drupal_array_diff_assoc_recursive($tree_variables, $info['token_tree']['variables']);
+  if (!isset($variables['options']['query']['options'])) {
+    $variables['options']['query']['options'] = array();
+  }
+  $variables['options']['query']['options'] += $tree_variables;
 
   // We should never pass the dialog option to theme_token_tree(). It is only
   // used for this function.
-- 
1.9.3 (Apple Git-50)


From f4167850740cbeeb0e53d1eca7caecb3f2ee0059 Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Thu, 19 Jun 2014 18:47:31 -0500
Subject: [PATCH 163/230] Issue #1938672 by Dane Powell, tatyana: Fixed field
 help token replacement should run on the original field description, not the
 already sanitized string.

---
 token.module | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/token.module b/token.module
index ce4495a..4dbb271 100644
--- a/token.module
+++ b/token.module
@@ -273,8 +273,8 @@ function token_form_block_admin_configure_alter(&$form, $form_state) {
  * Implements hook_widget_form_alter().
  */
 function token_field_widget_form_alter(&$element, &$form_state, $context) {
-  if (!empty($element['#description']) && is_string($element['#description'])) {
-    $element['#description'] = filter_xss_admin(token_replace($element['#description']));
+  if (!empty($element['#description']) && !empty($context['instance']['description'])) {
+    $element['#description'] = filter_xss_admin(token_replace($context['instance']['description']));
   }
 }
 
-- 
1.9.3 (Apple Git-50)


From 49db17816243441544fa09847276e626b02ba4e6 Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Thu, 19 Jun 2014 18:49:29 -0500
Subject: [PATCH 164/230] Issue #2182229 by davidneedham: Updated README.

---
 README.txt | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/README.txt b/README.txt
index 230774e..d393fb2 100644
--- a/README.txt
+++ b/README.txt
@@ -1,2 +1,33 @@
+INTRODUCTION
+------------
 
 Provides common and resuable token UI elements and missing core tokens.
+
+ * For a full description of the module, visit the project page:
+   https://drupal.org/project/token
+
+ * To submit bug reports and feature suggestions, or to track changes:
+   https://drupal.org/project/issues/token
+
+
+INSTALLATION
+------------
+
+Install as usual, see
+https://drupal.org/documentation/install/modules-themes/modules-7 for further
+information.
+
+
+TROUBLESHOOTING
+---------------
+
+Token module doesn't provide any visible functions to the user on its own, it
+just provides token handling services for other modules.
+
+
+MAINTAINERS
+-----------
+
+Current maintainers:
+
+ * Dave Reid (https://drupal.org/user/53892)
\ No newline at end of file
-- 
1.9.3 (Apple Git-50)


From e9391c125521523d36e27ad86328b72e0e1b8ca3 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Tue, 24 Jun 2014 17:48:04 +0200
Subject: [PATCH 165/230] Fix TokenCacheController

---
 src/Controller/TokenCacheController.php | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/Controller/TokenCacheController.php b/src/Controller/TokenCacheController.php
index c101928..589d595 100644
--- a/src/Controller/TokenCacheController.php
+++ b/src/Controller/TokenCacheController.php
@@ -7,6 +7,8 @@
 
 namespace Drupal\token\Controller;
 
+use Drupal\Core\Controller\ControllerBase;
+use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\HttpFoundation\Request;
@@ -14,7 +16,7 @@ use Symfony\Component\HttpFoundation\Request;
 /**
  * Clears cache for tokens.
  */
-class TokenCacheController implements ContainerInjectionInterface{
+class TokenCacheController extends ControllerBase implements ContainerInjectionInterface  {
 
   /**
    * @var \Drupal\Core\Access\CsrfTokenGenerator
-- 
1.9.3 (Apple Git-50)


From cfb9522923cb20c6f22942df64550554a940e2bc Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Sat, 28 Jun 2014 12:25:36 +0200
Subject: [PATCH 166/230] Added .travis and fixed user test

---
 .travis.yml                     | 101 ++++++++++++++++++++++++++++++++++++++++
 src/Tests/TokenUserTestCase.php |   3 +-
 2 files changed, 103 insertions(+), 1 deletion(-)
 create mode 100644 .travis.yml

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..3a59dde
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,101 @@
+language: php
+cache:
+  bundler: true
+  directories:
+    - $HOME/tmp/drush
+    - $HOME/.bundle
+  apt: true
+
+php:
+  - 5.4
+  - 5.5
+
+notifications:
+  email:
+    - saschagros@gmail.com
+
+env:
+  - PATH=$PATH:/home/travis/.composer/vendor/bin
+
+# This will create the database
+mysql:
+  database: drupal
+  username: root
+  encoding: utf8
+
+# To be able to run a webbrowser
+# If we need anything more powerful
+# than e.g. phantomjs
+before_install:
+  - "export DISPLAY=:99.0"
+  - "sh -e /etc/init.d/xvfb start"
+
+install:
+  # Grab Drush
+  - composer global require drush/drush:dev-master --prefer-source
+  - cd /home/travis/.composer/vendor/drush/drush && cd -
+  # Make sure we don't fail when checking out projects
+  - echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
+  # LAMP package installation (mysql is already started)
+  - sudo apt-get install apache2 libapache2-mod-fastcgi
+  # enable php-fpm, travis does not support any other method with php and apache
+  - sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf
+  - sudo a2enmod rewrite actions fastcgi alias
+  - echo "cgi.fix_pathinfo = 1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
+  - ~/.phpenv/versions/$(phpenv version-name)/sbin/php-fpm
+  # Make sure the apache root is in our wanted directory
+  - echo "$(curl -fsSL https://gist.githubusercontent.com/nickveenhof/11386315/raw/b8abaf9304fe12b5cc7752d39c29c1edae8ac2e6/gistfile1.txt)" | sed -e "s,PATH,$TRAVIS_BUILD_DIR/../drupal,g" | sudo tee /etc/apache2/sites-available/default > /dev/null
+  # Set sendmail so drush doesn't throw an error during site install.
+  - echo "sendmail_path='true'" >> `php --ini | grep "Loaded Configuration" | awk '{print $4}'`
+  # Forward the errors to the syslog so we can print them
+  - echo "error_log=syslog" >> `php --ini | grep "Loaded Configuration" | awk '{print $4}'`
+  # Get latest drupal 8 core
+  - cd $TRAVIS_BUILD_DIR/..
+  - git clone --depth 1 --branch 8.x http://git.drupal.org/project/drupal.git
+  # Restart apache and test it
+  - sudo service apache2 restart
+  - curl -v "http://localhost"
+  # Re-enable when trying to get CodeSniffer doesn't return a 403 anymore.
+  #- composer global require drupal/coder:\>7
+
+before_script:
+  - cd $TRAVIS_BUILD_DIR/../drupal
+  # Update drupal core
+  - git pull origin 8.x
+  # Install the site
+  - drush -v site-install minimal --db-url=mysql://root:@localhost/drupal --yes
+  - drush en --yes simpletest
+  - drush cr
+  - phpenv rehash
+
+script:
+  # go to our Drupal module directory
+  - mkdir $TRAVIS_BUILD_DIR/../drupal/modules/pathauto
+  - cp -R $TRAVIS_BUILD_DIR/* $TRAVIS_BUILD_DIR/../drupal/modules/pathauto/
+  # go to our Drupal main directory
+  - cd $TRAVIS_BUILD_DIR/../drupal
+  - ls -la $TRAVIS_BUILD_DIR/../drupal/sites/default
+  # Run the tests
+  - php core/scripts/run-tests.sh --verbose --color --concurrency 4 --php `which php` --url http://localhost "Token" | tee /tmp/test.txt
+  - TEST_EXIT=${PIPESTATUS[0]}
+  - echo $TEST_EXIT
+  # Check if we had fails in the run-tests.sh script
+  # Exit with the inverted value, because if there are no fails found, it will exit with 1 and for us that\
+  # is a good thing so invert it to 0. Travis has some issues with the exclamation mark in front so we have to fiddle a
+  # bit.
+  # Also make the grep case insensitive and fail on run-tests.sh regular fails as well on fatal errors.
+  - TEST_OUTPUT=$(! egrep -i "([0-9]+ fails)|(PHP Fatal error)|([0-9]+ exceptions)" /tmp/test.txt > /dev/null)$?
+  - echo $TEST_OUTPUT
+  - cd $TRAVIS_BUILD_DIR/../drupal/core
+  - ./vendor/bin/phpunit --group token --verbose --debug  --coverage-text
+  - TEST_PHPUNIT=$?
+  - echo $TEST_PHPUNIT
+  # if the TEST_EXIT status is 0 AND the TEST_OUTPUT status is also 0 it means we succeeded, in all other cases we
+  # failed.
+  # Re-enable when trying to get CodeSniffer doesn't return a 403 anymore.
+  #- /home/travis/.composer/vendor/bin/phpcs --standard=/home/travis/.composer/vendor/drupal/coder/coder_sniffer/Drupal --extensions=php,inc,test,module,install --ignore=css/ $TRAVIS_BUILD_DIR/../drupal/modules/search_api
+  - php -i | grep 'php.ini'
+  - sudo cat /var/log/apache2/error.log
+  - sudo cat /var/log/syslog | grep 'php'
+  # Exit the build
+  - if [ $TEST_EXIT -eq 0 ] && [ $TEST_OUTPUT -eq 0 ] && [ $TEST_PHPUNIT -eq 0 ]; then exit 0; else exit 1; fi
diff --git a/src/Tests/TokenUserTestCase.php b/src/Tests/TokenUserTestCase.php
index 0d37571..f0b357e 100644
--- a/src/Tests/TokenUserTestCase.php
+++ b/src/Tests/TokenUserTestCase.php
@@ -5,6 +5,7 @@
  * Contains \Drupal\token\Tests\TokenUserTestCase.
  */
 namespace Drupal\token\Tests;
+use Drupal\Core\Session\AnonymousUserSession;
 use Drupal\field\Entity\FieldConfig;
 use Drupal\field\Field;
 
@@ -86,7 +87,7 @@ class TokenUserTestCase extends TokenTestBase {
     );
     $this->assertTokens('current-user', array(), $tokens);
 
-    $anonymous = drupal_anonymous_user();
+    $anonymous = new AnonymousUserSession();
     $tokens = array(
       'roles' => 'anonymous',
       'roles:keys' => (string) DRUPAL_ANONYMOUS_RID,
-- 
1.9.3 (Apple Git-50)


From a67ec367b4aaaaf3043eb6a2bea5c4466cf9ed9f Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Sat, 28 Jun 2014 18:08:46 +0200
Subject: [PATCH 167/230] setError() needs the form_state.

---
 token.module | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/token.module b/token.module
index aebcf80..709509d 100644
--- a/token.module
+++ b/token.module
@@ -618,21 +618,21 @@ function token_element_validate(&$element, &$form_state) {
   if (isset($element['#min_tokens']) && count($tokens) < $element['#min_tokens']) {
     // @todo Change this error message to include the minimum number.
     $error = \Drupal::translation()->formatPlural($element['#min_tokens'], 'The %element-title cannot contain fewer than one token.', 'The %element-title must contain at least @count tokens.', array('%element-title' => $title));
-    \Drupal::formBuilder()->setError($element, $error);
+    \Drupal::formBuilder()->setError($element, $form_state, $error);
   }
 
   // Validate if an element must have a maximum number of tokens.
   if (isset($element['#max_tokens']) && count($tokens) > $element['#max_tokens']) {
     // @todo Change this error message to include the maximum number.
     $error = \Drupal::translation()->formatPlural($element['#max_tokens'], 'The %element-title must contain as most one token.', 'The %element-title must contain at most @count tokens.', array('%element-title' => $title));
-    \Drupal::formBuilder()->setError($element, $error);
+    \Drupal::formBuilder()->setError($element, $form_state, $error);
   }
 
   // Check if the field defines specific token types.
   if (isset($element['#token_types'])) {
     $invalid_tokens = token_get_invalid_tokens_by_context($tokens, $element['#token_types']);
     if ($invalid_tokens) {
-      \Drupal::formBuilder()->setError($element, t('The %element-title is using the following invalid tokens: @invalid-tokens.', array('%element-title' => $title, '@invalid-tokens' => implode(', ', $invalid_tokens))));
+      \Drupal::formBuilder()->setError($element, $form_state, t('The %element-title is using the following invalid tokens: @invalid-tokens.', array('%element-title' => $title, '@invalid-tokens' => implode(', ', $invalid_tokens))));
     }
   }
 
-- 
1.9.3 (Apple Git-50)


From a86ce71d604ca328c234e3a444a727dac5960428 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Sat, 28 Jun 2014 18:22:42 +0200
Subject: [PATCH 168/230] Remove coverage report

---
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 3a59dde..4d04541 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -87,7 +87,7 @@ script:
   - TEST_OUTPUT=$(! egrep -i "([0-9]+ fails)|(PHP Fatal error)|([0-9]+ exceptions)" /tmp/test.txt > /dev/null)$?
   - echo $TEST_OUTPUT
   - cd $TRAVIS_BUILD_DIR/../drupal/core
-  - ./vendor/bin/phpunit --group token --verbose --debug  --coverage-text
+  - ./vendor/bin/phpunit --verbose --debug ../modules/token
   - TEST_PHPUNIT=$?
   - echo $TEST_PHPUNIT
   # if the TEST_EXIT status is 0 AND the TEST_OUTPUT status is also 0 it means we succeeded, in all other cases we
-- 
1.9.3 (Apple Git-50)


From 56854402358ac73ae8ea725b75f30c65bb11f974 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Sat, 28 Jun 2014 20:11:34 +0200
Subject: [PATCH 169/230] Use trailing slash

---
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 4d04541..4600cf7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -87,7 +87,7 @@ script:
   - TEST_OUTPUT=$(! egrep -i "([0-9]+ fails)|(PHP Fatal error)|([0-9]+ exceptions)" /tmp/test.txt > /dev/null)$?
   - echo $TEST_OUTPUT
   - cd $TRAVIS_BUILD_DIR/../drupal/core
-  - ./vendor/bin/phpunit --verbose --debug ../modules/token
+  - ./vendor/bin/phpunit --verbose --debug ../modules/token/
   - TEST_PHPUNIT=$?
   - echo $TEST_PHPUNIT
   # if the TEST_EXIT status is 0 AND the TEST_OUTPUT status is also 0 it means we succeeded, in all other cases we
-- 
1.9.3 (Apple Git-50)


From e346d7b13c122e4e0b418e9f6e67cf0ab481a0af Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Tue, 1 Jul 2014 11:54:13 +0200
Subject: [PATCH 170/230] Update hook_help()

---
 token.module | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/token.module b/token.module
index 709509d..bdf3612 100644
--- a/token.module
+++ b/token.module
@@ -9,8 +9,8 @@ use Drupal\Component\Utility\String;
 use Drupal\Component\Utility\Xss;
 use Drupal\Core\Cache\Cache;
 use Drupal\Core\Render\Element;
+use Drupal\Core\Routing\RouteMatchInterface;
 use Drupal\Core\Utility\Token;
-use Symfony\Component\HttpFoundation\Request;
 
 /**
  * The maximum depth for token tree recursion.
@@ -20,7 +20,7 @@ define('TOKEN_MAX_DEPTH', 9);
 /**
  * Implements hook_help().
  */
-function token_help($route_name, Request $request) {
+function token_help($route_name, RouteMatchInterface $route_match) {
   if ($route_name == 'help.page.token') {
     if (current_path() != 'admin/help/token') {
       // Because system_modules() executes hook_help() for each module to 'test'
-- 
1.9.3 (Apple Git-50)


From 909e3ebaf4441f257ef8d3e439c93ac71c2f5580 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Tue, 1 Jul 2014 23:03:39 +0200
Subject: [PATCH 171/230] Fixed module name in .travis.yml

---
 .travis.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 4600cf7..fb13d6a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -70,8 +70,8 @@ before_script:
 
 script:
   # go to our Drupal module directory
-  - mkdir $TRAVIS_BUILD_DIR/../drupal/modules/pathauto
-  - cp -R $TRAVIS_BUILD_DIR/* $TRAVIS_BUILD_DIR/../drupal/modules/pathauto/
+  - mkdir $TRAVIS_BUILD_DIR/../drupal/modules/token
+  - cp -R $TRAVIS_BUILD_DIR/* $TRAVIS_BUILD_DIR/../drupal/modules/token/
   # go to our Drupal main directory
   - cd $TRAVIS_BUILD_DIR/../drupal
   - ls -la $TRAVIS_BUILD_DIR/../drupal/sites/default
-- 
1.9.3 (Apple Git-50)


From a5a49c79ca1fe373f8233e7052d5ed8001b283b5 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Fri, 11 Jul 2014 09:17:39 +0200
Subject: [PATCH 172/230] Make token test base class abstract to avoid errors
 with new test class discovery.

---
 src/Tests/TokenTestBase.php | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/Tests/TokenTestBase.php b/src/Tests/TokenTestBase.php
index fb90a2b..eaa3fb6 100644
--- a/src/Tests/TokenTestBase.php
+++ b/src/Tests/TokenTestBase.php
@@ -13,8 +13,7 @@ use Drupal\Core\Language\Language;
 /**
  * Helper test class with some added functions for testing.
  */
-class TokenTestBase extends WebTestBase {
-  protected $profile = 'testing';
+abstract class TokenTestBase extends WebTestBase {
 
   protected static $modules = array('path', 'token', 'token_test');
 
-- 
1.9.3 (Apple Git-50)


From c34d5d3a064c43d85c82fb2fd03edeb62e334e79 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Fri, 11 Jul 2014 19:42:10 +0200
Subject: [PATCH 173/230] module_invoke_all() has been removed.

---
 token.tokens.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index e3987d3..ffd329a 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -925,7 +925,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
   if (empty($data[$type]) && ($entity_type = token_get_entity_mapping('token', $type)) && $entity_type != $type && !empty($data[$entity_type]) && empty($options['recursive'])) {
     $data[$type] = $data[$entity_type];
     $options['recursive'] = TRUE;
-    $replacements += module_invoke_all('tokens', $type, $tokens, $data, $options);
+    $replacements += \Drupal::moduleHandler()->invokeAll('tokens', array($type, $tokens, $data, $options));
   }
 
   // If the token type specifics a 'needs-data' value, and the value is not
-- 
1.9.3 (Apple Git-50)


From c97938c4002bf04d72ace3cac445c0dfaa68bb51 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Mon, 14 Jul 2014 13:24:58 +0200
Subject: [PATCH 174/230] drupal_alter() was removed.

---
 token.module | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.module b/token.module
index bdf3612..f8bd3e7 100644
--- a/token.module
+++ b/token.module
@@ -315,7 +315,7 @@ function token_get_entity_mapping($value_type = 'token', $value = NULL, $fallbac
       $mapping[$entity_type] = $info->get('token type') ? $info->get('token type') : $entity_type;
     }
     // Allow modules to alter the mapping array.
-    drupal_alter('token_entity_mapping', $mapping);
+    \Drupal::moduleHandler()->alter('token_entity_mapping', $mapping);
   }
 
   if (!isset($value)) {
-- 
1.9.3 (Apple Git-50)


From 1989b8a65732b59227ab207a2cd7ea2170dcc52d Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Fri, 18 Jul 2014 01:32:01 +0200
Subject: [PATCH 175/230] Rename local_tasks.yml, replaced removed functions,
 updated tests

---
 .travis.yml                                        |  2 +-
 src/Tests/TokenArrayTestCase.php                   |  9 +------
 src/Tests/TokenBlockTestCase.php                   | 21 ++++++++-------
 src/Tests/TokenCommentTestCase.php                 | 10 +------
 src/Tests/TokenCurrentPageTestCase.php             | 12 ++-------
 src/Tests/TokenDateTestCase.php                    |  9 +------
 src/Tests/TokenEntityTestCase.php                  | 11 +++-----
 src/Tests/TokenFileTestCase.php                    | 10 +------
 src/Tests/TokenMenuTestCase.php                    | 10 +------
 src/Tests/TokenNodeTestCase.php                    | 13 +++------
 src/Tests/TokenRandomTestCase.php                  |  9 +------
 src/Tests/TokenTaxonomyTestCase.php                | 13 +++------
 src/Tests/TokenURLTestCase.php                     | 13 +++------
 src/Tests/TokenUnitTestCase.php                    | 12 ++-------
 src/Tests/TokenUserTestCase.php                    | 24 ++++++++---------
 .../entity.form_display.user.user.default.yml      | 23 ++++++++++++++++
 .../install/field.field.user.user_picture.yml      | 25 +++++++++++++++++
 .../field.instance.user.user.user_picture.yml      | 31 ++++++++++++++++++++++
 .../token_user_picture/token_user_picture.info.yml |  8 ++++++
 token.install                                      |  2 +-
 token.local_tasks.yml => token.links.task.yml      |  0
 token.module                                       |  2 +-
 token.tokens.inc                                   | 10 ++++---
 23 files changed, 144 insertions(+), 135 deletions(-)
 create mode 100644 tests/token_user_picture/config/install/entity.form_display.user.user.default.yml
 create mode 100644 tests/token_user_picture/config/install/field.field.user.user_picture.yml
 create mode 100644 tests/token_user_picture/config/install/field.instance.user.user.user_picture.yml
 create mode 100644 tests/token_user_picture/token_user_picture.info.yml
 rename token.local_tasks.yml => token.links.task.yml (100%)

diff --git a/.travis.yml b/.travis.yml
index fb13d6a..ede0de7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -76,7 +76,7 @@ script:
   - cd $TRAVIS_BUILD_DIR/../drupal
   - ls -la $TRAVIS_BUILD_DIR/../drupal/sites/default
   # Run the tests
-  - php core/scripts/run-tests.sh --verbose --color --concurrency 4 --php `which php` --url http://localhost "Token" | tee /tmp/test.txt
+  - php core/scripts/run-tests.sh --verbose --color --concurrency 4 --php `which php` --url http://localhost "token" | tee /tmp/test.txt
   - TEST_EXIT=${PIPESTATUS[0]}
   - echo $TEST_EXIT
   # Check if we had fails in the run-tests.sh script
diff --git a/src/Tests/TokenArrayTestCase.php b/src/Tests/TokenArrayTestCase.php
index 4249296..9fe9e51 100644
--- a/src/Tests/TokenArrayTestCase.php
+++ b/src/Tests/TokenArrayTestCase.php
@@ -9,16 +9,9 @@ namespace Drupal\token\Tests;
 /**
  * Tests array tokens.
  *
- * @group Token
+ * @group token
  */
 class TokenArrayTestCase extends TokenTestBase {
-  public static function getInfo() {
-    return array(
-      'name' => 'Array token tests',
-      'description' => 'Test the array tokens.',
-      'group' => 'Token',
-    );
-  }
 
   function testArrayTokens() {
     // Test a simple array.
diff --git a/src/Tests/TokenBlockTestCase.php b/src/Tests/TokenBlockTestCase.php
index 367c0fe..1caf4b9 100644
--- a/src/Tests/TokenBlockTestCase.php
+++ b/src/Tests/TokenBlockTestCase.php
@@ -11,19 +11,20 @@ use Drupal\block_content\Entity\BlockContentType;
 /**
  * Tests block tokens.
  *
- * @group Token
+ * @group token
  */
 class TokenBlockTestCase extends TokenTestBase {
-  protected static $modules = array('path', 'token', 'token_test', 'block', 'node', 'views', 'block_content');
 
-  public static function getInfo() {
-    return array(
-      'name' => 'Block token tests',
-      'description' => 'Test the block title token replacement.',
-      'group' => 'Token',
-    );
-  }
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  protected static $modules = array('path', 'token', 'token_test', 'block', 'node', 'views', 'block_content');
 
+  /**
+   * {@inheritdoc}
+   */
   public function setUp($modules = array()) {
     parent::setUp();
     $this->admin_user = $this->drupalCreateUser(array('access content', 'administer blocks'));
@@ -63,7 +64,7 @@ class TokenBlockTestCase extends TokenTestBase {
     // Ensure that tokens are not double-escaped when output as a block title.
     $node = $this->drupalCreateNode(array('title' => "Site's first node"));
     $this->drupalGet('node/' . $node->id());
-    // The apostraphe should only be escaped once via check_plain().
+    // The apostraphe should only be escaped once via \Drupal\Component\Utility\String::checkPlain().
     $this->assertRaw("Site&#039;s first node block title");
   }
 }
diff --git a/src/Tests/TokenCommentTestCase.php b/src/Tests/TokenCommentTestCase.php
index 6ddb0b2..7e3e39f 100644
--- a/src/Tests/TokenCommentTestCase.php
+++ b/src/Tests/TokenCommentTestCase.php
@@ -9,19 +9,11 @@ namespace Drupal\token\Tests;
 /**
  * Tests comment tokens.
  *
- * @group Token
+ * @group token
  */
 class TokenCommentTestCase extends TokenTestBase {
   protected static $modules = array('path', 'token', 'token_test', 'node', 'comment');
 
-  public static function getInfo() {
-    return array(
-      'name' => 'Comment token tests',
-      'description' => 'Test the comment tokens.',
-      'group' => 'Token',
-    );
-  }
-
   function testCommentTokens() {
     $this->drupalCreateContentType(array('type' => 'page', 'name' => t('Page')));
     \Drupal::service('comment.manager')->addDefaultField('node', 'page');
diff --git a/src/Tests/TokenCurrentPageTestCase.php b/src/Tests/TokenCurrentPageTestCase.php
index 8fb26fe..9ed1a25 100644
--- a/src/Tests/TokenCurrentPageTestCase.php
+++ b/src/Tests/TokenCurrentPageTestCase.php
@@ -7,22 +7,14 @@
 namespace Drupal\token\Tests;
 
 /**
- * Tests current page tokens.
+ * Test the [current-page:*] tokens.
  *
- * @group Token
+ * @group token
  */
 class TokenCurrentPageTestCase extends TokenTestBase {
 
   protected static $modules = array('path', 'token', 'token_test', 'node');
 
-  public static function getInfo() {
-    return array(
-      'name' => 'Current page token tests',
-      'description' => 'Test the [current-page:*] tokens.',
-      'group' => 'Token',
-    );
-  }
-
   function testCurrentPageTokens() {
     $this->drupalGet('user');
     $tokens = array(
diff --git a/src/Tests/TokenDateTestCase.php b/src/Tests/TokenDateTestCase.php
index 58624b7..a640832 100644
--- a/src/Tests/TokenDateTestCase.php
+++ b/src/Tests/TokenDateTestCase.php
@@ -9,16 +9,9 @@ namespace Drupal\token\Tests;
 /**
  * Tests date tokens.
  *
- * @group Token
+ * @group token
  */
 class TokenDateTestCase extends TokenTestBase {
-  public static function getInfo() {
-    return array(
-      'name' => 'Date token tests',
-      'description' => 'Test the date tokens.',
-      'group' => 'Token',
-    );
-  }
 
   function testDateTokens() {
     $tokens = array(
diff --git a/src/Tests/TokenEntityTestCase.php b/src/Tests/TokenEntityTestCase.php
index 8424e26..eb171de 100644
--- a/src/Tests/TokenEntityTestCase.php
+++ b/src/Tests/TokenEntityTestCase.php
@@ -15,14 +15,9 @@ use Drupal\taxonomy\VocabularyInterface;
 class TokenEntityTestCase extends TokenTestBase {
   protected static $modules = array('path', 'token', 'token_test', 'node', 'taxonomy');
 
-  public static function getInfo() {
-    return array(
-      'name' => 'Entity token tests',
-      'description' => 'Test the entity tokens.',
-      'group' => 'Token',
-    );
-  }
-
+  /**
+   * {@inheritdoc}
+   */
   public function setUp($modules = array()) {
     parent::setUp();
 
diff --git a/src/Tests/TokenFileTestCase.php b/src/Tests/TokenFileTestCase.php
index 7bbda18..8085d5e 100644
--- a/src/Tests/TokenFileTestCase.php
+++ b/src/Tests/TokenFileTestCase.php
@@ -9,19 +9,11 @@ namespace Drupal\token\Tests;
 /**
  * Tests file tokens.
  *
- * @group Token
+ * @group token
  */
 class TokenFileTestCase extends TokenTestBase {
   protected static $modules = array('path', 'token', 'token_test', 'file');
 
-  public static function getInfo() {
-    return array(
-      'name' => 'File token tests',
-      'description' => 'Test the file tokens.',
-      'group' => 'Token',
-    );
-  }
-
   function testFileTokens() {
     // Create a test file object.
     $file = entity_create('file', array(
diff --git a/src/Tests/TokenMenuTestCase.php b/src/Tests/TokenMenuTestCase.php
index 19218b7..e20f2e8 100644
--- a/src/Tests/TokenMenuTestCase.php
+++ b/src/Tests/TokenMenuTestCase.php
@@ -9,19 +9,11 @@ namespace Drupal\token\Tests;
 /**
  * Tests menu tokens.
  *
- * @group Token
+ * @group token
  */
 class TokenMenuTestCase extends TokenTestBase {
   protected static $modules = array('path', 'token', 'token_test', 'menu_ui', 'node');
 
-  public static function getInfo() {
-    return array(
-      'name' => 'Menu link and menu token tests',
-      'description' => 'Test the menu tokens.',
-      'group' => 'Token',
-    );
-  }
-
   function testMenuTokens() {
     // Add a menu.
     $menu = entity_create('menu', array(
diff --git a/src/Tests/TokenNodeTestCase.php b/src/Tests/TokenNodeTestCase.php
index ec7173f..c9f8786 100644
--- a/src/Tests/TokenNodeTestCase.php
+++ b/src/Tests/TokenNodeTestCase.php
@@ -4,24 +4,17 @@
  * @file
  * Contains \Drupal\token\Tests\TokenNodeTestCase.
  */
+
 namespace Drupal\token\Tests;
 
 /**
- * Tests node tokens.
+ * Test the node and content type tokens.
  *
- * @group Token
+ * @group token
  */
 class TokenNodeTestCase extends TokenTestBase {
   protected $profile = 'standard';
 
-  public static function getInfo() {
-    return array(
-      'name' => 'Node and content type token tests',
-      'description' => 'Test the node and content type tokens.',
-      'group' => 'Token',
-    );
-  }
-
   function testNodeTokens() {
     $source_node = $this->drupalCreateNode(array('log' => $this->randomName(), 'path' => array('alias' => 'content/source-node')));
     $tokens = array(
diff --git a/src/Tests/TokenRandomTestCase.php b/src/Tests/TokenRandomTestCase.php
index 4e8760b..82813f5 100644
--- a/src/Tests/TokenRandomTestCase.php
+++ b/src/Tests/TokenRandomTestCase.php
@@ -9,16 +9,9 @@ namespace Drupal\token\Tests;
 /**
  * Tests random tokens.
  *
- * @group Token
+ * @group token
  */
 class TokenRandomTestCase extends TokenTestBase {
-  public static function getInfo() {
-    return array(
-      'name' => 'Random token tests',
-      'description' => 'Test the random tokens.',
-      'group' => 'Token',
-    );
-  }
 
   function testRandomTokens() {
     $tokens = array(
diff --git a/src/Tests/TokenTaxonomyTestCase.php b/src/Tests/TokenTaxonomyTestCase.php
index 96c8e20..2f5f635 100644
--- a/src/Tests/TokenTaxonomyTestCase.php
+++ b/src/Tests/TokenTaxonomyTestCase.php
@@ -10,21 +10,16 @@ use Drupal\Component\Utility\String;
 /**
  * Tests taxonomy tokens.
  *
- * @group Token
+ * @group token
  */
 class TokenTaxonomyTestCase extends TokenTestBase {
   protected $vocab;
 
   protected static $modules = array('path', 'token', 'token_test', 'taxonomy');
 
-  public static function getInfo() {
-    return array(
-      'name' => 'Taxonomy and vocabulary token tests',
-      'description' => 'Test the taxonomy tokens.',
-      'group' => 'Token',
-    );
-  }
-
+  /**
+   * {@inheritdoc}
+   */
   public function setUp() {
     parent::setUp();
 
diff --git a/src/Tests/TokenURLTestCase.php b/src/Tests/TokenURLTestCase.php
index b5dbbd5..a770a60 100644
--- a/src/Tests/TokenURLTestCase.php
+++ b/src/Tests/TokenURLTestCase.php
@@ -9,19 +9,14 @@ namespace Drupal\token\Tests;
 /**
  * Tests url tokens.
  *
- * @group Token
+ * @group token
  */
 class TokenURLTestCase extends TokenTestBase {
   protected static $modules = array('path', 'token', 'token_test', 'node');
 
-  public static function getInfo() {
-    return array(
-      'name' => 'URL token tests',
-      'description' => 'Test the URL tokens.',
-      'group' => 'Token',
-    );
-  }
-
+  /**
+   * {@inheritdoc}
+   */
   public function setUp() {
     parent::setUp();
     $this->saveAlias('node/1', 'first-node');
diff --git a/src/Tests/TokenUnitTestCase.php b/src/Tests/TokenUnitTestCase.php
index d017494..d5097e9 100644
--- a/src/Tests/TokenUnitTestCase.php
+++ b/src/Tests/TokenUnitTestCase.php
@@ -7,21 +7,13 @@
 namespace Drupal\token\Tests;
 
 /**
- * Token unit tests.
+ * Test basic, low-level token functions.
  *
- * @group Token
+ * @group token
  */
 class TokenUnitTestCase extends TokenTestBase {
   protected static $modules = array('path', 'token', 'token_test', 'file', 'node');
 
-  public static function getInfo() {
-    return array(
-      'name' => 'Token unit tests',
-      'description' => 'Test basic, low-level token functions.',
-      'group' => 'Token',
-    );
-  }
-
   /**
    * Test token_get_invalid_tokens() and token_get_invalid_tokens_by_context().
    */
diff --git a/src/Tests/TokenUserTestCase.php b/src/Tests/TokenUserTestCase.php
index f0b357e..f1c9049 100644
--- a/src/Tests/TokenUserTestCase.php
+++ b/src/Tests/TokenUserTestCase.php
@@ -4,30 +4,30 @@
  * @file
  * Contains \Drupal\token\Tests\TokenUserTestCase.
  */
+
 namespace Drupal\token\Tests;
+
 use Drupal\Core\Session\AnonymousUserSession;
 use Drupal\field\Entity\FieldConfig;
-use Drupal\field\Field;
 
 /**
  * Tests user tokens.
  *
- * @group Token
+ * @group token
  */
 class TokenUserTestCase extends TokenTestBase {
   protected $account = NULL;
 
-  // User pictures only exist in standard now.
-  protected $profile = 'standard';
-
-  public static function getInfo() {
-    return array(
-      'name' => 'User token tests',
-      'description' => 'Test the user tokens.',
-      'group' => 'Token',
-    );
-  }
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  protected static $modules = array('token_user_picture');
 
+  /**
+   * {@inheritdoc}
+   */
   public function setUp() {
     parent::setUp();
 
diff --git a/tests/token_user_picture/config/install/entity.form_display.user.user.default.yml b/tests/token_user_picture/config/install/entity.form_display.user.user.default.yml
new file mode 100644
index 0000000..a30d012
--- /dev/null
+++ b/tests/token_user_picture/config/install/entity.form_display.user.user.default.yml
@@ -0,0 +1,23 @@
+langcode: de
+status: true
+dependencies:
+  module:
+    - image
+    - user
+id: user.user.default
+targetEntityType: user
+bundle: user
+mode: default
+content:
+  account:
+    weight: -10
+  user_picture:
+    type: image_image
+    settings:
+      progress_indicator: throbber
+      preview_image_style: thumbnail
+    third_party_settings: {  }
+    weight: -1
+  timezone:
+    weight: 6
+hidden: {  }
diff --git a/tests/token_user_picture/config/install/field.field.user.user_picture.yml b/tests/token_user_picture/config/install/field.field.user.user_picture.yml
new file mode 100644
index 0000000..986d7bf
--- /dev/null
+++ b/tests/token_user_picture/config/install/field.field.user.user_picture.yml
@@ -0,0 +1,25 @@
+id: user.user_picture
+status: true
+langcode: en
+name: user_picture
+entity_type: user
+type: image
+settings:
+  uri_scheme: public
+  default_image:
+    fid: null
+    alt: ''
+    title: ''
+    width: null
+    height: null
+module: image
+locked: false
+cardinality: 1
+translatable: false
+indexes:
+  target_id:
+    - target_id
+dependencies:
+  module:
+    - image
+    - user
diff --git a/tests/token_user_picture/config/install/field.instance.user.user.user_picture.yml b/tests/token_user_picture/config/install/field.instance.user.user.user_picture.yml
new file mode 100644
index 0000000..6469300
--- /dev/null
+++ b/tests/token_user_picture/config/install/field.instance.user.user.user_picture.yml
@@ -0,0 +1,31 @@
+id: user.user.user_picture
+status: true
+langcode: en
+entity_type: user
+bundle: user
+field_name: user_picture
+label: Picture
+description: 'Your virtual face or picture.'
+required: false
+default_value: {  }
+default_value_function: ''
+settings:
+  file_extensions: 'png gif jpg jpeg'
+  file_directory: pictures
+  max_filesize: '30 KB'
+  alt_field: false
+  title_field: false
+  max_resolution: 85x85
+  min_resolution: ''
+  default_image:
+    fid: null
+    alt: ''
+    title: ''
+    width: null
+    height: null
+  alt_field_required: false
+  title_field_required: false
+field_type: image
+dependencies:
+  entity:
+    - field.field.user.user_picture
diff --git a/tests/token_user_picture/token_user_picture.info.yml b/tests/token_user_picture/token_user_picture.info.yml
new file mode 100644
index 0000000..166659f
--- /dev/null
+++ b/tests/token_user_picture/token_user_picture.info.yml
@@ -0,0 +1,8 @@
+type: module
+name: Token User picture
+description: Testing module that provides user pictures field.
+package: Testing
+core: 8.x
+hidden: TRUE
+dependencies:
+  - image
diff --git a/token.install b/token.install
index 0007c61..dc32948 100644
--- a/token.install
+++ b/token.install
@@ -18,7 +18,7 @@ function token_requirements($phase = 'runtime') {
     foreach ($token_problems as $problem_key => $problem) {
       if (!empty($problem['problems'])) {
         $problems = array_unique($problem['problems']);
-        $problems = array_map('check_plain', $problems);
+        $problems = array_map('\Drupal\Component\Utility\String::checkPlain', $problems);
         // ToDo: Use render arrays. See https://drupal.org/node/2195739
         $token_problems[$problem_key] = $problem['label'] . _theme('item_list', array('items' => $problems));
       }
diff --git a/token.local_tasks.yml b/token.links.task.yml
similarity index 100%
rename from token.local_tasks.yml
rename to token.links.task.yml
diff --git a/token.module b/token.module
index f8bd3e7..e93099e 100644
--- a/token.module
+++ b/token.module
@@ -1025,7 +1025,7 @@ function token_render_array(array $array, array $options = array()) {
     $rendered[] = is_array($value) ? render($value) : (string) $value;
   }
   if (!empty($options['sanitize'])) {
-    $rendered = array_map('check_plain', $rendered);
+    $rendered = array_map('\Drupal\Component\Utility\String::checkPlain', $rendered);
   }
   $join = isset($options['join']) ? $options['join'] : ', ';
   return implode($join, $rendered);
diff --git a/token.tokens.inc b/token.tokens.inc
index ffd329a..c83fb85 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -692,7 +692,8 @@ 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')) {
+    // @todo: Replace with tokens for {slug}s?
+    if (FALSE && $arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'arg')) {
       $path = \Drupal::request()->attributes->get('_system_path');
       // Make sure its a system path.
       $path = \Drupal::service('path.alias_manager')->getPathByAlias($path);
@@ -768,15 +769,18 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
           $url_options['absolute'] = TRUE;
           $replacements[$original] = \Drupal::url($route, $route_param, array('alias' => TRUE) + $url_options);
           break;
-        case 'args':
+        // @todo Update this to not use arg()
+        /*case 'args':
           $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $language_code) : $path;
           $replacements[$original] = token_render_array(arg(NULL, $value), $options);
           break;
+        */
       }
     }
 
     // [url:arg:*] chained tokens.
-    if ($arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'args')) {
+    // @todo Update this to not use arg()
+    if (FALSE && $arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'args')) {
       $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $language_code) : $path;
       $value = ltrim($value, '/');
       $replacements += \Drupal::token()->generate('array', $arg_tokens, array('array' => arg(NULL, $value)), $options);
-- 
1.9.3 (Apple Git-50)


From 8527f44d058f979539360ea5555bad5d6161b1d5 Mon Sep 17 00:00:00 2001
From: Kim Pepper <kim@pepper.id.au>
Date: Fri, 18 Jul 2014 11:27:15 +1000
Subject: [PATCH 176/230] Convert README to markdown and show build status

---
 README.md  | 3 +++
 README.txt | 2 --
 2 files changed, 3 insertions(+), 2 deletions(-)
 create mode 100644 README.md
 delete mode 100644 README.txt

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..3028def
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# Token [![Build Status](https://travis-ci.org/larowlan/token.svg?branch=8.x-1.x)](https://travis-ci.org/larowlan/token)
+
+Provides common and resuable token UI elements and missing core tokens.
diff --git a/README.txt b/README.txt
deleted file mode 100644
index 230774e..0000000
--- a/README.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-
-Provides common and resuable token UI elements and missing core tokens.
-- 
1.9.3 (Apple Git-50)


From cbf305aac1a42ed8e7b31be803aeb2cb5e92bd7e Mon Sep 17 00:00:00 2001
From: marcingy <marcingy@gmail.com>
Date: Fri, 18 Jul 2014 12:13:16 -0600
Subject: [PATCH 177/230] Add license

---
 token.libraries.yml | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/token.libraries.yml b/token.libraries.yml
index 603e429..fe8274d 100644
--- a/token.libraries.yml
+++ b/token.libraries.yml
@@ -1,6 +1,10 @@
 jquery.treeTable:
-  remote: 'http://plugins.jquery.com/project/treetable'
+  remote: 'http://plugins.jquery.com/treetable/'
   version: 2.3.0
+  license:
+    name: MIT
+    url: https://github.com/jashkenas/backbone/blob/1.1.0/LICENSE
+    gpl-compatible: true
   js:
     js/jquery.treeTable.js: {}
   css:
-- 
1.9.3 (Apple Git-50)


From 2bfd323b8375a3b4c662df95dd698d7dd668f6d0 Mon Sep 17 00:00:00 2001
From: marcingy <marcingy@gmail.com>
Date: Fri, 18 Jul 2014 12:22:05 -0600
Subject: [PATCH 178/230] Add license

---
 token.libraries.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.libraries.yml b/token.libraries.yml
index fe8274d..7391211 100644
--- a/token.libraries.yml
+++ b/token.libraries.yml
@@ -3,7 +3,7 @@ jquery.treeTable:
   version: 2.3.0
   license:
     name: MIT
-    url: https://github.com/jashkenas/backbone/blob/1.1.0/LICENSE
+    url: https://github.com/ludo/jquery-treetable/blob/2.3.0/treeTable/MIT-LICENSE
     gpl-compatible: true
   js:
     js/jquery.treeTable.js: {}
-- 
1.9.3 (Apple Git-50)


From fcab1c34fa76f942aa1ad404f9e53abddd4098a5 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Fri, 18 Jul 2014 23:57:40 +0200
Subject: [PATCH 179/230] FieldConfig has been renamed to FieldStorageConfig

---
 src/Tests/TokenUserTestCase.php | 4 ++--
 token.tokens.inc                | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/Tests/TokenUserTestCase.php b/src/Tests/TokenUserTestCase.php
index f1c9049..98cde16 100644
--- a/src/Tests/TokenUserTestCase.php
+++ b/src/Tests/TokenUserTestCase.php
@@ -8,7 +8,7 @@
 namespace Drupal\token\Tests;
 
 use Drupal\Core\Session\AnonymousUserSession;
-use Drupal\field\Entity\FieldConfig;
+use Drupal\field\Entity\FieldStorageConfig;
 
 /**
  * Tests user tokens.
@@ -66,7 +66,7 @@ class TokenUserTestCase extends TokenTestBase {
     $this->assertTokens('user', array('user' => $this->account), $user_tokens);
 
     // Remove the user picture field.
-    FieldConfig::loadByName('user', 'user_picture')->delete();
+    FieldStorageConfig::loadByName('user', 'user_picture')->delete();
 
     // Remove the simpletest-created user role.
     $roles = $this->account->getRoles();
diff --git a/token.tokens.inc b/token.tokens.inc
index c83fb85..ec0aeee 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -9,8 +9,8 @@ use Drupal\Component\Utility\String;
 use Drupal\Core\Entity\ContentEntityInterface;
 use Drupal\Core\Render\Element;
 use Drupal\Component\Utility\Xss;
-use Drupal\field\Entity\FieldConfig;
-use Drupal\field\FieldConfigInterface;
+use Drupal\field\Entity\FieldStorageConfig;
+use Drupal\field\FieldStorageConfigInterface;
 use Drupal\field\FieldInstanceConfigInterface;
 use Drupal\system\Entity\Menu;
 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
@@ -1221,7 +1221,7 @@ function field_token_info_alter(&$info) {
 
     $fields = \Drupal::entityManager()->getFieldStorageDefinitions($entity_type_id);
     foreach ($fields as $field_name => $field) {
-      if (!($field instanceof FieldConfigInterface)) {
+      if (!($field instanceof FieldStorageConfigInterface)) {
         continue;
       }
       // If a token already exists for this field, then don't add it.
-- 
1.9.3 (Apple Git-50)


From db142ed4778cca582648c459937ead462ea96ce0 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Sat, 19 Jul 2014 00:15:36 +0200
Subject: [PATCH 180/230] Update default configuration

---
 .../config/install/field.instance.user.user.user_picture.yml            | 2 +-
 ....field.user.user_picture.yml => field.storage.user.user_picture.yml} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename tests/token_user_picture/config/install/{field.field.user.user_picture.yml => field.storage.user.user_picture.yml} (100%)

diff --git a/tests/token_user_picture/config/install/field.instance.user.user.user_picture.yml b/tests/token_user_picture/config/install/field.instance.user.user.user_picture.yml
index 6469300..a7a2ef7 100644
--- a/tests/token_user_picture/config/install/field.instance.user.user.user_picture.yml
+++ b/tests/token_user_picture/config/install/field.instance.user.user.user_picture.yml
@@ -28,4 +28,4 @@ settings:
 field_type: image
 dependencies:
   entity:
-    - field.field.user.user_picture
+    - field.storage.user.user_picture
diff --git a/tests/token_user_picture/config/install/field.field.user.user_picture.yml b/tests/token_user_picture/config/install/field.storage.user.user_picture.yml
similarity index 100%
rename from tests/token_user_picture/config/install/field.field.user.user_picture.yml
rename to tests/token_user_picture/config/install/field.storage.user.user_picture.yml
-- 
1.9.3 (Apple Git-50)


From 03668f59ca4afb5cbf4a3edc7d661ea22f819471 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Thu, 31 Jul 2014 08:05:20 +0200
Subject: [PATCH 181/230] Update for FormStateInterface

---
 token.module | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/token.module b/token.module
index e93099e..f247878 100644
--- a/token.module
+++ b/token.module
@@ -8,6 +8,7 @@
 use Drupal\Component\Utility\String;
 use Drupal\Component\Utility\Xss;
 use Drupal\Core\Cache\Cache;
+use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\Render\Element;
 use Drupal\Core\Routing\RouteMatchInterface;
 use Drupal\Core\Utility\Token;
@@ -193,7 +194,7 @@ function token_block_view_alter(&$data, \Drupal\block\BlockPluginInterface $bloc
 /**
  * Implements hook_form_FORM_ID_alter().
  */
-function token_form_block_form_alter(&$form, &$form_state) {
+function token_form_block_form_alter(&$form, FormStateInterface $form_state) {
   $form['settings']['label']['#description'] = t('This field supports tokens.');
   // @todo Figure out why this token validation does not seem to be working here.
   $form['settings']['label']['#element_validate'][] = 'token_element_validate';
@@ -203,7 +204,7 @@ function token_form_block_form_alter(&$form, &$form_state) {
 /**
  * Implements hook_widget_form_alter().
  */
-function token_field_widget_form_alter(&$element, &$form_state, $context) {
+function token_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
   if (!empty($element['#description']) && is_string($element['#description'])) {
     $element['#description'] = Xss::filterAdmin(\Drupal::token()->replace($element['#description']));
   }
@@ -601,7 +602,7 @@ function token_get_invalid_tokens($type, $tokens) {
  * );
  * @endcode
  */
-function token_element_validate(&$element, &$form_state) {
+function token_element_validate(&$element, FormStateInterface $form_state) {
   $value = isset($element['#value']) ? $element['#value'] : $element['#default_value'];
 
   if (!drupal_strlen($value)) {
@@ -642,7 +643,7 @@ function token_element_validate(&$element, &$form_state) {
 /**
  * Deprecated. Use token_element_validate() instead.
  */
-function token_element_validate_token_context(&$element, &$form_state) {
+function token_element_validate_token_context(&$element, FormStateInterface $form_state) {
   return token_element_validate($element, $form_state);
 }
 
@@ -704,7 +705,7 @@ function token_form_system_actions_configure_alter(&$form, $form_state) {
  * Alters the user e-mail fields to add token context validation and
  * adds the token tree for a better token UI and selection.
  */
-function token_form_user_admin_settings_alter(&$form, &$form_state) {
+function token_form_user_admin_settings_alter(&$form, FormStateInterface $form_state) {
   $email_token_help = t('Available variables are: [site:name], [site:url], [user:name], [user:mail], [site:login-url], [site:url-brief], [user:edit-url], [user:one-time-login-url], [user:cancel-url].');
 
   foreach (Element::children($form) as $key) {
-- 
1.9.3 (Apple Git-50)


From 903f8955a2e4a3fb3e2e0a9d685d5fea30539de5 Mon Sep 17 00:00:00 2001
From: "tien.xuan.vo" <tien.xuan.vo@gmail.com>
Date: Fri, 8 Aug 2014 09:52:17 +0700
Subject: [PATCH 182/230] Update the PR: replace _drupal_add_library by
 #attached.

---
 token.pages.inc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/token.pages.inc b/token.pages.inc
index a7ca1bb..dda284e 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -16,9 +16,9 @@ function theme_token_tree_link($variables) {
   }
 
   if (!empty($variables['dialog'])) {
-    // @todo Move this somewhere it can use #attached.
-    _drupal_add_library('core/drupal.dialog.ajax');
-    _drupal_add_library('token/token');
+    $attached['#attached']['library'][] = 'core/drupal.dialog.ajax';
+    $attached['#attached']['library'][] = 'token/token';
+    drupal_render($attached);
     $variables['options']['attributes']['class'][] = 'token-dialog';
   }
 
-- 
1.9.3 (Apple Git-50)


From 587f19021ccc8f9566c10fb1288ae447cc612b03 Mon Sep 17 00:00:00 2001
From: "tien.xuan.vo" <tien.xuan.vo@gmail.com>
Date: Fri, 8 Aug 2014 12:02:11 +0700
Subject: [PATCH 183/230] Replace comment.permalink by entity.comment.canonical

---
 src/Tests/TokenCommentTestCase.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/Tests/TokenCommentTestCase.php b/src/Tests/TokenCommentTestCase.php
index cfaf3d8..5f68a9a 100644
--- a/src/Tests/TokenCommentTestCase.php
+++ b/src/Tests/TokenCommentTestCase.php
@@ -31,7 +31,7 @@ class TokenCommentTestCase extends TokenTestBase {
     $parent_comment->save();
 
     // Fix http://example.com/index.php/comment/1 fails 'url:path' test.
-    $parent_comment_path = \Drupal::url('comment.permalink', array('comment' => $parent_comment->id()));
+    $parent_comment_path = \Drupal::url('entity.comment.canonical', array('comment' => $parent_comment->id()));
     $parent_comment_path = ltrim($parent_comment_path, '/');
 
     $tokens = array(
@@ -57,7 +57,7 @@ class TokenCommentTestCase extends TokenTestBase {
     $comment->save();
 
     // Fix http://example.com/index.php/comment/1 fails 'url:path' test.
-    $comment_path = \Drupal::url('comment.permalink', array('comment' => $comment->id()));
+    $comment_path = \Drupal::url('entity.comment.canonical', array('comment' => $comment->id()));
     $comment_path = ltrim($comment_path, '/');
 
     $tokens = array(
-- 
1.9.3 (Apple Git-50)


From 6008f7fa24af280ac167aee1fb89ca91e2ee3f79 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Fri, 25 Jul 2014 01:27:36 +0200
Subject: [PATCH 184/230] Add apt-get update to .travis

---
 .travis.yml | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index ede0de7..816a45f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,10 +10,6 @@ php:
   - 5.4
   - 5.5
 
-notifications:
-  email:
-    - saschagros@gmail.com
-
 env:
   - PATH=$PATH:/home/travis/.composer/vendor/bin
 
@@ -37,6 +33,7 @@ install:
   # Make sure we don't fail when checking out projects
   - echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
   # LAMP package installation (mysql is already started)
+  - sudo apt-get update
   - sudo apt-get install apache2 libapache2-mod-fastcgi
   # enable php-fpm, travis does not support any other method with php and apache
   - sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf
-- 
1.9.3 (Apple Git-50)


From f5384630cd80f89aa5c9625f2014bc8ab04910d0 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Thu, 31 Jul 2014 08:41:57 +0200
Subject: [PATCH 185/230] Update .travis.yml

---
 .travis.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 816a45f..62e4acc 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -48,7 +48,7 @@ install:
   - echo "error_log=syslog" >> `php --ini | grep "Loaded Configuration" | awk '{print $4}'`
   # Get latest drupal 8 core
   - cd $TRAVIS_BUILD_DIR/..
-  - git clone --depth 1 --branch 8.x http://git.drupal.org/project/drupal.git
+  - git clone --depth 1 --branch 8.0.x http://git.drupal.org/project/drupal.git
   # Restart apache and test it
   - sudo service apache2 restart
   - curl -v "http://localhost"
@@ -58,7 +58,7 @@ install:
 before_script:
   - cd $TRAVIS_BUILD_DIR/../drupal
   # Update drupal core
-  - git pull origin 8.x
+  - git pull origin 8.0.x
   # Install the site
   - drush -v site-install minimal --db-url=mysql://root:@localhost/drupal --yes
   - drush en --yes simpletest
-- 
1.9.3 (Apple Git-50)


From fb0b16529cdf4d269133bd633e7a3c5e0702b583 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Fri, 8 Aug 2014 14:46:34 +0200
Subject: [PATCH 186/230] setError() is now on FormStateInterface

---
 token.module | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/token.module b/token.module
index f247878..a30df46 100644
--- a/token.module
+++ b/token.module
@@ -619,21 +619,21 @@ function token_element_validate(&$element, FormStateInterface $form_state) {
   if (isset($element['#min_tokens']) && count($tokens) < $element['#min_tokens']) {
     // @todo Change this error message to include the minimum number.
     $error = \Drupal::translation()->formatPlural($element['#min_tokens'], 'The %element-title cannot contain fewer than one token.', 'The %element-title must contain at least @count tokens.', array('%element-title' => $title));
-    \Drupal::formBuilder()->setError($element, $form_state, $error);
+    $form_state->setError($element, $error);
   }
 
   // Validate if an element must have a maximum number of tokens.
   if (isset($element['#max_tokens']) && count($tokens) > $element['#max_tokens']) {
     // @todo Change this error message to include the maximum number.
     $error = \Drupal::translation()->formatPlural($element['#max_tokens'], 'The %element-title must contain as most one token.', 'The %element-title must contain at most @count tokens.', array('%element-title' => $title));
-    \Drupal::formBuilder()->setError($element, $form_state, $error);
+    $form_state->setError($element, $error);
   }
 
   // Check if the field defines specific token types.
   if (isset($element['#token_types'])) {
     $invalid_tokens = token_get_invalid_tokens_by_context($tokens, $element['#token_types']);
     if ($invalid_tokens) {
-      \Drupal::formBuilder()->setError($element, $form_state, t('The %element-title is using the following invalid tokens: @invalid-tokens.', array('%element-title' => $title, '@invalid-tokens' => implode(', ', $invalid_tokens))));
+      $form_state->setError($element, t('The %element-title is using the following invalid tokens: @invalid-tokens.', array('%element-title' => $title, '@invalid-tokens' => implode(', ', $invalid_tokens))));
     }
   }
 
-- 
1.9.3 (Apple Git-50)


From ae5d415d9fab62970fd6d316c3db1f0789cd9016 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Sun, 17 Aug 2014 16:04:55 +0200
Subject: [PATCH 187/230] Update randomName() to randomMachineName()

---
 src/Tests/TokenCommentTestCase.php  | 8 ++++----
 src/Tests/TokenEntityTestCase.php   | 2 +-
 src/Tests/TokenNodeTestCase.php     | 2 +-
 src/Tests/TokenTaxonomyTestCase.php | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/Tests/TokenCommentTestCase.php b/src/Tests/TokenCommentTestCase.php
index 5f68a9a..be98e71 100644
--- a/src/Tests/TokenCommentTestCase.php
+++ b/src/Tests/TokenCommentTestCase.php
@@ -25,8 +25,8 @@ class TokenCommentTestCase extends TokenTestBase {
       'field_name' => 'comment',
       'name' => 'anonymous user',
       'mail' => 'anonymous@example.com',
-      'subject' => $this->randomName(),
-      'body' => $this->randomName(),
+      'subject' => $this->randomMachineName(),
+      'body' => $this->randomMachineName(),
     ));
     $parent_comment->save();
 
@@ -51,8 +51,8 @@ class TokenCommentTestCase extends TokenTestBase {
       'uid' => 1,
       'name' => 'anonymous user',
       'mail' => 'anonymous@example.com',
-      'subject' => $this->randomName(),
-      'body' => $this->randomName(),
+      'subject' => $this->randomMachineName(),
+      'body' => $this->randomMachineName(),
     ));
     $comment->save();
 
diff --git a/src/Tests/TokenEntityTestCase.php b/src/Tests/TokenEntityTestCase.php
index eb171de..6899646 100644
--- a/src/Tests/TokenEntityTestCase.php
+++ b/src/Tests/TokenEntityTestCase.php
@@ -52,7 +52,7 @@ class TokenEntityTestCase extends TokenTestBase {
 
   function addTerm(VocabularyInterface $vocabulary, array $term = array()) {
     $term += array(
-      'name' => drupal_strtolower($this->randomName(5)),
+      'name' => drupal_strtolower($this->randomMachineName(5)),
       'vid' => $vocabulary->id(),
     );
     $term = entity_create('taxonomy_term', $term);
diff --git a/src/Tests/TokenNodeTestCase.php b/src/Tests/TokenNodeTestCase.php
index c9f8786..6cda60d 100644
--- a/src/Tests/TokenNodeTestCase.php
+++ b/src/Tests/TokenNodeTestCase.php
@@ -16,7 +16,7 @@ class TokenNodeTestCase extends TokenTestBase {
   protected $profile = 'standard';
 
   function testNodeTokens() {
-    $source_node = $this->drupalCreateNode(array('log' => $this->randomName(), 'path' => array('alias' => 'content/source-node')));
+    $source_node = $this->drupalCreateNode(array('log' => $this->randomMachineName(), 'path' => array('alias' => 'content/source-node')));
     $tokens = array(
       'source' => NULL,
       'source:nid' => NULL,
diff --git a/src/Tests/TokenTaxonomyTestCase.php b/src/Tests/TokenTaxonomyTestCase.php
index 2f5f635..1a36518 100644
--- a/src/Tests/TokenTaxonomyTestCase.php
+++ b/src/Tests/TokenTaxonomyTestCase.php
@@ -94,7 +94,7 @@ class TokenTaxonomyTestCase extends TokenTestBase {
 
   function addVocabulary(array $vocabulary = array()) {
     $vocabulary += array(
-      'name' => drupal_strtolower($this->randomName(5)),
+      'name' => drupal_strtolower($this->randomMachineName(5)),
       'nodes' => array('article' => 'article'),
     );
     $vocabulary = entity_create('taxonomy_vocabulary', $vocabulary)->save();
@@ -103,7 +103,7 @@ class TokenTaxonomyTestCase extends TokenTestBase {
 
   function addTerm($vocabulary, array $term = array()) {
     $term += array(
-      'name' => drupal_strtolower($this->randomName(5)),
+      'name' => drupal_strtolower($this->randomMachineName(5)),
       'vid' => $vocabulary->id(),
     );
     $term = entity_create('taxonomy_term', $term);
-- 
1.9.3 (Apple Git-50)


From 4b4f4c720c8f51ac41270535a6a17d42ce5b553f Mon Sep 17 00:00:00 2001
From: Arild Matsson <arild@klavaro.se>
Date: Tue, 2 Sep 2014 17:11:51 +0200
Subject: [PATCH 188/230] Changed entity type reference view_mode to
 entity_view_mode, fixes #28

---
 token.install | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.install b/token.install
index dc32948..8cf58ab 100644
--- a/token.install
+++ b/token.install
@@ -51,7 +51,7 @@ function token_install() {
       continue;
     }
     // Try to find a token view mode for that entity type.
-    $storage = \Drupal::entityManager()->getStorage('view_mode');
+    $storage = \Drupal::entityManager()->getStorage('entity_view_mode');
     // Add a token view mode if it does not already exist.
     if (!$storage->load("$entity_type.token")) {
       $storage->create(array(
-- 
1.9.3 (Apple Git-50)


From 54fa775ce494df636aee8522e6cee666fff4e910 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 3 Sep 2014 19:39:00 +0200
Subject: [PATCH 189/230] Rename default configuration

---
 ...er.user.default.yml => core.entity_form_display.user.user.default.yml} | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename tests/token_user_picture/config/install/{entity.form_display.user.user.default.yml => core.entity_form_display.user.user.default.yml} (100%)

diff --git a/tests/token_user_picture/config/install/entity.form_display.user.user.default.yml b/tests/token_user_picture/config/install/core.entity_form_display.user.user.default.yml
similarity index 100%
rename from tests/token_user_picture/config/install/entity.form_display.user.user.default.yml
rename to tests/token_user_picture/config/install/core.entity_form_display.user.user.default.yml
-- 
1.9.3 (Apple Git-50)


From 0bfaf4f7f3bab05587de97cbfefb267d6b7b15d4 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 3 Sep 2014 19:51:40 +0200
Subject: [PATCH 190/230] BlockPluginInterface moved to Drupal\Core

---
 token.module | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/token.module b/token.module
index a30df46..e66caba 100644
--- a/token.module
+++ b/token.module
@@ -7,6 +7,7 @@
 
 use Drupal\Component\Utility\String;
 use Drupal\Component\Utility\Xss;
+use Drupal\Core\Block\BlockPluginInterface;
 use Drupal\Core\Cache\Cache;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\Render\Element;
@@ -182,7 +183,7 @@ function token_form_alter(&$form, $form_state, $form_id) {
 /**
  * Implements hook_block_view_alter().
  */
-function token_block_view_alter(&$data, \Drupal\block\BlockPluginInterface $block) {
+function token_block_view_alter(&$data, BlockPluginInterface $block) {
   $config = $block->getConfiguration();
   $label = $config['label'];
   if ($label != '<none>') {
-- 
1.9.3 (Apple Git-50)


From 61caf5772ad7a7d982a08ded865387e59f55a6d8 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Sat, 6 Sep 2014 16:27:51 +0200
Subject: [PATCH 191/230] Fixing args, node and link tests. Started fixing
 menu_link tests

---
 src/Tests/TokenMenuTestCase.php                    | 44 +++++++++++-----------
 src/Tests/TokenNodeTestCase.php                    |  2 +-
 src/Tests/TokenURLTestCase.php                     |  2 +-
 ...en_test.yml => core.date_format.token_test.yml} |  0
 token.tokens.inc                                   | 22 +++++------
 5 files changed, 33 insertions(+), 37 deletions(-)
 rename tests/token_test/config/install/{system.date_format.token_test.yml => core.date_format.token_test.yml} (100%)

diff --git a/src/Tests/TokenMenuTestCase.php b/src/Tests/TokenMenuTestCase.php
index e20f2e8..51311f0 100644
--- a/src/Tests/TokenMenuTestCase.php
+++ b/src/Tests/TokenMenuTestCase.php
@@ -23,25 +23,27 @@ class TokenMenuTestCase extends TokenTestBase {
     ));
     $menu->save();
     // Add a root link.
-    $root_link = entity_create('menu_link', array(
-      'link_path' => 'admin',
-      'link_title' => 'Administration',
+    $root_link = entity_create('menu_link_content', array(
+      'url' => 'admin',
+      'title' => 'Administration',
       'menu_name' => 'main-menu',
+      'bundle' => 'menu_link_content',
     ));
     $root_link->save();
 
     // Add another link with the root link as the parent
-    $parent_link = entity_create('menu_link', array(
-      'link_path' => 'admin/config',
-      'link_title' => 'Configuration',
+    $parent_link = entity_create('menu_link_content', array(
+      'url' => 'admin/config',
+      'title' => 'Configuration',
       'menu_name' => 'main-menu',
-      'plid' => $root_link['mlid'],
+      'parent' => 'menu_link_content:' . $root_link->uuid(),
+      'bundle' => 'menu_link_content',
     ));
     $parent_link->save();
 
     // Test menu link tokens.
     $tokens = array(
-      'mlid' => $parent_link['mlid'],
+      'mlid' => $parent_link->id(),
       'title' => 'Configuration',
       'menu' => 'Main menu',
       'menu:name' => 'Main menu',
@@ -54,17 +56,17 @@ class TokenMenuTestCase extends TokenTestBase {
       'url:relative' => url('admin/config', array('absolute' => FALSE)),
       'url:path' => 'admin/config',
       'url:alias' => 'admin/config',
-      'edit-url' => url("admin/structure/menu/item/{$parent_link['mlid']}/edit", array('absolute' => TRUE)),
+      'edit-url' => url("admin/structure/menu/item/{$parent_link->id()}/edit", array('absolute' => TRUE)),
       'parent' => 'Administration',
-      'parent:mlid' => $root_link['mlid'],
+      'parent:mlid' => $root_link->id(),
       'parent:title' => 'Administration',
       'parent:menu' => 'Main menu',
       'parent:parent' => NULL,
       'parents' => 'Administration',
       'parents:count' => 1,
-      'parents:keys' => $root_link['mlid'],
+      'parents:keys' => $root_link->id(),
       'root' => 'Administration',
-      'root:mlid' => $root_link['mlid'],
+      'root:mlid' => $root_link->id(),
       'root:parent' => NULL,
       'root:root' => NULL,
     );
@@ -77,34 +79,30 @@ class TokenMenuTestCase extends TokenTestBase {
     \Drupal::config('menu.entity.node.' . $node->getType())->set('available_menus', array('main-menu'))->save();
 
     // Add a node menu link
-    $node_link = entity_create('menu_link', array(
-      'enabled' => TRUE,
+    $node_link = entity_create('menu_link_content', array(
       'link_path' => 'node/' . $node->id(),
-      'link_title' => 'Node link',
-      'plid' => $parent_link['mlid'],
-      'customized' => 0,
+      'title' => 'Node link',
+      'parent' => 'menu_link_content:' . $parent_link->uuid(),
       'menu_name' => 'main-menu',
-      'description' => '',
     ));
     $node_link->save();
 
     // Test [node:menu] tokens.
     $tokens = array(
       'menu-link' => 'Node link',
-      'menu-link:mlid' => $node->menu['mlid'],
+      'menu-link:mlid' => $node_link->id(),
       'menu-link:title' => 'Node link',
       'menu-link:menu' => 'Main menu',
       'menu-link:url' => url('node/' . $node->id(), array('absolute' => TRUE)),
       'menu-link:url:path' => 'node/' . $node->id(),
       'menu-link:edit-url' => url("admin/structure/menu/item/{$node_link->id()}/edit", array('absolute' => TRUE)),
       'menu-link:parent' => 'Configuration',
-      'menu-link:parent:mlid' => $node->menu['plid'],
-      'menu-link:parent:mlid' => $parent_link['mlid'],
+      'menu-link:parent:mlid' => $parent_link->id(),
       'menu-link:parents' => 'Administration, Configuration',
       'menu-link:parents:count' => 2,
-      'menu-link:parents:keys' => $root_link['mlid'] . ', ' . $parent_link['mlid'],
+      'menu-link:parents:keys' => $root_link->id() . ', ' . $parent_link->id(),
       'menu-link:root' => 'Administration',
-      'menu-link:root:mlid' => $root_link['mlid'],
+      'menu-link:root:mlid' => $root_link->id(),
     );
     $this->assertTokens('node', array('node' => $node), $tokens);
 
diff --git a/src/Tests/TokenNodeTestCase.php b/src/Tests/TokenNodeTestCase.php
index 6cda60d..c291390 100644
--- a/src/Tests/TokenNodeTestCase.php
+++ b/src/Tests/TokenNodeTestCase.php
@@ -16,7 +16,7 @@ class TokenNodeTestCase extends TokenTestBase {
   protected $profile = 'standard';
 
   function testNodeTokens() {
-    $source_node = $this->drupalCreateNode(array('log' => $this->randomMachineName(), 'path' => array('alias' => 'content/source-node')));
+    $source_node = $this->drupalCreateNode(array('revision_log' => $this->randomMachineName(), 'path' => array('alias' => 'content/source-node')));
     $tokens = array(
       'source' => NULL,
       'source:nid' => NULL,
diff --git a/src/Tests/TokenURLTestCase.php b/src/Tests/TokenURLTestCase.php
index a770a60..de50d7b 100644
--- a/src/Tests/TokenURLTestCase.php
+++ b/src/Tests/TokenURLTestCase.php
@@ -42,6 +42,6 @@ class TokenURLTestCase extends TokenTestBase {
       // Deprecated tokens.
       'alias' => 'first-node',
     );
-    $this->assertTokens('url', array('route_name' => 'node.view', 'route_parameters' => array('node' => 1)), $tokens);
+    $this->assertTokens('url', array('route_name' => 'entity.node.canonical', 'route_parameters' => array('node' => 1)), $tokens);
   }
 }
diff --git a/tests/token_test/config/install/system.date_format.token_test.yml b/tests/token_test/config/install/core.date_format.token_test.yml
similarity index 100%
rename from tests/token_test/config/install/system.date_format.token_test.yml
rename to tests/token_test/config/install/core.date_format.token_test.yml
diff --git a/token.tokens.inc b/token.tokens.inc
index b42ad36..8e93636 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -628,7 +628,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
           $replacements[$original] = $sanitize ? String::checkPlain($link->label()) : $link->label();
           break;
         case 'url':
-          $replacements[$original] = \Drupal::url($link->route_name, $link->route_parameters, !empty($link->localized_options) ? $link->localized_options : array('absolute' => TRUE));
+          $replacements[$original] = \Drupal::url($link->getRouteName(), $link->route_parameters, !empty($link->localized_options) ? $link->localized_options : array('absolute' => TRUE));
           break;
         case 'parent':
           if (!empty($link->plid) && $parent = menu_link_load($link->plid)) {
@@ -695,14 +695,14 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
 
     // @deprecated
     // [current-page:arg] dynamic tokens.
-    // @todo: Replace with tokens for {slug}s?
-    if (FALSE && $arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'arg')) {
+    if ($arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'arg')) {
       $path = \Drupal::request()->attributes->get('_system_path');
       // Make sure its a system path.
       $path = \Drupal::service('path.alias_manager')->getPathByAlias($path);
       foreach ($arg_tokens as $name => $original) {
-        if (is_numeric($name) && ($arg = arg($name, $path)) && isset($arg)) {
-          $replacements[$original] = $sanitize ? String::checkPlain($arg) : $arg;
+        $parts = explode('/', $path);
+        if (is_numeric($name) && isset($parts[$name])) {
+          $replacements[$original] = $sanitize ? String::checkPlain($parts[$name]) : $parts[$name];
         }
       }
     }
@@ -772,21 +772,19 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
           $url_options['absolute'] = TRUE;
           $replacements[$original] = \Drupal::url($route, $route_param, array('alias' => TRUE) + $url_options);
           break;
-        // @todo Update this to not use arg()
-        /*case 'args':
+        case 'args':
           $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $language_code) : $path;
-          $replacements[$original] = token_render_array(arg(NULL, $value), $options);
+          $replacements[$original] = token_render_array(explode('/', $value), $options);
           break;
-        */
+
       }
     }
 
     // [url:arg:*] chained tokens.
-    // @todo Update this to not use arg()
-    if (FALSE && $arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'args')) {
+    if ($arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'args')) {
       $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $language_code) : $path;
       $value = ltrim($value, '/');
-      $replacements += \Drupal::token()->generate('array', $arg_tokens, array('array' => arg(NULL, $value)), $options);
+      $replacements += \Drupal::token()->generate('array', $arg_tokens, array('array' => explode('/', $value)), $options);
     }
 
     // [url:unaliased:*] chained tokens.
-- 
1.9.3 (Apple Git-50)


From 8d1b453a4dc847c8c7473666a1fd4d6f728eb486 Mon Sep 17 00:00:00 2001
From: Daniel Wehner <daniel.wehner@erdfisch.de>
Date: Tue, 9 Sep 2014 11:44:32 +0200
Subject: [PATCH 192/230] add composer.json

---
 composer.json | 6 ++++++
 1 file changed, 6 insertions(+)
 create mode 100644 composer.json

diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..aae115f
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,6 @@
+{
+  "name": "drupal/token",
+  "description": "Provides a user interface for the Token API and some missing core tokens.",
+  "type": "drupal-module",
+  "license": "GPL-2.0+"
+}
-- 
1.9.3 (Apple Git-50)


From d01156dbd0faee6d8f3dd6384ffbfe9541798b9d Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Thu, 18 Sep 2014 02:11:05 +0200
Subject: [PATCH 193/230] Fixing them tests

---
 src/Tests/TokenBlockTestCase.php       |  6 ++++--
 src/Tests/TokenCurrentPageTestCase.php |  1 +
 src/Tests/TokenUserTestCase.php        | 14 ++++++++++----
 token.module                           | 10 +++++-----
 token.tokens.inc                       |  7 +++++--
 5 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/src/Tests/TokenBlockTestCase.php b/src/Tests/TokenBlockTestCase.php
index 1caf4b9..456c825 100644
--- a/src/Tests/TokenBlockTestCase.php
+++ b/src/Tests/TokenBlockTestCase.php
@@ -52,8 +52,9 @@ class TokenBlockTestCase extends TokenTestBase {
       'label' => '[user:name]',
     ));
     $this->drupalGet($block->getSystemPath());
+    $this->drupalPostForm(NULL, array(), t('Save block'));
     // Ensure token validation is working on the block.
-    $this->assertText('The Block title is using the following invalid tokens: [user:name].');
+    $this->assertText('The Title is using the following invalid tokens: [user:name].');
 
     // Create the block for real now with a valid title.
     $settings = $block->get('settings');
@@ -62,9 +63,10 @@ class TokenBlockTestCase extends TokenTestBase {
     $block->save();
 
     // Ensure that tokens are not double-escaped when output as a block title.
+    $this->drupalCreateContentType(array('type' => 'page'));
     $node = $this->drupalCreateNode(array('title' => "Site's first node"));
     $this->drupalGet('node/' . $node->id());
-    // The apostraphe should only be escaped once via \Drupal\Component\Utility\String::checkPlain().
+    // The apostraphe should only be escaped once.
     $this->assertRaw("Site&#039;s first node block title");
   }
 }
diff --git a/src/Tests/TokenCurrentPageTestCase.php b/src/Tests/TokenCurrentPageTestCase.php
index 9ed1a25..b66a80a 100644
--- a/src/Tests/TokenCurrentPageTestCase.php
+++ b/src/Tests/TokenCurrentPageTestCase.php
@@ -36,6 +36,7 @@ class TokenCurrentPageTestCase extends TokenTestBase {
     );
     $this->assertPageTokens('', $tokens);
 
+    $this->drupalCreateContentType(array('type' => 'page'));
     $node = $this->drupalCreateNode(array('title' => 'Node title', 'path' => array('alias' => 'node-alias')));
     $tokens = array(
       '[current-page:title]' => 'Node title',
diff --git a/src/Tests/TokenUserTestCase.php b/src/Tests/TokenUserTestCase.php
index 98cde16..750ebe7 100644
--- a/src/Tests/TokenUserTestCase.php
+++ b/src/Tests/TokenUserTestCase.php
@@ -51,8 +51,11 @@ class TokenUserTestCase extends TokenTestBase {
     $edit = array('files[user_picture_0]' => drupal_realpath($image->uri));
     $this->drupalPostForm('user/' . $this->account->id() . '/edit', $edit, t('Save'));
 
+    $storage = \Drupal::entityManager()->getStorage('user');
+
     // Load actual user data from database.
-    $this->account = user_load($this->account->id(), TRUE);
+    $storage->resetCache();
+    $this->account = $storage->load($this->account->id());
     $this->assertTrue(!empty($this->account->user_picture->target_id), 'User picture uploaded.');
 
     $user_tokens = array(
@@ -65,12 +68,15 @@ class TokenUserTestCase extends TokenTestBase {
     );
     $this->assertTokens('user', array('user' => $this->account), $user_tokens);
 
-    // Remove the user picture field.
-    FieldStorageConfig::loadByName('user', 'user_picture')->delete();
-
     // Remove the simpletest-created user role.
     $roles = $this->account->getRoles();
     $this->account->removeRole(end($roles));
+    $this->account->save();
+
+    // Remove the user picture field and reload the user.
+    FieldStorageConfig::loadByName('user', 'user_picture')->delete();
+    $storage->resetCache();
+    $this->account = $storage->load($this->account->id());
 
     $user_tokens = array(
       'picture' => NULL,
diff --git a/token.module b/token.module
index e66caba..0c83b77 100644
--- a/token.module
+++ b/token.module
@@ -6,6 +6,7 @@
  */
 
 use Drupal\Component\Utility\String;
+use Drupal\Component\Utility\Unicode;
 use Drupal\Component\Utility\Xss;
 use Drupal\Core\Block\BlockPluginInterface;
 use Drupal\Core\Cache\Cache;
@@ -183,12 +184,12 @@ function token_form_alter(&$form, $form_state, $form_id) {
 /**
  * Implements hook_block_view_alter().
  */
-function token_block_view_alter(&$data, BlockPluginInterface $block) {
+function token_block_view_alter(&$build, BlockPluginInterface $block) {
   $config = $block->getConfiguration();
   $label = $config['label'];
   if ($label != '<none>') {
-    //$block->setConfigurationValue('label', \Drupal::token()->replace($label, array(), array('sanitize' => TRUE)));
-    $data['#configuration']['label'] = \Drupal::token()->replace($label, array(), array('sanitize' => TRUE));
+    // The label is automatically escaped, avoid escaping it twice.
+    $build['#configuration']['label'] = \Drupal::token()->replace($label, array(), array('sanitize' => FALSE));
   }
 }
 
@@ -197,7 +198,6 @@ function token_block_view_alter(&$data, BlockPluginInterface $block) {
  */
 function token_form_block_form_alter(&$form, FormStateInterface $form_state) {
   $form['settings']['label']['#description'] = t('This field supports tokens.');
-  // @todo Figure out why this token validation does not seem to be working here.
   $form['settings']['label']['#element_validate'][] = 'token_element_validate';
   $form['settings']['label'] += array('#token_types' => array());
 }
@@ -606,7 +606,7 @@ function token_get_invalid_tokens($type, $tokens) {
 function token_element_validate(&$element, FormStateInterface $form_state) {
   $value = isset($element['#value']) ? $element['#value'] : $element['#default_value'];
 
-  if (!drupal_strlen($value)) {
+  if (!Unicode::strlen($value)) {
     // Empty value needs no further validation since the element should depend
     // on using the '#required' FAPI property.
     return $element;
diff --git a/token.tokens.inc b/token.tokens.inc
index 8e93636..09d989c 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -13,6 +13,7 @@ use Drupal\field\Entity\FieldStorageConfig;
 use Drupal\field\FieldStorageConfigInterface;
 use Drupal\field\FieldInstanceConfigInterface;
 use Drupal\system\Entity\Menu;
+use Drupal\user\UserInterface;
 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
 
 /**
@@ -578,7 +579,9 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
       switch ($name) {
         case 'picture':
           // ToDo: Use render arrays. See https://drupal.org/node/2195739
-          $replacements[$original] = _theme('user_picture', array('account' => $account));
+          if ($account instanceof UserInterface && $account->hasField('user_picture')) {
+            $replacements[$original] = _theme('user_picture', array('account' => $account));
+          }
           break;
 
         case 'roles':
@@ -590,7 +593,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
     }
 
     // Chained token relationships.
-    if (!empty($account->user_picture) && ($picture_tokens = \Drupal::token()->findWithPrefix($tokens, 'picture'))) {
+    if ($account instanceof UserInterface && $account->hasField('user_picture') && ($picture_tokens = \Drupal::token()->findWithPrefix($tokens, 'picture'))) {
       $replacements += \Drupal::token()->generate('file', $picture_tokens, array('file' => $account->user_picture->entity), $options);
     }
     if ($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) {
-- 
1.9.3 (Apple Git-50)


From ed9e91e33f89c992ae4976db40eb7a45c4f5428d Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Sun, 28 Sep 2014 17:13:54 +0200
Subject: [PATCH 194/230] Fixed cache tags

---
 token.module    | 2 +-
 token.pages.inc | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/token.module b/token.module
index 0c83b77..f3c4364 100644
--- a/token.module
+++ b/token.module
@@ -811,7 +811,7 @@ function token_build_tree($token_type, array $options = array()) {
     else {
       $options['parents'] = array();
       $trees[$tree_cid] = _token_build_tree($token_type, $options);
-      \Drupal::cache('data')->set($tree_cid, $trees[$tree_cid], Cache::PERMANENT, array(Token::TOKEN_INFO_CACHE_TAG => TRUE));
+      \Drupal::cache('data')->set($tree_cid, $trees[$tree_cid], Cache::PERMANENT, array(Token::TOKEN_INFO_CACHE_TAG));
     }
   }
 
diff --git a/token.pages.inc b/token.pages.inc
index dda284e..b4de79f 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -95,7 +95,7 @@ function theme_token_tree($variables) {
   $element = 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 => TRUE),
+      'tags' => array(Token::TOKEN_INFO_CACHE_TAG),
     ),
   );
   if ($cached_output = token_render_cache_get($element)) {
-- 
1.9.3 (Apple Git-50)


From b12503837c866b98baf66530a0a36a11982ab793 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Mon, 29 Sep 2014 12:30:55 +0200
Subject: [PATCH 195/230] Update for list_text change and name: => field_name

---
 ...ser.user.user_picture.yml => field.field.user.user.user_picture.yml} | 0
 .../config/install/field.storage.user.user_picture.yml                  | 2 +-
 token.module                                                            | 2 +-
 3 files changed, 2 insertions(+), 2 deletions(-)
 rename tests/token_user_picture/config/install/{field.instance.user.user.user_picture.yml => field.field.user.user.user_picture.yml} (100%)

diff --git a/tests/token_user_picture/config/install/field.instance.user.user.user_picture.yml b/tests/token_user_picture/config/install/field.field.user.user.user_picture.yml
similarity index 100%
rename from tests/token_user_picture/config/install/field.instance.user.user.user_picture.yml
rename to tests/token_user_picture/config/install/field.field.user.user.user_picture.yml
diff --git a/tests/token_user_picture/config/install/field.storage.user.user_picture.yml b/tests/token_user_picture/config/install/field.storage.user.user_picture.yml
index 986d7bf..2987390 100644
--- a/tests/token_user_picture/config/install/field.storage.user.user_picture.yml
+++ b/tests/token_user_picture/config/install/field.storage.user.user_picture.yml
@@ -1,7 +1,7 @@
 id: user.user_picture
 status: true
 langcode: en
-name: user_picture
+field_name: user_picture
 entity_type: user
 type: image
 settings:
diff --git a/token.module b/token.module
index f3c4364..acd5d04 100644
--- a/token.module
+++ b/token.module
@@ -227,7 +227,7 @@ function token_field_info_alter(&$info) {
     'text_with_summary' => 'text_default',
     'list_integer' => 'list_default',
     'list_float' => 'list_default',
-    'list_text' => 'list_default',
+    'list_string' => 'list_default',
     'list_boolean' => 'list_default',
   );
   foreach ($defaults as $field_type => $default_token_formatter) {
-- 
1.9.3 (Apple Git-50)


From a63fe21eb46ff7a6bbc45b705a553a8b56360330 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Mon, 29 Sep 2014 23:58:44 +0200
Subject: [PATCH 196/230] Check for a content entitiy instead of isFieldable()

---
 token.tokens.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index 09d989c..9fb05dc 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -1213,7 +1213,7 @@ function field_token_info_alter(&$info) {
 
   // Attach field tokens to their respecitve entity tokens.
   foreach (\Drupal::entityManager()->getDefinitions() as $entity_type_id => $entity_type) {
-    if (!$entity_type->isFieldable()) {
+    if (!$entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) {
       continue;
     }
 
-- 
1.9.3 (Apple Git-50)


From 59f3803500584203dcfeccbd07c0936912a2d1ca Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Tue, 30 Sep 2014 14:34:59 +0200
Subject: [PATCH 197/230] Fixed FieldInstanceConfigInterface is now
 FieldConfigInterface

---
 token.tokens.inc | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index 9fb05dc..b2899b3 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -9,9 +9,8 @@ use Drupal\Component\Utility\String;
 use Drupal\Core\Entity\ContentEntityInterface;
 use Drupal\Core\Render\Element;
 use Drupal\Component\Utility\Xss;
-use Drupal\field\Entity\FieldStorageConfig;
+use Drupal\field\FieldConfigInterface;
 use Drupal\field\FieldStorageConfigInterface;
-use Drupal\field\FieldInstanceConfigInterface;
 use Drupal\system\Entity\Menu;
 use Drupal\user\UserInterface;
 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
@@ -1274,7 +1273,7 @@ function _token_field_label($entity_type, $field_name) {
   // Count the amount of instances per label per field.
   foreach (array_keys(\Drupal::entityManager()->getBundleInfo($entity_type)) as $bundle) {
     $bundle_instances = array_filter(\Drupal::entityManager()->getFieldDefinitions($entity_type, $bundle), function ($field_definition) {
-        return $field_definition instanceof FieldInstanceConfigInterface;
+        return $field_definition instanceof FieldConfigInterface;
       });
     if (isset($bundle_instances[$field_name])) {
       $instance = $bundle_instances[$field_name];
@@ -1319,7 +1318,7 @@ function field_tokens($type, $tokens, array $data = array(), array $options = ar
 
     foreach (array_keys($fields) as $field_name) {
       // Do not continue if the field is empty or not a configurable field.
-      if (empty($entity->{$field_name}) || !($fields[$field_name] instanceof FieldInstanceConfigInterface)) {
+      if (empty($entity->{$field_name}) || !($fields[$field_name] instanceof FieldConfigInterface)) {
         continue;
       }
 
-- 
1.9.3 (Apple Git-50)


From b6d45c54efef5d7d84506089e1615b8f5fd25f2d Mon Sep 17 00:00:00 2001
From: Bas van der Heijden <bas.van.der.heijden@wunderkraut.com>
Date: Fri, 3 Oct 2014 14:57:38 +0200
Subject: [PATCH 198/230] Change token requirements to renderable array to
 allow html tags

---
 token.install | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.install b/token.install
index 8cf58ab..e0bb2cf 100644
--- a/token.install
+++ b/token.install
@@ -31,7 +31,7 @@ function token_requirements($phase = 'runtime') {
         'title' => t('Tokens'),
         'value' => t('Problems detected'),
         'severity' => REQUIREMENT_WARNING,
-        'description' => '<p>' . implode('</p><p>', $token_problems) . '</p>',
+        'description' => array('#markup' => '<p>' . implode('</p><p>', $token_problems) . '</p>'),
       );
     }
   }
-- 
1.9.3 (Apple Git-50)


From 06a7342ba2be2dd7274ebf127b1f78ebe1bcad5f Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Mon, 13 Oct 2014 22:34:54 +0200
Subject: [PATCH 199/230] Use getId() instead of ->id for current language.

---
 token.module | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.module b/token.module
index acd5d04..4cc4d3b 100644
--- a/token.module
+++ b/token.module
@@ -799,7 +799,7 @@ function token_build_tree($token_type, array $options = array()) {
     $token_type = $entity_token_type;
   }
 
-  $langcode = \Drupal::languageManager()->getCurrentLanguage()->id;
+  $langcode = \Drupal::languageManager()->getCurrentLanguage()->getId();
   $tree_cid = "token_tree:{$token_type}:{$langcode}:{$options['depth']}";
 
   // If we do not have this base tree in the static cache, check the cache
-- 
1.9.3 (Apple Git-50)


From 89b59717772ba365e2d5f0085efe715c65f43672 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Thu, 23 Oct 2014 23:13:33 +0200
Subject: [PATCH 200/230] Workaround for broken hook_module_implements_alter()

---
 token.module | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/token.module b/token.module
index 4cc4d3b..6bc8ab1 100644
--- a/token.module
+++ b/token.module
@@ -20,6 +20,10 @@ use Drupal\Core\Utility\Token;
  */
 define('TOKEN_MAX_DEPTH', 9);
 
+// @todo Hack until hook_module_implements_alter() works again, see
+//   https://www.drupal.org/node/2353357
+require_once __DIR__ . '/token.tokens.inc';
+
 /**
  * Implements hook_help().
  */
-- 
1.9.3 (Apple Git-50)


From f20d2ede8745e2b93724b9507da8afb92d4c385c Mon Sep 17 00:00:00 2001
From: Arild Matsson <arild@klavaro.se>
Date: Wed, 15 Oct 2014 16:15:47 +0200
Subject: [PATCH 201/230] Eradicating url() calls

---
 src/Tests/TokenCommentTestCase.php     | 14 +++++++-------
 src/Tests/TokenCurrentPageTestCase.php | 16 ++++++++--------
 src/Tests/TokenMenuTestCase.php        | 14 +++++++-------
 src/Tests/TokenNodeTestCase.php        | 12 ++++++------
 src/Tests/TokenTaxonomyTestCase.php    | 18 +++++++++---------
 token.tokens.inc                       | 17 +++++++++--------
 6 files changed, 46 insertions(+), 45 deletions(-)

diff --git a/src/Tests/TokenCommentTestCase.php b/src/Tests/TokenCommentTestCase.php
index be98e71..86901d3 100644
--- a/src/Tests/TokenCommentTestCase.php
+++ b/src/Tests/TokenCommentTestCase.php
@@ -35,9 +35,9 @@ class TokenCommentTestCase extends TokenTestBase {
     $parent_comment_path = ltrim($parent_comment_path, '/');
 
     $tokens = array(
-      'url' => url('comment/' . $parent_comment->id(), array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
-      'url:absolute' => url('comment/' . $parent_comment->id(), array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
-      'url:relative' => url('comment/' . $parent_comment->id(), array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => FALSE)),
+      'url' => \Drupal::url('entity.comment.canonical', ['comment' => $parent_comment->id()], array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
+      'url:absolute' => \Drupal::url('entity.comment.canonical', ['comment' => $parent_comment->id()], array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
+      'url:relative' => \Drupal::url('entity.comment.canonical', ['comment' => $parent_comment->id()], array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => FALSE)),
       'url:path' => $parent_comment_path,
       'parent:url:absolute' => NULL,
     );
@@ -61,11 +61,11 @@ class TokenCommentTestCase extends TokenTestBase {
     $comment_path = ltrim($comment_path, '/');
 
     $tokens = array(
-      'url' => url('comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id(), 'absolute' => TRUE)),
-      'url:absolute' => url('comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id(), 'absolute' => TRUE)),
-      'url:relative' => url('comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id(), 'absolute' => FALSE)),
+      'url' => \Drupal::url('entity.comment.canonical', ['comment' => $comment->id()], array('fragment' => 'comment-' . $comment->id(), 'absolute' => TRUE)),
+      'url:absolute' => \Drupal::url('entity.comment.canonical', ['comment' => $comment->id()], array('fragment' => 'comment-' . $comment->id(), 'absolute' => TRUE)),
+      'url:relative' => \Drupal::url('entity.comment.canonical', ['comment' => $comment->id()], array('fragment' => 'comment-' . $comment->id(), 'absolute' => FALSE)),
       'url:path' => $comment_path,
-      'parent:url:absolute' => url('comment/' . $parent_comment->id(), array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
+      'parent:url:absolute' => \Drupal::url('entity.comment.canonical', ['comment' => $parent_comment->id()], array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
     );
     $this->assertTokens('comment', array('comment' => $comment), $tokens);
   }
diff --git a/src/Tests/TokenCurrentPageTestCase.php b/src/Tests/TokenCurrentPageTestCase.php
index b66a80a..13d900d 100644
--- a/src/Tests/TokenCurrentPageTestCase.php
+++ b/src/Tests/TokenCurrentPageTestCase.php
@@ -19,13 +19,13 @@ class TokenCurrentPageTestCase extends TokenTestBase {
     $this->drupalGet('user');
     $tokens = array(
       '[current-page:title]' => t('Log in'),
-      '[current-page:url]' => url('user', array('absolute' => TRUE)),
-      '[current-page:url:absolute]' => url('user', array('absolute' => TRUE)),
-      '[current-page:url:relative]' => url('user', array('absolute' => FALSE)),
+      '[current-page:url]' => \Drupal::url('user.page', array('absolute' => TRUE)),
+      '[current-page:url:absolute]' => \Drupal::url('user.page', array('absolute' => TRUE)),
+      '[current-page:url:relative]' => \Drupal::url('user.page', array('absolute' => FALSE)),
       '[current-page:url:path]' => 'user',
       '[current-page:url:args:value:0]' => 'user',
       '[current-page:url:args:value:1]' => NULL,
-      '[current-page:url:unaliased]' => url('user', array('absolute' => TRUE, 'alias' => TRUE)),
+      '[current-page:url:unaliased]' => \Drupal::url('user.page', array('absolute' => TRUE, 'alias' => TRUE)),
       '[current-page:page-number]' => 1,
       '[current-page:query:foo]' => NULL,
       '[current-page:query:bar]' => NULL,
@@ -40,13 +40,13 @@ class TokenCurrentPageTestCase extends TokenTestBase {
     $node = $this->drupalCreateNode(array('title' => 'Node title', 'path' => array('alias' => 'node-alias')));
     $tokens = array(
       '[current-page:title]' => 'Node title',
-      '[current-page:url]' => url("node/{$node->id()}", array('absolute' => TRUE)),
-      '[current-page:url:absolute]' => url("node/{$node->id()}", array('absolute' => TRUE)),
-      '[current-page:url:relative]' => url("node/{$node->id()}", array('absolute' => FALSE)),
+      '[current-page:url]' => \Drupal::url('entity.node.canonical', ['node' => $node->id()], array('absolute' => TRUE)),
+      '[current-page:url:absolute]' => \Drupal::url('entity.node.canonical', ['node' => $node->id()], array('absolute' => TRUE)),
+      '[current-page:url:relative]' => \Drupal::url('entity.node.canonical', ['node' => $node->id()], array('absolute' => FALSE)),
       '[current-page:url:alias]' => 'node-alias',
       '[current-page:url:args:value:0]' => 'node-alias',
       '[current-page:url:args:value:1]' => NULL,
-      '[current-page:url:unaliased]' => url("node/{$node->id()}", array('absolute' => TRUE, 'alias' => TRUE)),
+      '[current-page:url:unaliased]' => \Drupal::url('entity.node.canonical', ['node' => $node->id()], array('absolute' => TRUE, 'alias' => TRUE)),
       '[current-page:url:unaliased:args:value:0]' => 'node',
       '[current-page:url:unaliased:args:value:1]' => $node->id(),
       '[current-page:url:unaliased:args:value:2]' => NULL,
diff --git a/src/Tests/TokenMenuTestCase.php b/src/Tests/TokenMenuTestCase.php
index 51311f0..876b0cb 100644
--- a/src/Tests/TokenMenuTestCase.php
+++ b/src/Tests/TokenMenuTestCase.php
@@ -50,13 +50,13 @@ class TokenMenuTestCase extends TokenTestBase {
       'menu:machine-name' => 'main-menu',
       'menu:description' => 'The <em>Main</em> menu is used on many sites to show the major sections of the site, often in a top navigation bar.',
       'menu:menu-link-count' => 2,
-      'menu:edit-url' => url("admin/structure/menu/manage/main-menu", array('absolute' => TRUE)),
-      'url' => url('admin/config', array('absolute' => TRUE)),
-      'url:absolute' => url('admin/config', array('absolute' => TRUE)),
-      'url:relative' => url('admin/config', array('absolute' => FALSE)),
+      'menu:edit-url' => \Drupal::url('entity.menu.edit_form', ['menu' => 'main-menu'], array('absolute' => TRUE)),
+      'url' => \Drupal::url('system.admin_config', array('absolute' => TRUE)),
+      'url:absolute' => \Drupal::url('system.admin_config', array('absolute' => TRUE)),
+      'url:relative' => \Drupal::url('system.admin_config', array('absolute' => FALSE)),
       'url:path' => 'admin/config',
       'url:alias' => 'admin/config',
-      'edit-url' => url("admin/structure/menu/item/{$parent_link->id()}/edit", array('absolute' => TRUE)),
+      'edit-url' => \Drupal::url('entity.menu_link_content.canonical', ['menu_link_content' => $parent_link->id()], array('absolute' => TRUE)),
       'parent' => 'Administration',
       'parent:mlid' => $root_link->id(),
       'parent:title' => 'Administration',
@@ -93,9 +93,9 @@ class TokenMenuTestCase extends TokenTestBase {
       'menu-link:mlid' => $node_link->id(),
       'menu-link:title' => 'Node link',
       'menu-link:menu' => 'Main menu',
-      'menu-link:url' => url('node/' . $node->id(), array('absolute' => TRUE)),
+      'menu-link:url' => \Drupal::url('entity.node.canonical', ['node' => $node->id()], array('absolute' => TRUE)),
       'menu-link:url:path' => 'node/' . $node->id(),
-      'menu-link:edit-url' => url("admin/structure/menu/item/{$node_link->id()}/edit", array('absolute' => TRUE)),
+      'menu-link:edit-url' => \Drupal::url('entity.menu_link_content.canonical', ['menu_link_content' => $node_link->id()], array('absolute' => TRUE)),
       'menu-link:parent' => 'Configuration',
       'menu-link:parent:mlid' => $parent_link->id(),
       'menu-link:parents' => 'Administration, Configuration',
diff --git a/src/Tests/TokenNodeTestCase.php b/src/Tests/TokenNodeTestCase.php
index c291390..bb714cd 100644
--- a/src/Tests/TokenNodeTestCase.php
+++ b/src/Tests/TokenNodeTestCase.php
@@ -22,15 +22,15 @@ class TokenNodeTestCase extends TokenTestBase {
       'source:nid' => NULL,
       'log' => $source_node->revision_log->value,
       'url:path' => 'content/source-node',
-      'url:absolute' => url("node/{$source_node->id()}", array('absolute' => TRUE)),
-      'url:relative' => url("node/{$source_node->id()}", array('absolute' => FALSE)),
+      'url:absolute' => \Drupal::url('entity.node.canonical', ['node' => $source_node->id()], array('absolute' => TRUE)),
+      'url:relative' => \Drupal::url('entity.node.canonical', ['node' => $source_node->id()], array('absolute' => FALSE)),
       'url:unaliased:path' => "node/{$source_node->id()}",
       'content-type' => 'Basic page',
       'content-type:name' => 'Basic page',
       'content-type:machine-name' => 'page',
       'content-type:description' => "Use <em>basic pages</em> for your static content, such as an 'About us' page.",
       'content-type:node-count' => 1,
-      'content-type:edit-url' => url('admin/structure/types/manage/page', array('absolute' => TRUE)),
+      'content-type:edit-url' => \Drupal::url('entity.node_type.edit_form', ['node_type' => 'page'], array('absolute' => TRUE)),
       // Deprecated tokens.
       'type' => 'page',
       'type-name' => 'Basic page',
@@ -44,15 +44,15 @@ class TokenNodeTestCase extends TokenTestBase {
       'source:nid' => $source_node->id(),
       'log' => '',
       'url:path' => "node/{$translated_node->id()}",
-      'url:absolute' => url("node/{$translated_node->id()}", array('absolute' => TRUE)),
-      'url:relative' => url("node/{$translated_node->id()}", array('absolute' => FALSE)),
+      'url:absolute' => \Drupal::url('entity.node.canonical', ['node' => $translated_node->id()], array('absolute' => TRUE)),
+      'url:relative' => \Drupal::url('entity.node.canonical', ['node' => $translated_node->id()], array('absolute' => FALSE)),
       'url:unaliased:path' => "node/{$translated_node->id()}",
       'content-type' => 'Article',
       'content-type:name' => 'Article',
       'content-type:machine-name' => 'article',
       'content-type:description' => "Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.",
       'content-type:node-count' => 1,
-      'content-type:edit-url' => url('admin/structure/types/manage/article', array('absolute' => TRUE)),
+      'content-type:edit-url' => \Drupal::url('entity.node_type.edit_form', ['node_type' => 'article'], array('absolute' => TRUE)),
       // Deprecated tokens.
       'type' => 'article',
       'type-name' => 'Article',
diff --git a/src/Tests/TokenTaxonomyTestCase.php b/src/Tests/TokenTaxonomyTestCase.php
index 1a36518..fe0a540 100644
--- a/src/Tests/TokenTaxonomyTestCase.php
+++ b/src/Tests/TokenTaxonomyTestCase.php
@@ -38,12 +38,12 @@ class TokenTaxonomyTestCase extends TokenTestBase {
   function testTaxonomyTokens() {
     $root_term = $this->addTerm($this->vocab, array('name' => 'Root term', 'path' => array('alias' => 'root-term')));
     $tokens = array(
-      'url' => url("taxonomy/term/{$root_term->id()}", array('absolute' => TRUE)),
-      'url:absolute' => url("taxonomy/term/{$root_term->id()}", array('absolute' => TRUE)),
-      'url:relative' => url("taxonomy/term/{$root_term->id()}", array('absolute' => FALSE)),
+      'url' => \Drupal::url('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], array('absolute' => TRUE)),
+      'url:absolute' => \Drupal::url('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], array('absolute' => TRUE)),
+      'url:relative' => \Drupal::url('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], array('absolute' => FALSE)),
       'url:path' => 'root-term',
       'url:unaliased:path' => "taxonomy/term/{$root_term->id()}",
-      'edit-url' => url("taxonomy/term/{$root_term->id()}/edit", array('absolute' => TRUE)),
+      'edit-url' => \Drupal::url('entity.taxonomy_term.edit_form', ['taxonomy_term' => $root_term->id()], array('absolute' => TRUE)),
       'parents' => NULL,
       'parents:count' => NULL,
       'parents:keys' => NULL,
@@ -55,12 +55,12 @@ class TokenTaxonomyTestCase extends TokenTestBase {
 
     $parent_term = $this->addTerm($this->vocab, array('name' => 'Parent term', 'parent' => $root_term->id()));
     $tokens = array(
-      'url' => url("taxonomy/term/{$parent_term->id()}", array('absolute' => TRUE)),
-      'url:absolute' => url("taxonomy/term/{$parent_term->id()}", array('absolute' => TRUE)),
-      'url:relative' => url("taxonomy/term/{$parent_term->id()}", array('absolute' => FALSE)),
+      'url' => \Drupal::url('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], array('absolute' => TRUE)),
+      'url:absolute' => \Drupal::url('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], array('absolute' => TRUE)),
+      'url:relative' => \Drupal::url('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], array('absolute' => FALSE)),
       'url:path' => "taxonomy/term/{$parent_term->id()}",
       'url:unaliased:path' => "taxonomy/term/{$parent_term->id()}",
-      'edit-url' => url("taxonomy/term/{$parent_term->id()}/edit", array('absolute' => TRUE)),
+      'edit-url' => \Drupal::url('entity.taxonomy_term.edit_form', ['taxonomy_term' => $parent_term->id()], array('absolute' => TRUE)),
       'parents' => 'Root term',
       'parents:count' => 1,
       'parents:keys' => $root_term->id(),
@@ -87,7 +87,7 @@ class TokenTaxonomyTestCase extends TokenTestBase {
     $vocabulary = $this->vocab;
     $tokens = array(
       'machine-name' => 'tags',
-      'edit-url' => url("admin/structure/taxonomy/{$vocabulary->id()}/edit", array('absolute' => TRUE)),
+      'edit-url' => \Drupal::url('entity.taxonomy_vocabulary.edit_form', ['taxonomy_vocabulary' => $vocabulary->id()], array('absolute' => TRUE)),
     );
     $this->assertTokens('vocabulary', array('vocabulary' => $vocabulary), $tokens);
   }
diff --git a/token.tokens.inc b/token.tokens.inc
index b2899b3..eefacac 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -9,6 +9,7 @@ use Drupal\Component\Utility\String;
 use Drupal\Core\Entity\ContentEntityInterface;
 use Drupal\Core\Render\Element;
 use Drupal\Component\Utility\Xss;
+use Drupal\Core\Url;
 use Drupal\field\FieldConfigInterface;
 use Drupal\field\FieldStorageConfigInterface;
 use Drupal\system\Entity\Menu;
@@ -479,7 +480,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
           $replacements[$original] = (int) $count;
           break;
         case 'edit-url':
-          $replacements[$original] = url("admin/structure/types/manage/{$node_type->type}", $url_options);
+          $replacements[$original] = \Drupal::url('entity.node_type.edit_form', ['node_type' => $node_type->type], $url_options);
           break;
       }
     }
@@ -493,7 +494,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'edit-url':
-          $replacements[$original] = url("taxonomy/term/{$term->id()}/edit", $url_options);
+          $replacements[$original] = \Drupal::url('entity.taxonomy_term.edit_form', ['taxonomy_term' => $term->id()], $url_options);
           break;
 
         case 'parents':
@@ -542,7 +543,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
           $replacements[$original] = $vocabulary->id();
           break;
         case 'edit-url':
-          $replacements[$original] = url("admin/structure/taxonomy/{$vocabulary->id()}/edit", $url_options);
+          $replacements[$original] = \Drupal::url('entity.taxonomy_vocabulary.edit_form', ['taxonomy_vocabulary' => $vocabulary->id()], $url_options);
           break;
       }
     }
@@ -682,7 +683,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
           $replacements[$original] = $sanitize ? $title : decode_entities($title);
           break;
         case 'url':
-          $replacements[$original] = url($current_path, $url_options);
+          $replacements[$original] = Url::fromUri(\Drupal::request()->getUri(), $url_options)->toString();
           break;
         case 'page-number':
           if ($page = \Drupal::request()->query->get('page')) {
@@ -808,8 +809,8 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'url':
-          if (_token_module($type, 'url') == 'token' && $uri = $entity->urlInfo()->toArray()) {
-            $replacements[$original] = url($uri['path'], $uri['options']);
+          if (_token_module($type, 'url') == 'token' && $url = $entity->urlInfo()) {
+            $replacements[$original] = $url;
           }
           break;
 
@@ -1157,7 +1158,7 @@ function menu_ui_tokens($type, $tokens, array $data = array(), array $options =
           }
           break;
         case 'edit-url':
-          $replacements[$original] = url("admin/structure/menu/item/{$link->id()}/edit", $url_options);
+          $replacements[$original] = \Drupal::url('entity.menu_link_content.canonical', ['menu_link_content' => $link->id()], $url_options);
           break;
       }
     }
@@ -1192,7 +1193,7 @@ function menu_ui_tokens($type, $tokens, array $data = array(), array $options =
           $replacements[$original] = (int) $count;
           break;
         case 'edit-url':
-          $replacements[$original] = url("admin/structure/menu/manage/" . $menu->id(), $url_options);
+          $replacements[$original] = \Drupal::url('entity.menu.edit_form', ['menu' => $menu->id()], $url_options);
           break;
       }
     }
-- 
1.9.3 (Apple Git-50)


From 923626d773ac0f3132654cf6de932f55302331f6 Mon Sep 17 00:00:00 2001
From: Arild Matsson <arild@klavaro.se>
Date: Wed, 15 Oct 2014 17:12:13 +0200
Subject: [PATCH 202/230] Added missing empty url() params

---
 src/Tests/TokenCurrentPageTestCase.php | 8 ++++----
 src/Tests/TokenMenuTestCase.php        | 6 +++---
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/Tests/TokenCurrentPageTestCase.php b/src/Tests/TokenCurrentPageTestCase.php
index 13d900d..8cfc603 100644
--- a/src/Tests/TokenCurrentPageTestCase.php
+++ b/src/Tests/TokenCurrentPageTestCase.php
@@ -19,13 +19,13 @@ class TokenCurrentPageTestCase extends TokenTestBase {
     $this->drupalGet('user');
     $tokens = array(
       '[current-page:title]' => t('Log in'),
-      '[current-page:url]' => \Drupal::url('user.page', array('absolute' => TRUE)),
-      '[current-page:url:absolute]' => \Drupal::url('user.page', array('absolute' => TRUE)),
-      '[current-page:url:relative]' => \Drupal::url('user.page', array('absolute' => FALSE)),
+      '[current-page:url]' => \Drupal::url('user.page', [], array('absolute' => TRUE)),
+      '[current-page:url:absolute]' => \Drupal::url('user.page', [], array('absolute' => TRUE)),
+      '[current-page:url:relative]' => \Drupal::url('user.page', [], array('absolute' => FALSE)),
       '[current-page:url:path]' => 'user',
       '[current-page:url:args:value:0]' => 'user',
       '[current-page:url:args:value:1]' => NULL,
-      '[current-page:url:unaliased]' => \Drupal::url('user.page', array('absolute' => TRUE, 'alias' => TRUE)),
+      '[current-page:url:unaliased]' => \Drupal::url('user.page', [], array('absolute' => TRUE, 'alias' => TRUE)),
       '[current-page:page-number]' => 1,
       '[current-page:query:foo]' => NULL,
       '[current-page:query:bar]' => NULL,
diff --git a/src/Tests/TokenMenuTestCase.php b/src/Tests/TokenMenuTestCase.php
index 876b0cb..bf9c093 100644
--- a/src/Tests/TokenMenuTestCase.php
+++ b/src/Tests/TokenMenuTestCase.php
@@ -51,9 +51,9 @@ class TokenMenuTestCase extends TokenTestBase {
       'menu:description' => 'The <em>Main</em> menu is used on many sites to show the major sections of the site, often in a top navigation bar.',
       'menu:menu-link-count' => 2,
       'menu:edit-url' => \Drupal::url('entity.menu.edit_form', ['menu' => 'main-menu'], array('absolute' => TRUE)),
-      'url' => \Drupal::url('system.admin_config', array('absolute' => TRUE)),
-      'url:absolute' => \Drupal::url('system.admin_config', array('absolute' => TRUE)),
-      'url:relative' => \Drupal::url('system.admin_config', array('absolute' => FALSE)),
+      'url' => \Drupal::url('system.admin_config', [], array('absolute' => TRUE)),
+      'url:absolute' => \Drupal::url('system.admin_config', [], array('absolute' => TRUE)),
+      'url:relative' => \Drupal::url('system.admin_config', [], array('absolute' => FALSE)),
       'url:path' => 'admin/config',
       'url:alias' => 'admin/config',
       'edit-url' => \Drupal::url('entity.menu_link_content.canonical', ['menu_link_content' => $parent_link->id()], array('absolute' => TRUE)),
-- 
1.9.3 (Apple Git-50)


From d478b020f2c7059ace57b1370b9d9f195928348a Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Tue, 28 Oct 2014 08:54:27 +0100
Subject: [PATCH 203/230] Fixed config dependency key

---
 .../config/install/field.field.user.user.user_picture.yml               | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/token_user_picture/config/install/field.field.user.user.user_picture.yml b/tests/token_user_picture/config/install/field.field.user.user.user_picture.yml
index a7a2ef7..887b6b0 100644
--- a/tests/token_user_picture/config/install/field.field.user.user.user_picture.yml
+++ b/tests/token_user_picture/config/install/field.field.user.user.user_picture.yml
@@ -27,5 +27,5 @@ settings:
   title_field_required: false
 field_type: image
 dependencies:
-  entity:
+  config:
     - field.storage.user.user_picture
-- 
1.9.3 (Apple Git-50)


From cec67f87da247ff7df3ae5ccf0dc5e7fb85dbbb9 Mon Sep 17 00:00:00 2001
From: anushka-mp <anushka.mp@live.com>
Date: Tue, 28 Oct 2014 11:50:58 +0100
Subject: [PATCH 204/230] Modifications done according to Sascha's comments

---
 src/Tests/TokenCommentTestCase.php     | 16 +++++++++-------
 src/Tests/TokenCurrentPageTestCase.php |  8 ++++----
 token.tokens.inc                       |  4 ++--
 3 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/src/Tests/TokenCommentTestCase.php b/src/Tests/TokenCommentTestCase.php
index 86901d3..11c0556 100644
--- a/src/Tests/TokenCommentTestCase.php
+++ b/src/Tests/TokenCommentTestCase.php
@@ -19,6 +19,7 @@ class TokenCommentTestCase extends TokenTestBase {
     \Drupal::service('comment.manager')->addDefaultField('node', 'page');
     $node = $this->drupalCreateNode();
 
+    /** @var \Drupal\comment\Entity\Comment $parent_comment */
     $parent_comment = entity_create('comment', array(
       'entity_id' => $node->id(),
       'entity_type' => 'node',
@@ -35,14 +36,15 @@ class TokenCommentTestCase extends TokenTestBase {
     $parent_comment_path = ltrim($parent_comment_path, '/');
 
     $tokens = array(
-      'url' => \Drupal::url('entity.comment.canonical', ['comment' => $parent_comment->id()], array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
-      'url:absolute' => \Drupal::url('entity.comment.canonical', ['comment' => $parent_comment->id()], array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
-      'url:relative' => \Drupal::url('entity.comment.canonical', ['comment' => $parent_comment->id()], array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => FALSE)),
+      'url' => $parent_comment->permalink()->setAbsolute()->toString(),
+      'url:absolute' => $parent_comment->permalink()->setAbsolute()->toString(),
+      'url:relative' => $parent_comment->permalink()->toString(),
       'url:path' => $parent_comment_path,
       'parent:url:absolute' => NULL,
     );
     $this->assertTokens('comment', array('comment' => $parent_comment), $tokens);
 
+    /** @var \Drupal\comment\Entity\Comment  $comment */
     $comment = entity_create('comment', array(
       'entity_id' => $node->id(),
       'pid' => $parent_comment->id(),
@@ -61,11 +63,11 @@ class TokenCommentTestCase extends TokenTestBase {
     $comment_path = ltrim($comment_path, '/');
 
     $tokens = array(
-      'url' => \Drupal::url('entity.comment.canonical', ['comment' => $comment->id()], array('fragment' => 'comment-' . $comment->id(), 'absolute' => TRUE)),
-      'url:absolute' => \Drupal::url('entity.comment.canonical', ['comment' => $comment->id()], array('fragment' => 'comment-' . $comment->id(), 'absolute' => TRUE)),
-      'url:relative' => \Drupal::url('entity.comment.canonical', ['comment' => $comment->id()], array('fragment' => 'comment-' . $comment->id(), 'absolute' => FALSE)),
+      'url' => $comment->permalink()->setAbsolute()->toString(),
+      'url:absolute' => $omment->permalink()->setAbsolute()->toString(),
+      'url:relative' => $comment->permalink()->toString(),
       'url:path' => $comment_path,
-      'parent:url:absolute' => \Drupal::url('entity.comment.canonical', ['comment' => $parent_comment->id()], array('fragment' => 'comment-' . $parent_comment->id(), 'absolute' => TRUE)),
+      'parent:url:absolute' => $parent_comment->permalink()->setAbsolute()->toString(),
     );
     $this->assertTokens('comment', array('comment' => $comment), $tokens);
   }
diff --git a/src/Tests/TokenCurrentPageTestCase.php b/src/Tests/TokenCurrentPageTestCase.php
index 8cfc603..16caa3a 100644
--- a/src/Tests/TokenCurrentPageTestCase.php
+++ b/src/Tests/TokenCurrentPageTestCase.php
@@ -40,13 +40,13 @@ class TokenCurrentPageTestCase extends TokenTestBase {
     $node = $this->drupalCreateNode(array('title' => 'Node title', 'path' => array('alias' => 'node-alias')));
     $tokens = array(
       '[current-page:title]' => 'Node title',
-      '[current-page:url]' => \Drupal::url('entity.node.canonical', ['node' => $node->id()], array('absolute' => TRUE)),
-      '[current-page:url:absolute]' => \Drupal::url('entity.node.canonical', ['node' => $node->id()], array('absolute' => TRUE)),
-      '[current-page:url:relative]' => \Drupal::url('entity.node.canonical', ['node' => $node->id()], array('absolute' => FALSE)),
+      '[current-page:url]' => $node->url('canonical', array('absolute' => TRUE)),
+      '[current-page:url:absolute]' => $node->url('canonical', array('absolute' => TRUE)),
+      '[current-page:url:relative]' => $node->url(),
       '[current-page:url:alias]' => 'node-alias',
       '[current-page:url:args:value:0]' => 'node-alias',
       '[current-page:url:args:value:1]' => NULL,
-      '[current-page:url:unaliased]' => \Drupal::url('entity.node.canonical', ['node' => $node->id()], array('absolute' => TRUE, 'alias' => TRUE)),
+      '[current-page:url:unaliased]' => $node->url('canonical', array('absolute' => TRUE, 'alias' => TRUE)),
       '[current-page:url:unaliased:args:value:0]' => 'node',
       '[current-page:url:unaliased:args:value:1]' => $node->id(),
       '[current-page:url:unaliased:args:value:2]' => NULL,
diff --git a/token.tokens.inc b/token.tokens.inc
index eefacac..36bfcda 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -480,7 +480,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
           $replacements[$original] = (int) $count;
           break;
         case 'edit-url':
-          $replacements[$original] = \Drupal::url('entity.node_type.edit_form', ['node_type' => $node_type->type], $url_options);
+          $replacements[$original] = $node_type->url('edit-form', $url_options);
           break;
       }
     }
@@ -810,7 +810,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
       switch ($name) {
         case 'url':
           if (_token_module($type, 'url') == 'token' && $url = $entity->urlInfo()) {
-            $replacements[$original] = $url;
+            $replacements[$original] = $url->toString();
           }
           break;
 
-- 
1.9.3 (Apple Git-50)


From a16dc362262fc4ac444502c8f47badf1e289a48c Mon Sep 17 00:00:00 2001
From: anushka-mp <anushka.mp@live.com>
Date: Tue, 28 Oct 2014 14:45:48 +0100
Subject: [PATCH 205/230] used the url() for the nested url tokens as well

---
 src/Tests/TokenCommentTestCase.php |  4 +--
 token.tokens.inc                   | 64 ++++++++++++++------------------------
 2 files changed, 25 insertions(+), 43 deletions(-)

diff --git a/src/Tests/TokenCommentTestCase.php b/src/Tests/TokenCommentTestCase.php
index 11c0556..d14acb7 100644
--- a/src/Tests/TokenCommentTestCase.php
+++ b/src/Tests/TokenCommentTestCase.php
@@ -32,7 +32,7 @@ class TokenCommentTestCase extends TokenTestBase {
     $parent_comment->save();
 
     // Fix http://example.com/index.php/comment/1 fails 'url:path' test.
-    $parent_comment_path = \Drupal::url('entity.comment.canonical', array('comment' => $parent_comment->id()));
+    $parent_comment_path = $parent_comment->url();
     $parent_comment_path = ltrim($parent_comment_path, '/');
 
     $tokens = array(
@@ -64,7 +64,7 @@ class TokenCommentTestCase extends TokenTestBase {
 
     $tokens = array(
       'url' => $comment->permalink()->setAbsolute()->toString(),
-      'url:absolute' => $omment->permalink()->setAbsolute()->toString(),
+      'url:absolute' => $comment->permalink()->setAbsolute()->toString(),
       'url:relative' => $comment->permalink()->toString(),
       'url:path' => $comment_path,
       'parent:url:absolute' => $parent_comment->permalink()->setAbsolute()->toString(),
diff --git a/token.tokens.inc b/token.tokens.inc
index 36bfcda..21bb5cf 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -415,9 +415,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
     // Chained token relationships.
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
       // Add fragment to url options.
-      $comment_data = $comment->urlInfo()->toArray();
-      $comment_data['options'] += array('fragment' => 'comment-' . $comment->id());
-      $replacements += \Drupal::token()->generate('url', $url_tokens, $comment_data, $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, array('url' => $comment->permalink()), $options);
     }
   }
 
@@ -452,7 +450,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
       $replacements += \Drupal::token()->generate('content-type', $node_type_tokens, array('node_type' => $node_type), $options);
     }
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, $node->urlInfo()->toArray(), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, array('url' => $node->urlInfo()), $options);
     }
   }
 
@@ -515,7 +513,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
 
     // Chained token relationships.
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, $term->urlInfo()->toArray(), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, array('url' => $term->urlInfo()), $options);
     }
     // [term:parents:*] chained tokens.
     if ($parents_tokens = \Drupal::token()->findWithPrefix($tokens, 'parents')) {
@@ -597,7 +595,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
       $replacements += \Drupal::token()->generate('file', $picture_tokens, array('file' => $account->user_picture->entity), $options);
     }
     if ($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, $account->urlInfo()->toArray(), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, array('url' => $account->urlInfo()), $options);
     }
     if ($role_tokens = \Drupal::token()->findWithPrefix($tokens, 'roles')) {
       $roles = $account->getRoles();
@@ -665,7 +663,8 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
       $replacements += \Drupal::token()->generate('menu-link', $root_tokens, array('menu-link' => $root), $options);
     }
     if ($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, array('route_name' => $link->route_name, 'route_parameters' => $link->route_parameters), $options);
+      $url = new Url($link->route_name, $link->route_parameters);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, array('url' => $url), $options);
     }
 
   }
@@ -727,33 +726,22 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
     // Chained token relationships.
     if ($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) {
       $request = \Drupal::request();
-      $url_data['route_name'] = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT);
-      $url_data['route_parameters'] = $request->attributes->get('_raw_variables')->all();
-      $replacements += \Drupal::token()->generate('url', $url_tokens, $url_data, $options);
+      $url = new Url($request->attributes->get(RouteObjectInterface::ROUTE_OBJECT), $request->attributes->get('_raw_variables')->all());
+      $replacements += \Drupal::token()->generate('url', $url_tokens, array('url' => $url), $options);
     }
   }
 
   // URL tokens.
-  if ($type == 'url' && !empty($data['route_name'])) {
-    $route = $data['route_name'];
-    $route_param = array();
-    if (isset($data['route_parameters'])) {
-      $route_param = $data['route_parameters'];
-    }
-    $url_options = array();
-    if (isset($data['options'])) {
-      // Merge in the URL options if available.
-      $url_options = $data['options'] + $url_options;
-    }
-    $path_url_options = $url_options;
-    unset($path_url_options['fragment']);
-    $path = \Drupal::url($route, $route_param, $path_url_options);
+  if ($type == 'url' && !empty($data['url'])) {
+    $url = $data['url'];
+    $path_url = clone $url;
+    $path = $path_url->setOption('fragment', NULL)->toString();
     $path = ltrim($path, '/');
 
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'path':
-          $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $language_code) : $path;
+          $value = !($url->getOption('alias')) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $language_code) : $path;
           $replacements[$original] = $sanitize ? String::checkPlain($value) : $value;
           break;
         case 'alias':
@@ -762,21 +750,19 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
           $replacements[$original] = $sanitize ? String::checkPlain($alias) : $alias;
           break;
         case 'absolute':
-          $replacements[$original] = \Drupal::url($route, $route_param, array('absolute' => TRUE) + $url_options);
+          $replacements[$original] = $url->setAbsolute()->toString();
           break;
         case 'relative':
-          $replacements[$original] = \Drupal::url($route, $route_param, array('absolute' => FALSE) + $url_options);
+          $replacements[$original] = $url->setAbsolute(FALSE)->toString();
           break;
         case 'brief':
-          $url_options['absolute'] = TRUE;
-          $replacements[$original] = preg_replace(array('!^https?://!', '!/$!'), '', \Drupal::url($route, $route_param, $url_options));
+          $replacements[$original] = preg_replace(array('!^https?://!', '!/$!'), '', $url->setAbsolute()->toString());
           break;
         case 'unaliased':
-          $url_options['absolute'] = TRUE;
-          $replacements[$original] = \Drupal::url($route, $route_param, array('alias' => TRUE) + $url_options);
+          $replacements[$original] = $url->setAbsolute()->setOptions(array('alias' => TRUE))->toString();
           break;
         case 'args':
-          $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $language_code) : $path;
+          $value = !($url->getOption('alias')) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $language_code) : $path;
           $replacements[$original] = token_render_array(explode('/', $value), $options);
           break;
 
@@ -792,12 +778,8 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
 
     // [url:unaliased:*] chained tokens.
     if ($unaliased_tokens = \Drupal::token()->findWithPrefix($tokens, 'unaliased')) {
-      $unaliased_token_data['route_name'] = $route;
-      $unaliased_token_data['route_parameters'] = $route_param;
-      $unaliased_token_data['path'] = $path;
-      $unaliased_token_data['options'] = isset($data['options']) ? $data['options'] : array();
-      $unaliased_token_data['options']['alias'] = TRUE;
-      $replacements += \Drupal::token()->generate('url', $unaliased_tokens, $unaliased_token_data, $options);
+      $url->setOption('alias', TRUE);
+      $replacements += \Drupal::token()->generate('url', $unaliased_tokens, array('url' => $url), $options);
     }
   }
 
@@ -809,8 +791,8 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'url':
-          if (_token_module($type, 'url') == 'token' && $url = $entity->urlInfo()) {
-            $replacements[$original] = $url->toString();
+          if (_token_module($type, 'url') == 'token' && $url = $entity->url()) {
+            $replacements[$original] = $url;
           }
           break;
 
@@ -825,7 +807,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
 
     // [entity:url:*] chained tokens.
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) && _token_module($type, 'url') == 'token') {
-      $replacements += \Drupal::token()->generate('url', $url_tokens, $entity->urlInfo()->toArray(), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, array('url' => $entity->urlInfo()), $options);
     }
 
     // [entity:original:*] chained tokens.
-- 
1.9.3 (Apple Git-50)


From a77d6c4952857763991dd76807acfedc8f6d52a5 Mon Sep 17 00:00:00 2001
From: Arild Matsson <arild@klavaro.se>
Date: Wed, 29 Oct 2014 09:58:30 +0100
Subject: [PATCH 206/230] Fixed TokenCurrentPageTestCase

---
 src/Tests/TokenCurrentPageTestCase.php | 21 +++++++++++----------
 token.tokens.inc                       | 11 ++++++-----
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/src/Tests/TokenCurrentPageTestCase.php b/src/Tests/TokenCurrentPageTestCase.php
index 16caa3a..858e7a0 100644
--- a/src/Tests/TokenCurrentPageTestCase.php
+++ b/src/Tests/TokenCurrentPageTestCase.php
@@ -16,25 +16,26 @@ class TokenCurrentPageTestCase extends TokenTestBase {
   protected static $modules = array('path', 'token', 'token_test', 'node');
 
   function testCurrentPageTokens() {
-    $this->drupalGet('user');
     $tokens = array(
       '[current-page:title]' => t('Log in'),
-      '[current-page:url]' => \Drupal::url('user.page', [], array('absolute' => TRUE)),
-      '[current-page:url:absolute]' => \Drupal::url('user.page', [], array('absolute' => TRUE)),
-      '[current-page:url:relative]' => \Drupal::url('user.page', [], array('absolute' => FALSE)),
-      '[current-page:url:path]' => 'user',
+      '[current-page:url]' => \Drupal::url('user.login', [], array('absolute' => TRUE)),
+      '[current-page:url:absolute]' => \Drupal::url('user.login', [], array('absolute' => TRUE)),
+      '[current-page:url:relative]' => \Drupal::url('user.login'),
+      '[current-page:url:path]' => 'user/login',
       '[current-page:url:args:value:0]' => 'user',
-      '[current-page:url:args:value:1]' => NULL,
-      '[current-page:url:unaliased]' => \Drupal::url('user.page', [], array('absolute' => TRUE, 'alias' => TRUE)),
+      '[current-page:url:args:value:1]' => 'login',
+      '[current-page:url:args:value:2]' => NULL,
+      '[current-page:url:unaliased]' => \Drupal::url('user.login', [], array('absolute' => TRUE, 'alias' => TRUE)),
       '[current-page:page-number]' => 1,
       '[current-page:query:foo]' => NULL,
       '[current-page:query:bar]' => NULL,
-      '[current-page:query:q]' => 'user',
+      '[current-page:query:q]' => 'user/login',
       // Deprecated tokens
       '[current-page:arg:0]' => 'user',
-      '[current-page:arg:1]' => NULL,
+      '[current-page:arg:1]' => 'login',
+      '[current-page:arg:2]' => NULL,
     );
-    $this->assertPageTokens('', $tokens);
+    $this->assertPageTokens('user/login', $tokens);
 
     $this->drupalCreateContentType(array('type' => 'page'));
     $node = $this->drupalCreateNode(array('title' => 'Node title', 'path' => array('alias' => 'node-alias')));
diff --git a/token.tokens.inc b/token.tokens.inc
index 21bb5cf..639dc52 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -671,8 +671,6 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
 
   // Current page tokens.
   if ($type == 'current-page') {
-    $current_path = current_path();
-
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'title':
@@ -682,7 +680,9 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
           $replacements[$original] = $sanitize ? $title : decode_entities($title);
           break;
         case 'url':
-          $replacements[$original] = Url::fromUri(\Drupal::request()->getUri(), $url_options)->toString();
+          // Strip the query string from the result of Request::getUri().
+          list($uri) = explode('?', \Drupal::request()->getUri());
+          $replacements[$original] = Url::fromUri($uri, $url_options)->toString();
           break;
         case 'page-number':
           if ($page = \Drupal::request()->query->get('page')) {
@@ -733,6 +733,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
 
   // URL tokens.
   if ($type == 'url' && !empty($data['url'])) {
+    /** @var \Drupal\Core\Url $url */
     $url = $data['url'];
     $path_url = clone $url;
     $path = $path_url->setOption('fragment', NULL)->toString();
@@ -759,7 +760,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
           $replacements[$original] = preg_replace(array('!^https?://!', '!/$!'), '', $url->setAbsolute()->toString());
           break;
         case 'unaliased':
-          $replacements[$original] = $url->setAbsolute()->setOptions(array('alias' => TRUE))->toString();
+          $replacements[$original] = $url->setAbsolute()->setOption('alias', TRUE)->toString();
           break;
         case 'args':
           $value = !($url->getOption('alias')) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $language_code) : $path;
@@ -771,7 +772,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
 
     // [url:arg:*] chained tokens.
     if ($arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'args')) {
-      $value = empty($url_options['alias']) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $language_code) : $path;
+      $value = !($url->getOption('alias')) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $language_code) : $path;
       $value = ltrim($value, '/');
       $replacements += \Drupal::token()->generate('array', $arg_tokens, array('array' => explode('/', $value)), $options);
     }
-- 
1.9.3 (Apple Git-50)


From 9a6916dd086177e1f654304f8a8558df5eadb9e8 Mon Sep 17 00:00:00 2001
From: Arild Matsson <arild@klavaro.se>
Date: Wed, 29 Oct 2014 10:27:40 +0100
Subject: [PATCH 207/230] Fixed TokenCommentTestCase

Could not use `permalink()` because it returns `node/1#comment-1` when we
expect `comment/1#comment-1`. We _should_ probably change that expectation, but
that requires some further tinkering, e.g. the part in `token_tokens()` that
renders `[(any entity):url]` calls `$entity->url()` which differs from
`$comment->permalink()`.
---
 src/Tests/TokenCommentTestCase.php | 14 +++++++-------
 token.tokens.inc                   |  3 ++-
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/Tests/TokenCommentTestCase.php b/src/Tests/TokenCommentTestCase.php
index d14acb7..3642bf1 100644
--- a/src/Tests/TokenCommentTestCase.php
+++ b/src/Tests/TokenCommentTestCase.php
@@ -36,9 +36,9 @@ class TokenCommentTestCase extends TokenTestBase {
     $parent_comment_path = ltrim($parent_comment_path, '/');
 
     $tokens = array(
-      'url' => $parent_comment->permalink()->setAbsolute()->toString(),
-      'url:absolute' => $parent_comment->permalink()->setAbsolute()->toString(),
-      'url:relative' => $parent_comment->permalink()->toString(),
+      'url' => $parent_comment->urlInfo('canonical', ['fragment' => "comment-{$parent_comment->id()}"])->setAbsolute()->toString(),
+      'url:absolute' => $parent_comment->urlInfo('canonical', ['fragment' => "comment-{$parent_comment->id()}"])->setAbsolute()->toString(),
+      'url:relative' => $parent_comment->urlInfo('canonical', ['fragment' => "comment-{$parent_comment->id()}"])->toString(),
       'url:path' => $parent_comment_path,
       'parent:url:absolute' => NULL,
     );
@@ -63,11 +63,11 @@ class TokenCommentTestCase extends TokenTestBase {
     $comment_path = ltrim($comment_path, '/');
 
     $tokens = array(
-      'url' => $comment->permalink()->setAbsolute()->toString(),
-      'url:absolute' => $comment->permalink()->setAbsolute()->toString(),
-      'url:relative' => $comment->permalink()->toString(),
+      'url' => $comment->urlInfo('canonical', ['fragment' => "comment-{$comment->id()}"])->setAbsolute()->toString(),
+      'url:absolute' => $comment->urlInfo('canonical', ['fragment' => "comment-{$comment->id()}"])->setAbsolute()->toString(),
+      'url:relative' => $comment->urlInfo('canonical', ['fragment' => "comment-{$comment->id()}"])->toString(),
       'url:path' => $comment_path,
-      'parent:url:absolute' => $parent_comment->permalink()->setAbsolute()->toString(),
+      'parent:url:absolute' => $parent_comment->urlInfo('canonical', ['fragment' => "comment-{$parent_comment->id()}"])->setAbsolute()->toString(),
     );
     $this->assertTokens('comment', array('comment' => $comment), $tokens);
   }
diff --git a/token.tokens.inc b/token.tokens.inc
index 639dc52..c7e2f18 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -415,7 +415,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
     // Chained token relationships.
     if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
       // Add fragment to url options.
-      $replacements += \Drupal::token()->generate('url', $url_tokens, array('url' => $comment->permalink()), $options);
+      $replacements += \Drupal::token()->generate('url', $url_tokens, array('url' => $comment->urlInfo('canonical', ['fragment' => "comment-{$comment->id()}"])), $options);
     }
   }
 
@@ -735,6 +735,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
   if ($type == 'url' && !empty($data['url'])) {
     /** @var \Drupal\Core\Url $url */
     $url = $data['url'];
+    // To retrieve a path without fragment, modify a copy of the Url object.
     $path_url = clone $url;
     $path = $path_url->setOption('fragment', NULL)->toString();
     $path = ltrim($path, '/');
-- 
1.9.3 (Apple Git-50)


From 256d1e49e1d34d44286cd892e89de27fb129b8c6 Mon Sep 17 00:00:00 2001
From: Arild Matsson <arild@klavaro.se>
Date: Wed, 29 Oct 2014 12:34:54 +0100
Subject: [PATCH 208/230] Fixed some of TokenURLTestCase and TokenMenuTestCase

TokenMenuTestCase needs menu_link_content-related changes but not in this pull
request. I did sneak in a YAML 'entity:' key update though.
---
 src/Tests/TokenMenuTestCase.php                                |  6 +++---
 src/Tests/TokenURLTestCase.php                                 |  3 ++-
 .../config/install/field.field.user.user.user_picture.yml      |  2 +-
 token.tokens.inc                                               | 10 +++++-----
 4 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/Tests/TokenMenuTestCase.php b/src/Tests/TokenMenuTestCase.php
index bf9c093..cb85f22 100644
--- a/src/Tests/TokenMenuTestCase.php
+++ b/src/Tests/TokenMenuTestCase.php
@@ -33,7 +33,7 @@ class TokenMenuTestCase extends TokenTestBase {
 
     // Add another link with the root link as the parent
     $parent_link = entity_create('menu_link_content', array(
-      'url' => 'admin/config',
+      'route_name' => 'system.admin_config',
       'title' => 'Configuration',
       'menu_name' => 'main-menu',
       'parent' => 'menu_link_content:' . $root_link->uuid(),
@@ -93,9 +93,9 @@ class TokenMenuTestCase extends TokenTestBase {
       'menu-link:mlid' => $node_link->id(),
       'menu-link:title' => 'Node link',
       'menu-link:menu' => 'Main menu',
-      'menu-link:url' => \Drupal::url('entity.node.canonical', ['node' => $node->id()], array('absolute' => TRUE)),
+      'menu-link:url' => $node->url('canonical', ['absolute' => TRUE]),
       'menu-link:url:path' => 'node/' . $node->id(),
-      'menu-link:edit-url' => \Drupal::url('entity.menu_link_content.canonical', ['menu_link_content' => $node_link->id()], array('absolute' => TRUE)),
+      'menu-link:edit-url' => $node_link->url('canonical', ['absolute' => TRUE]),
       'menu-link:parent' => 'Configuration',
       'menu-link:parent:mlid' => $parent_link->id(),
       'menu-link:parents' => 'Administration, Configuration',
diff --git a/src/Tests/TokenURLTestCase.php b/src/Tests/TokenURLTestCase.php
index de50d7b..327db39 100644
--- a/src/Tests/TokenURLTestCase.php
+++ b/src/Tests/TokenURLTestCase.php
@@ -5,6 +5,7 @@
  * Contains \Drupal\token\Tests\TokenURLTestCase.
  */
 namespace Drupal\token\Tests;
+use Drupal\Core\Url;
 
 /**
  * Tests url tokens.
@@ -42,6 +43,6 @@ class TokenURLTestCase extends TokenTestBase {
       // Deprecated tokens.
       'alias' => 'first-node',
     );
-    $this->assertTokens('url', array('route_name' => 'entity.node.canonical', 'route_parameters' => array('node' => 1)), $tokens);
+    $this->assertTokens('url', array('url' => new Url('entity.node.canonical', array('node' => 1))), $tokens);
   }
 }
diff --git a/tests/token_user_picture/config/install/field.field.user.user.user_picture.yml b/tests/token_user_picture/config/install/field.field.user.user.user_picture.yml
index a7a2ef7..887b6b0 100644
--- a/tests/token_user_picture/config/install/field.field.user.user.user_picture.yml
+++ b/tests/token_user_picture/config/install/field.field.user.user.user_picture.yml
@@ -27,5 +27,5 @@ settings:
   title_field_required: false
 field_type: image
 dependencies:
-  entity:
+  config:
     - field.storage.user.user_picture
diff --git a/token.tokens.inc b/token.tokens.inc
index c7e2f18..dd5529f 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -629,7 +629,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
           $replacements[$original] = $sanitize ? String::checkPlain($link->label()) : $link->label();
           break;
         case 'url':
-          $replacements[$original] = \Drupal::url($link->getRouteName(), $link->route_parameters, !empty($link->localized_options) ? $link->localized_options : array('absolute' => TRUE));
+          $replacements[$original] = $link->getUrlObject()->setAbsolute()->toString();
           break;
         case 'parent':
           if (!empty($link->plid) && $parent = menu_link_load($link->plid)) {
@@ -735,9 +735,9 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
   if ($type == 'url' && !empty($data['url'])) {
     /** @var \Drupal\Core\Url $url */
     $url = $data['url'];
-    // To retrieve a path without fragment, modify a copy of the Url object.
+    // To retrieve the correct path, modify a copy of the Url object.
     $path_url = clone $url;
-    $path = $path_url->setOption('fragment', NULL)->toString();
+    $path = $path_url->setAbsolute(FALSE)->setOption('fragment', NULL)->toString();
     $path = ltrim($path, '/');
 
     foreach ($tokens as $name => $original) {
@@ -771,7 +771,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
       }
     }
 
-    // [url:arg:*] chained tokens.
+    // [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 = ltrim($value, '/');
@@ -1142,7 +1142,7 @@ function menu_ui_tokens($type, $tokens, array $data = array(), array $options =
           }
           break;
         case 'edit-url':
-          $replacements[$original] = \Drupal::url('entity.menu_link_content.canonical', ['menu_link_content' => $link->id()], $url_options);
+          $replacements[$original] = $link->url($url_options);
           break;
       }
     }
-- 
1.9.3 (Apple Git-50)


From ef08798c69f88bc3f6f0260e0f401faf18e57f1a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tobias=20St=C3=B6ckler?= <tobiasstoeckler@googlemail.com>
Date: Fri, 31 Oct 2014 12:10:45 +0100
Subject: [PATCH 209/230] theme_token_tree_link() uses \Drupal::l() incorrectly
 (after core API change)

---
 token.pages.inc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/token.pages.inc b/token.pages.inc
index b4de79f..22711c9 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -5,6 +5,7 @@
  * User page callbacks for the token module.
  */
 use Drupal\Component\Serialization\Json;
+use Drupal\Core\Url;
 use Drupal\Core\Utility\Token;
 
 /**
@@ -47,7 +48,7 @@ function theme_token_tree_link($variables) {
    );
   $variables['options']['attributes']['class'][] = 'use-ajax';
 
-  return Drupal::l($variables['text'], 'token.tree', array(), $variables['options']);
+  return Drupal::l($variables['text'], Url::fromRoute('token.tree', array(), $variables['options']));
 }
 
 /**
-- 
1.9.3 (Apple Git-50)


From 64234390b04b9456607f2de33d170fbe6d884154 Mon Sep 17 00:00:00 2001
From: marcingy <marcingy@gmail.com>
Date: Tue, 4 Nov 2014 14:42:08 -0700
Subject: [PATCH 210/230] Fix references to drupal_strlower

---
 src/Tests/TokenEntityTestCase.php   | 3 ++-
 src/Tests/TokenTaxonomyTestCase.php | 5 +++--
 token.tokens.inc                    | 7 ++++---
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/Tests/TokenEntityTestCase.php b/src/Tests/TokenEntityTestCase.php
index 6899646..2324aba 100644
--- a/src/Tests/TokenEntityTestCase.php
+++ b/src/Tests/TokenEntityTestCase.php
@@ -5,6 +5,7 @@
  * Contains \Drupal\token\Tests\TokenEntityTestCase.
  */
 namespace Drupal\token\Tests;
+use Drupal\Component\Utility\Unicode;
 use Drupal\taxonomy\VocabularyInterface;
 
 /**
@@ -52,7 +53,7 @@ class TokenEntityTestCase extends TokenTestBase {
 
   function addTerm(VocabularyInterface $vocabulary, array $term = array()) {
     $term += array(
-      'name' => drupal_strtolower($this->randomMachineName(5)),
+      'name' => Unicode::strtolower($this->randomMachineName(5)),
       'vid' => $vocabulary->id(),
     );
     $term = entity_create('taxonomy_term', $term);
diff --git a/src/Tests/TokenTaxonomyTestCase.php b/src/Tests/TokenTaxonomyTestCase.php
index fe0a540..8136cb4 100644
--- a/src/Tests/TokenTaxonomyTestCase.php
+++ b/src/Tests/TokenTaxonomyTestCase.php
@@ -6,6 +6,7 @@
  */
 namespace Drupal\token\Tests;
 use Drupal\Component\Utility\String;
+use Drupal\Component\Utility\Unicode;
 
 /**
  * Tests taxonomy tokens.
@@ -94,7 +95,7 @@ class TokenTaxonomyTestCase extends TokenTestBase {
 
   function addVocabulary(array $vocabulary = array()) {
     $vocabulary += array(
-      'name' => drupal_strtolower($this->randomMachineName(5)),
+      'name' => Unicode::strtolower($this->randomMachineName(5)),
       'nodes' => array('article' => 'article'),
     );
     $vocabulary = entity_create('taxonomy_vocabulary', $vocabulary)->save();
@@ -103,7 +104,7 @@ class TokenTaxonomyTestCase extends TokenTestBase {
 
   function addTerm($vocabulary, array $term = array()) {
     $term += array(
-      'name' => drupal_strtolower($this->randomMachineName(5)),
+      'name' => Unicode::strtolower($this->randomMachineName(5)),
       'vid' => $vocabulary->id(),
     );
     $term = entity_create('taxonomy_term', $term);
diff --git a/token.tokens.inc b/token.tokens.inc
index dd5529f..20b906d 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -6,6 +6,7 @@
  */
 use Drupal\Component\Utility\Crypt;
 use Drupal\Component\Utility\String;
+use Drupal\Component\Utility\Unicode;
 use Drupal\Core\Entity\ContentEntityInterface;
 use Drupal\Core\Render\Element;
 use Drupal\Component\Utility\Xss;
@@ -73,7 +74,7 @@ function token_token_info_alter(&$info) {
     if (!isset($info['tokens'][$token_type]['url'])) {
       $info['tokens'][$token_type]['url'] = array(
         'name' => t('URL'),
-        'description' => t('The URL of the @entity.', array('@entity' => drupal_strtolower($entity_info->getLabel()))),
+        'description' => t('The URL of the @entity.', array('@entity' => Unicode::strtolower($entity_info->getLabel()))),
         'module' => 'token',
         'type' => 'url',
       );
@@ -82,8 +83,8 @@ function token_token_info_alter(&$info) {
     // Add [entity:original] tokens if they do not already exist.
     if (!isset($info['tokens'][$token_type]['original'])) {
       $info['tokens'][$token_type]['original'] = array(
-        'name' => t('Original @entity', array('@entity' => drupal_strtolower($entity_info->getLabel()))),
-        'description' => t('The original @entity data if the @entity is being updated or saved.', array('@entity' => drupal_strtolower($entity_info->getLabel()))),
+        'name' => t('Original @entity', array('@entity' => Unicode::strtolower($entity_info->getLabel()))),
+        'description' => t('The original @entity data if the @entity is being updated or saved.', array('@entity' => Unicode::strtolower($entity_info->getLabel()))),
         'module' => 'token',
         'type' => $token_type,
       );
-- 
1.9.3 (Apple Git-50)


From 6520add13cf339b9186873ffe1e55d7767018a5a Mon Sep 17 00:00:00 2001
From: Kim Pepper <kim@pepper.id.au>
Date: Fri, 7 Nov 2014 10:08:35 +1100
Subject: [PATCH 211/230] Replace removed string functions

---
 src/Controller/TokenAutocompleteController.php | 5 +++--
 token.tokens.inc                               | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/Controller/TokenAutocompleteController.php b/src/Controller/TokenAutocompleteController.php
index 87efca1..8aadff3 100644
--- a/src/Controller/TokenAutocompleteController.php
+++ b/src/Controller/TokenAutocompleteController.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\token\Controller;
 
+use Drupal\Component\Utility\Unicode;
 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\HttpFoundation\JsonResponse;
@@ -50,7 +51,7 @@ class TokenAutocompleteController implements ContainerInjectionInterface {
 
     $matches = array();
 
-    if (!drupal_strlen($filter)) {
+    if (!Unicode::strlen($filter)) {
       $matches["[{$token_type}:"] = 0;
     }
     else {
@@ -75,4 +76,4 @@ class TokenAutocompleteController implements ContainerInjectionInterface {
     return new JsonResponse($matches);
   }
 
-}
\ No newline at end of file
+}
diff --git a/token.tokens.inc b/token.tokens.inc
index 20b906d..1c88dc6 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -678,7 +678,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] = $sanitize ? $title : decode_entities($title);
+          $replacements[$original] = $sanitize ? $title : String::decodeEntities($title);
           break;
         case 'url':
           // Strip the query string from the result of Request::getUri().
-- 
1.9.3 (Apple Git-50)


From e9b72b33d91e20e0b68a524790fb4ee6f7aab511 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 26 Nov 2014 21:59:26 +0100
Subject: [PATCH 212/230] Fixed routing, rename content to controller

---
 token.install     |  2 +-
 token.routing.yml | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/token.install b/token.install
index e0bb2cf..26d8ca1 100644
--- a/token.install
+++ b/token.install
@@ -20,7 +20,7 @@ function token_requirements($phase = 'runtime') {
         $problems = array_unique($problem['problems']);
         $problems = array_map('\Drupal\Component\Utility\String::checkPlain', $problems);
         // ToDo: Use render arrays. See https://drupal.org/node/2195739
-        $token_problems[$problem_key] = $problem['label'] . _theme('item_list', array('items' => $problems));
+        $token_problems[$problem_key] = $problem['label'] . \Drupal::theme()->render('item_list', array('items' => $problems));
       }
       else {
         unset($token_problems[$problem_key]);
diff --git a/token.routing.yml b/token.routing.yml
index 467122e..c571c87 100644
--- a/token.routing.yml
+++ b/token.routing.yml
@@ -1,7 +1,7 @@
 token.tree:
   path: '/token/tree'
   defaults:
-    _content: '\Drupal\token\Controller\TokenTreeController::outputTree'
+    _controller: '\Drupal\token\Controller\TokenTreeController::outputTree'
   requirements:
     _csrf_token: 'TRUE'
 
@@ -20,7 +20,7 @@ token.flush_cache:
 token.devel_node_token:
   path: '/node/{node}/devel/token'
   defaults:
-    _content: '\Drupal\token\Controller\TokenDevelController::devel_token_node'
+    _controller: '\Drupal\token\Controller\TokenDevelController::devel_token_node'
     _title: 'Tokens'
   options:
     _access_mode: 'ALL'
@@ -30,7 +30,7 @@ token.devel_node_token:
 token.devel_comment_token:
   path: '/comment/{comment}/devel/token'
   defaults:
-    _content: '\Drupal\token\Controller\TokenDevelController::devel_token_comment'
+    _controller: '\Drupal\token\Controller\TokenDevelController::devel_token_comment'
     _title: 'Tokens'
   options:
     _access_mode: 'ALL'
@@ -40,7 +40,7 @@ token.devel_comment_token:
 token.devel_taxonomy_term_token:
   path: '/taxonomy/term/{taxonomy_term}/devel/token'
   defaults:
-    _content: '\Drupal\token\Controller\TokenDevelController::devel_token_taxonomy_term'
+    _controller: '\Drupal\token\Controller\TokenDevelController::devel_token_taxonomy_term'
     _title: 'Tokens'
   options:
     _access_mode: 'ALL'
@@ -50,7 +50,7 @@ token.devel_taxonomy_term_token:
 token.devel_user_token:
   path: '/user/{user}/devel/token'
   defaults:
-    _content: '\Drupal\token\Controller\TokenDevelController::devel_token_user'
+    _controller: '\Drupal\token\Controller\TokenDevelController::devel_token_user'
     _title: 'Tokens'
   options:
     _access_mode: 'ALL'
-- 
1.9.3 (Apple Git-50)


From 1c85e1204a52ce3658b245d236a48c4313729637 Mon Sep 17 00:00:00 2001
From: Kim Pepper <kim@pepper.id.au>
Date: Mon, 22 Dec 2014 09:19:02 +1100
Subject: [PATCH 213/230] Fixes #50 Replace instances of current_path()

---
 src/Controller/TokenCacheController.php | 4 +++-
 token.module                            | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/Controller/TokenCacheController.php b/src/Controller/TokenCacheController.php
index 589d595..279e614 100644
--- a/src/Controller/TokenCacheController.php
+++ b/src/Controller/TokenCacheController.php
@@ -9,6 +9,7 @@ namespace Drupal\token\Controller;
 
 use Drupal\Core\Controller\ControllerBase;
 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
+use Drupal\Core\Url;
 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\HttpFoundation\Request;
@@ -40,7 +41,8 @@ class TokenCacheController extends ControllerBase implements ContainerInjectionI
   }
 
   public function flush(Request $request) {
-    if (!$request->query->has('token') || ! $this->csrfToken->validate($request->query->get('token'), current_path())) {
+    $current_url = Url::fromRoute('<current>');
+    if (!$request->query->has('token') || ! $this->csrfToken->validate($request->query->get('token'), $current_url->toString())) {
       return MENU_NOT_FOUND;
     }
 
diff --git a/token.module b/token.module
index 6bc8ab1..d37579d 100644
--- a/token.module
+++ b/token.module
@@ -14,6 +14,7 @@ use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\Render\Element;
 use Drupal\Core\Routing\RouteMatchInterface;
 use Drupal\Core\Utility\Token;
+use Drupal\Core\Url;
 
 /**
  * The maximum depth for token tree recursion.
@@ -29,7 +30,8 @@ require_once __DIR__ . '/token.tokens.inc';
  */
 function token_help($route_name, RouteMatchInterface $route_match) {
   if ($route_name == 'help.page.token') {
-    if (current_path() != 'admin/help/token') {
+    $current_url = Url::fromRoute('<current>');
+    if ($current_url->toString() != 'admin/help/token') {
       // Because system_modules() executes hook_help() for each module to 'test'
       // if they will return anything, but not actually display it, we want to
       // return a TRUE value if this is not actually the help page.
-- 
1.9.3 (Apple Git-50)


From a4f78f0abfcb977c2d1e3834a47d4ea812cc9ed2 Mon Sep 17 00:00:00 2001
From: Kim Pepper <kim@pepper.id.au>
Date: Sun, 28 Dec 2014 13:25:12 +1100
Subject: [PATCH 214/230] Remove use of _theme()

---
 src/Tests/TokenUserTestCase.php | 15 +++++++++++++--
 token.module                    | 11 +++++++++--
 token.pages.inc                 | 21 +++++++++++++++------
 token.tokens.inc                |  9 +++++++--
 4 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/src/Tests/TokenUserTestCase.php b/src/Tests/TokenUserTestCase.php
index 750ebe7..641e03d 100644
--- a/src/Tests/TokenUserTestCase.php
+++ b/src/Tests/TokenUserTestCase.php
@@ -16,6 +16,12 @@ use Drupal\field\Entity\FieldStorageConfig;
  * @group token
  */
 class TokenUserTestCase extends TokenTestBase {
+
+  /**
+   * The user account.
+   *
+   * @var \Drupal\Core\Session\AccountInterface
+   */
   protected $account = NULL;
 
   /**
@@ -58,9 +64,14 @@ class TokenUserTestCase extends TokenTestBase {
     $this->account = $storage->load($this->account->id());
     $this->assertTrue(!empty($this->account->user_picture->target_id), 'User picture uploaded.');
 
+    $picture = [
+      '#theme' => 'user_picture',
+      '#account' => $this->account,
+    ];
+    /** @var \Drupal\Core\Render\RendererInterface $renderer */
+    $renderer = \Drupal::service('renderer');
     $user_tokens = array(
-      // ToDo: Use render arrays. See https://drupal.org/node/2195739
-      'picture' => _theme('user_picture', array('account' => $this->account)),
+      'picture' => $renderer->render($picture),
       'picture:fid' => $this->account->user_picture->target_id,
       'picture:size-raw' => 125,
       'ip-address' => NULL,
diff --git a/token.module b/token.module
index d37579d..ea57699 100644
--- a/token.module
+++ b/token.module
@@ -39,8 +39,15 @@ function token_help($route_name, RouteMatchInterface $route_match) {
     }
     $output = '<dl>';
     $output .= '<dt>' . t('List of the currently available tokens on this site') . '</dt>';
-    // ToDo: Use render arrays. See https://drupal.org/node/2195739
-    $output .= '<dd>' . _theme('token_tree', array('token_types' => 'all', 'click_insert' => FALSE, 'show_restricted' => TRUE)) . '</dd>';
+    $token_tree = array(
+      '#theme' => 'token_tree',
+      '#token_types' => 'all',
+      '#click_insert' => FALSE,
+      '#show_restricted' => TRUE,
+    );
+    /** @var \Drupal\Core\Render\RendererInterface $renderer */
+    $renderer = \Drupal::service('renderer');
+    $output .= '<dd>' . $renderer->render($token_tree) . '</dd>';
     $output .= '</dl>';
     return $output;
   }
diff --git a/token.pages.inc b/token.pages.inc
index 22711c9..f4a66cd 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -64,13 +64,16 @@ function theme_tree_table($variables) {
       unset($row['parent']);
     }
   }
-  $attached['#attached']['library'][] = 'token/token';
+  $output = [];
+  $output['#attached']['library'][] = 'token/token';
   if (!empty($variables['rows'])) {
-    $attached['#attached']['library'][] = 'token/jquery.treeTable';
+    $output['#attached']['library'][] = 'token/jquery.treeTable';
   }
-  drupal_render($attached);
-  // ToDo: Use render arrays. See https://drupal.org/node/2195739
-  return _theme('table', $variables);
+  $output['#type'] = 'table';
+  $output['#variables'] = $variables;
+  /** @var \Drupal\Core\Render\RendererInterface $renderer */
+  $renderer = \Drupal::service('renderer');
+  return $renderer->render($output);
 }
 
 /**
@@ -80,7 +83,13 @@ function theme_tree_table($variables) {
  */
 function theme_token_tree($variables) {
   if (!empty($variables['dialog'])) {
-    return _theme('token_tree_link', $variables);
+    $output = [
+      '#theme' => 'token_tree_link',
+      '#variables' => $variables,
+    ];
+    /** @var \Drupal\Core\Render\RendererInterface $renderer */
+    $renderer = \Drupal::service('renderer');
+    return $renderer->render($output);
   }
 
   $token_types = $variables['token_types'];
diff --git a/token.tokens.inc b/token.tokens.inc
index 1c88dc6..3a8fe75 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -577,9 +577,14 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'picture':
-          // ToDo: Use render arrays. See https://drupal.org/node/2195739
           if ($account instanceof UserInterface && $account->hasField('user_picture')) {
-            $replacements[$original] = _theme('user_picture', array('account' => $account));
+            /** @var \Drupal\Core\Render\RendererInterface $renderer */
+            $renderer = \Drupal::service('renderer');
+            $output = [
+              '#theme' => 'user_picture',
+              '#account' => $account,
+            ];
+            $replacements[$original] = $renderer->render($output);
           }
           break;
 
-- 
1.9.3 (Apple Git-50)


From 82c864b53573e33e89d14e899e058f3cf70af762 Mon Sep 17 00:00:00 2001
From: Kim Pepper <kim@pepper.id.au>
Date: Sun, 28 Dec 2014 15:01:35 +1100
Subject: [PATCH 215/230] Replace taxonomy_term_load_parents_all()

---
 token.module     | 7 +++++--
 token.tokens.inc | 7 +++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/token.module b/token.module
index ea57699..95f0f0d 100644
--- a/token.module
+++ b/token.module
@@ -1121,8 +1121,11 @@ function token_taxonomy_term_load_all_parents($tid) {
 
   if (!isset($cache[$tid])) {
     $cache[$tid] = array();
-    $parents = taxonomy_term_load_parents_all($tid);
-    array_shift($parents); // Remove this term from the array.
+    /** @var \Drupal\taxonomy\TermStorageInterface $term_storage */
+    $term_storage = \Drupal::entityManager()->getStorage('taxonomy_term');
+    $parents = $term_storage->loadAllParents($tid);
+    // Remove this term from the array.
+    array_shift($parents);
     $parents = array_reverse($parents);
     foreach ($parents as $term) {
       $cache[$tid][$term->id()] = $term->label();
diff --git a/token.tokens.inc b/token.tokens.inc
index 3a8fe75..ef4d094 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -490,6 +490,9 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
     /* @var \Drupal\taxonomy\TermInterface $term */
     $term = $data['term'];
 
+    /** @var \Drupal\taxonomy\TermStorageInterface $term_storage */
+    $term_storage = \Drupal::entityManager()->getStorage('taxonomy_term');
+
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'edit-url':
@@ -503,7 +506,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
           break;
 
         case 'root':
-          $parents = taxonomy_term_load_parents_all($term->id());
+          $parents = $term_storage->loadAllParents($term->id());
           $root_term = end($parents);
           if ($root_term->id() != $term->id()) {
             $replacements[$original] = $sanitize ? String::checkPlain($root_term->label()) : $root_term->label();
@@ -523,7 +526,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
       }
     }
     if ($root_tokens = \Drupal::token()->findWithPrefix($tokens, 'root')) {
-      $parents = taxonomy_term_load_parents_all($term->id());
+      $parents = $term_storage->loadAllParents($term->id());
       $root_term = end($parents);
       if ($root_term->tid != $term->id()) {
         $replacements += \Drupal::token()->generate('term', $root_tokens, array('term' => $root_term), $options);
-- 
1.9.3 (Apple Git-50)


From ed314e19c141483244909f4f0c3548525de630b6 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 27 Aug 2014 19:03:24 +0200
Subject: [PATCH 216/230] Optimize field_tokens() by looping over requested
 tokens instead of all fields.

---
 token.tokens.inc | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index ef4d094..3c94a6f 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -1295,10 +1295,8 @@ function field_tokens($type, $tokens, array $data = array(), array $options = ar
 
   // Entity tokens.
   if ($type == 'entity' && !empty($data['entity_type']) && !empty($data['entity']) && !empty($data['token_type'])) {
-    $entity_type = $data['entity_type'];
-
     // The field API does weird stuff to the entity, so let's clone it.
-    /* @var \Drupal\Core\Entity\EntityInterface $entity */
+    /* @var \Drupal\Core\Entity\ContentEntityInterface $entity */
     $entity = clone $data['entity'];
     if (!($entity instanceof ContentEntityInterface)) {
       return $replacements;
@@ -1308,26 +1306,17 @@ function field_tokens($type, $tokens, array $data = array(), array $options = ar
     // inside field_attach_view().
     unset($entity->_field_view_prepared);
 
-    $fields = $entity->getFieldDefinitions();
-
-    foreach (array_keys($fields) as $field_name) {
-      // Do not continue if the field is empty or not a configurable field.
-      if (empty($entity->{$field_name}) || !($fields[$field_name] instanceof FieldConfigInterface)) {
-        continue;
-      }
-
+    foreach ($tokens as $name => $original) {
       // Replace the [entity:field-name] token only if token module added this
       // token.
-      if (isset($tokens[$field_name]) && _token_module($data['token_type'], $field_name) == 'token') {
-        $original = $tokens[$field_name];
+      if ($entity->hasField($name) && _token_module($data['token_type'], $name) == 'token') {
 
-        // Assert that this field was added by token.module.
-        $token_info = token_get_info($data['token_type'], $field_name);
-        if (!isset($token_info['module']) || $token_info['module'] != 'token') {
+        // Do not continue if the field is empty or not a configurable field.
+        if ($entity->get($name)->isEmpty() || !($entity->getFieldDefinition($name) instanceof FieldInstanceConfigInterface)) {
           continue;
         }
 
-        $field_output = $entity->$field_name->view('token');
+        $field_output = $entity->$name->view('token');
         $field_output['#token_options'] = $options;
         $field_output['#pre_render'][] = 'token_pre_render_field_token';
         $replacements[$original] = drupal_render($field_output);
-- 
1.9.3 (Apple Git-50)


From 3a3fe147be082069c872271ab9d535530cab04ad Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Fri, 24 Oct 2014 01:16:04 +0200
Subject: [PATCH 217/230] Fixed classname

---
 token.tokens.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.tokens.inc b/token.tokens.inc
index 3c94a6f..d818eac 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -1312,7 +1312,7 @@ function field_tokens($type, $tokens, array $data = array(), array $options = ar
       if ($entity->hasField($name) && _token_module($data['token_type'], $name) == 'token') {
 
         // Do not continue if the field is empty or not a configurable field.
-        if ($entity->get($name)->isEmpty() || !($entity->getFieldDefinition($name) instanceof FieldInstanceConfigInterface)) {
+        if ($entity->get($name)->isEmpty() || !($entity->getFieldDefinition($name) instanceof FieldConfigInterface)) {
           continue;
         }
 
-- 
1.9.3 (Apple Git-50)


From 5754f7d0cc18040058f84b23e111e6d39f9b5b2d Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Tue, 13 Jan 2015 23:07:39 +0100
Subject: [PATCH 218/230] Change fid to uuid in user picture field configs.

---
 .../config/install/field.field.user.user.user_picture.yml               | 2 +-
 .../config/install/field.storage.user.user_picture.yml                  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/token_user_picture/config/install/field.field.user.user.user_picture.yml b/tests/token_user_picture/config/install/field.field.user.user.user_picture.yml
index 887b6b0..45f6e82 100644
--- a/tests/token_user_picture/config/install/field.field.user.user.user_picture.yml
+++ b/tests/token_user_picture/config/install/field.field.user.user.user_picture.yml
@@ -18,7 +18,7 @@ settings:
   max_resolution: 85x85
   min_resolution: ''
   default_image:
-    fid: null
+    uuid: null
     alt: ''
     title: ''
     width: null
diff --git a/tests/token_user_picture/config/install/field.storage.user.user_picture.yml b/tests/token_user_picture/config/install/field.storage.user.user_picture.yml
index 2987390..01d0939 100644
--- a/tests/token_user_picture/config/install/field.storage.user.user_picture.yml
+++ b/tests/token_user_picture/config/install/field.storage.user.user_picture.yml
@@ -7,7 +7,7 @@ type: image
 settings:
   uri_scheme: public
   default_image:
-    fid: null
+    uuid: null
     alt: ''
     title: ''
     width: null
-- 
1.9.3 (Apple Git-50)


From f484623e9492dd72cdb1c9fddde5de5465d51050 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Tue, 13 Jan 2015 23:08:03 +0100
Subject: [PATCH 219/230] Fixed node and node type tokens and speed up test

---
 src/Tests/TokenNodeTestCase.php | 29 +++++++++++++++++++++++++----
 token.tokens.inc                | 21 ++++++++-------------
 2 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/src/Tests/TokenNodeTestCase.php b/src/Tests/TokenNodeTestCase.php
index bb714cd..4994708 100644
--- a/src/Tests/TokenNodeTestCase.php
+++ b/src/Tests/TokenNodeTestCase.php
@@ -13,7 +13,30 @@ namespace Drupal\token\Tests;
  * @group token
  */
 class TokenNodeTestCase extends TokenTestBase {
-  protected $profile = 'standard';
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = ['node'];
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+    $this->drupalCreateContentType([
+      'type' => 'page',
+      'name' => 'Basic page',
+      'description' => "Use <em>basic pages</em> for your static content, such as an 'About us' page.",
+    ]);
+    $this->drupalCreateContentType([
+      'type' => 'article',
+      'name' => 'Article',
+      'description' => "Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.",
+    ]);
+  }
 
   function testNodeTokens() {
     $source_node = $this->drupalCreateNode(array('revision_log' => $this->randomMachineName(), 'path' => array('alias' => 'content/source-node')));
@@ -38,10 +61,8 @@ class TokenNodeTestCase extends TokenTestBase {
     );
     $this->assertTokens('node', array('node' => $source_node), $tokens);
 
-    $translated_node = $this->drupalCreateNode(array('tnid' => $source_node->id(), 'type' => 'article'));
+    $translated_node = $this->drupalCreateNode(array('type' => 'article'));
     $tokens = array(
-      'source' => $source_node->label(),
-      'source:nid' => $source_node->id(),
       'log' => '',
       'url:path' => "node/{$translated_node->id()}",
       'url:absolute' => \Drupal::url('entity.node.canonical', ['node' => $translated_node->id()], array('absolute' => TRUE)),
diff --git a/token.tokens.inc b/token.tokens.inc
index ef4d094..e89eed7 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -427,12 +427,6 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
 
     foreach ($tokens as $name => $original) {
       switch ($name) {
-        case 'source':
-          if (!empty($node->tnid) && $source_node = node_load($node->tnid)) {
-            $title = $source_node->label();
-            $replacements[$original] = $sanitize ? Xss::filter($title) : $title;
-          }
-          break;
         case 'log':
           $replacements[$original] = $sanitize ? Xss::filter($node->revision_log->value) : $node->revision_log->value;
           break;
@@ -457,25 +451,26 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
 
   // Content type tokens.
   if ($type == 'content-type' && !empty($data['node_type'])) {
+    /* @var \Drupal\node\NodeTypeInterface $node_type */
     $node_type = $data['node_type'];
 
     foreach ($tokens as $name => $original) {
       switch ($name) {
         case 'name':
-          $replacements[$original] = $sanitize ? String::checkPlain($node_type->name) : $node_type->name;
+          $replacements[$original] = $sanitize ? String::checkPlain($node_type->label()) : $node_type->label();
           break;
         case 'machine-name':
           // This is a machine name so does not ever need to be sanitized.
-          $replacements[$original] = $node_type->type;
+          $replacements[$original] = $node_type->id();
           break;
         case 'description':
-          $replacements[$original] = $sanitize ? Xss::filter($node_type->description) : $node_type->description;
+          $replacements[$original] = $sanitize ? Xss::filter($node_type->getDescription()) : $node_type->getDescription();
           break;
         case 'node-count':
-          $query = db_select('node');
-          $query->condition('type', $node_type->type);
-          $query->addTag('node_type_node_count');
-          $count = $query->countQuery()->execute()->fetchField();
+          $count = \Drupal::entityQueryAggregate('node')
+            ->aggregate('nid', 'COUNT')
+            ->condition('type', $node_type->id())
+            ->execute();
           $replacements[$original] = (int) $count;
           break;
         case 'edit-url':
-- 
1.9.3 (Apple Git-50)


From c43ad1c5b7daa25153cee1b2cc8357565cdc5a74 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Tue, 13 Jan 2015 23:08:26 +0100
Subject: [PATCH 220/230] Remove require_once,  hook_module_implements_alter()
 works again.

---
 token.module | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/token.module b/token.module
index 95f0f0d..194c07e 100644
--- a/token.module
+++ b/token.module
@@ -21,10 +21,6 @@ use Drupal\Core\Url;
  */
 define('TOKEN_MAX_DEPTH', 9);
 
-// @todo Hack until hook_module_implements_alter() works again, see
-//   https://www.drupal.org/node/2353357
-require_once __DIR__ . '/token.tokens.inc';
-
 /**
  * Implements hook_help().
  */
-- 
1.9.3 (Apple Git-50)


From 576adfb291526c2a1cb03cbf7b997d6dcce39a09 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Tue, 13 Jan 2015 23:57:22 +0100
Subject: [PATCH 221/230] Add trait, kernel test base, convert most test to
 kernel tests

---
 .../{TokenArrayTestCase.php => TokenArrayTest.php} |   4 +-
 .../{TokenBlockTestCase.php => TokenBlockTest.php} |   6 +-
 ...kenCommentTestCase.php => TokenCommentTest.php} |  50 +++++++---
 ...ntPageTestCase.php => TokenCurrentPageTest.php} |  12 ++-
 src/Tests/TokenDateTest.php                        |  40 ++++++++
 src/Tests/TokenDateTestCase.php                    |  24 -----
 ...TokenEntityTestCase.php => TokenEntityTest.php} |  30 ++++--
 .../{TokenFileTestCase.php => TokenFileTest.php}   |  21 ++++-
 src/Tests/TokenKernelTestBase.php                  |  37 ++++++++
 .../{TokenMenuTestCase.php => TokenMenuTest.php}   |  12 ++-
 .../{TokenNodeTestCase.php => TokenNodeTest.php}   |  49 ++++++----
 ...TokenRandomTestCase.php => TokenRandomTest.php} |   4 +-
 ...nTaxonomyTestCase.php => TokenTaxonomyTest.php} |  20 +++-
 src/Tests/TokenTestBase.php                        | 101 +--------------------
 .../{TokenTestBase.php => TokenTestTrait.php}      |  10 +-
 .../{TokenURLTestCase.php => TokenURLTest.php}     |  14 ++-
 .../{TokenUnitTestCase.php => TokenUnitTest.php}   |  12 ++-
 .../{TokenUserTestCase.php => TokenUserTest.php}   |   6 +-
 18 files changed, 257 insertions(+), 195 deletions(-)
 rename src/Tests/{TokenArrayTestCase.php => TokenArrayTest.php} (93%)
 rename src/Tests/{TokenBlockTestCase.php => TokenBlockTest.php} (90%)
 rename src/Tests/{TokenCommentTestCase.php => TokenCommentTest.php} (73%)
 rename src/Tests/{TokenCurrentPageTestCase.php => TokenCurrentPageTest.php} (92%)
 create mode 100644 src/Tests/TokenDateTest.php
 delete mode 100644 src/Tests/TokenDateTestCase.php
 rename src/Tests/{TokenEntityTestCase.php => TokenEntityTest.php} (82%)
 rename src/Tests/{TokenFileTestCase.php => TokenFileTest.php} (70%)
 create mode 100644 src/Tests/TokenKernelTestBase.php
 rename src/Tests/{TokenMenuTestCase.php => TokenMenuTest.php} (94%)
 rename src/Tests/{TokenNodeTestCase.php => TokenNodeTest.php} (62%)
 rename src/Tests/{TokenRandomTestCase.php => TokenRandomTest.php} (86%)
 rename src/Tests/{TokenTaxonomyTestCase.php => TokenTaxonomyTest.php} (92%)
 copy src/Tests/{TokenTestBase.php => TokenTestTrait.php} (94%)
 rename src/Tests/{TokenURLTestCase.php => TokenURLTest.php} (85%)
 rename src/Tests/{TokenUnitTestCase.php => TokenUnitTest.php} (91%)
 rename src/Tests/{TokenUserTestCase.php => TokenUserTest.php} (95%)

diff --git a/src/Tests/TokenArrayTestCase.php b/src/Tests/TokenArrayTest.php
similarity index 93%
rename from src/Tests/TokenArrayTestCase.php
rename to src/Tests/TokenArrayTest.php
index 9fe9e51..e4ce87f 100644
--- a/src/Tests/TokenArrayTestCase.php
+++ b/src/Tests/TokenArrayTest.php
@@ -2,7 +2,7 @@
 
 /**
  * @file
- * Contains \Drupal\token\Tests\TokenArrayTestCase
+ * Contains \Drupal\token\Tests\TokenArrayTest
  */
 namespace Drupal\token\Tests;
 
@@ -11,7 +11,7 @@ namespace Drupal\token\Tests;
  *
  * @group token
  */
-class TokenArrayTestCase extends TokenTestBase {
+class TokenArrayTest extends TokenKernelTestBase {
 
   function testArrayTokens() {
     // Test a simple array.
diff --git a/src/Tests/TokenBlockTestCase.php b/src/Tests/TokenBlockTest.php
similarity index 90%
rename from src/Tests/TokenBlockTestCase.php
rename to src/Tests/TokenBlockTest.php
index 456c825..c34b48b 100644
--- a/src/Tests/TokenBlockTestCase.php
+++ b/src/Tests/TokenBlockTest.php
@@ -2,7 +2,7 @@
 
 /**
  * @file
- * Contains \Drupal\token\Tests\TokenBlockTestCase.
+ * Contains \Drupal\token\Tests\TokenBlockTest.
  */
 namespace Drupal\token\Tests;
 use Drupal\block_content\Entity\BlockContent;
@@ -13,14 +13,14 @@ use Drupal\block_content\Entity\BlockContentType;
  *
  * @group token
  */
-class TokenBlockTestCase extends TokenTestBase {
+class TokenBlockTest extends TokenTestBase {
 
   /**
    * Modules to enable.
    *
    * @var array
    */
-  protected static $modules = array('path', 'token', 'token_test', 'block', 'node', 'views', 'block_content');
+  public static $modules = array('path', 'token', 'token_test', 'block', 'node', 'views', 'block_content');
 
   /**
    * {@inheritdoc}
diff --git a/src/Tests/TokenCommentTestCase.php b/src/Tests/TokenCommentTest.php
similarity index 73%
rename from src/Tests/TokenCommentTestCase.php
rename to src/Tests/TokenCommentTest.php
index 3642bf1..6286c6d 100644
--- a/src/Tests/TokenCommentTestCase.php
+++ b/src/Tests/TokenCommentTest.php
@@ -2,25 +2,52 @@
 
 /**
  * @file
- * Contains \Drupal\token\Tests\TokenCommentTestCase.
+ * Contains \Drupal\token\Tests\TokenCommentTest.
  */
+
 namespace Drupal\token\Tests;
 
+use Drupal\node\Entity\NodeType;
+use Drupal\node\Entity\Node;
+use Drupal\comment\Entity\Comment;
+
 /**
  * Tests comment tokens.
  *
  * @group token
  */
-class TokenCommentTestCase extends TokenTestBase {
-  protected static $modules = array('path', 'token', 'token_test', 'node', 'comment');
+class TokenCommentTest extends TokenKernelTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = array('path', 'token', 'token_test', 'node', 'comment', 'user', 'field', 'text', 'entity_reference', 'system');
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+
+    $this->installEntitySchema('node');
+    $this->installEntitySchema('user');
+    $this->installEntitySchema('comment');
+
+    $node_type = NodeType::create(['type' => 'page', 'name' => t('Page')]);
+    $node_type->save();
+
+    $this->installConfig(['comment']);
 
-  function testCommentTokens() {
-    $this->drupalCreateContentType(array('type' => 'page', 'name' => t('Page')));
     \Drupal::service('comment.manager')->addDefaultField('node', 'page');
-    $node = $this->drupalCreateNode();
+  }
+
+  function testCommentTokens() {
+    $node = Node::create(['type' => 'page']);
+    $node->save();
 
-    /** @var \Drupal\comment\Entity\Comment $parent_comment */
-    $parent_comment = entity_create('comment', array(
+    $parent_comment = Comment::create([
       'entity_id' => $node->id(),
       'entity_type' => 'node',
       'field_name' => 'comment',
@@ -28,7 +55,7 @@ class TokenCommentTestCase extends TokenTestBase {
       'mail' => 'anonymous@example.com',
       'subject' => $this->randomMachineName(),
       'body' => $this->randomMachineName(),
-    ));
+    ]);
     $parent_comment->save();
 
     // Fix http://example.com/index.php/comment/1 fails 'url:path' test.
@@ -44,8 +71,7 @@ class TokenCommentTestCase extends TokenTestBase {
     );
     $this->assertTokens('comment', array('comment' => $parent_comment), $tokens);
 
-    /** @var \Drupal\comment\Entity\Comment  $comment */
-    $comment = entity_create('comment', array(
+    $comment = Comment::create([
       'entity_id' => $node->id(),
       'pid' => $parent_comment->id(),
       'entity_type' => 'node',
@@ -55,7 +81,7 @@ class TokenCommentTestCase extends TokenTestBase {
       'mail' => 'anonymous@example.com',
       'subject' => $this->randomMachineName(),
       'body' => $this->randomMachineName(),
-    ));
+    ]);
     $comment->save();
 
     // Fix http://example.com/index.php/comment/1 fails 'url:path' test.
diff --git a/src/Tests/TokenCurrentPageTestCase.php b/src/Tests/TokenCurrentPageTest.php
similarity index 92%
rename from src/Tests/TokenCurrentPageTestCase.php
rename to src/Tests/TokenCurrentPageTest.php
index 858e7a0..4b68976 100644
--- a/src/Tests/TokenCurrentPageTestCase.php
+++ b/src/Tests/TokenCurrentPageTest.php
@@ -2,8 +2,9 @@
 
 /**
  * @file
- * Contains \Drupal\token\Tests\TokenCurrentPageTestCase.
+ * Contains \Drupal\token\Tests\TokenCurrentPageTest.
  */
+
 namespace Drupal\token\Tests;
 
 /**
@@ -11,9 +12,14 @@ namespace Drupal\token\Tests;
  *
  * @group token
  */
-class TokenCurrentPageTestCase extends TokenTestBase {
+class TokenCurrentPageTest extends TokenTestBase {
 
-  protected static $modules = array('path', 'token', 'token_test', 'node');
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = array('node');
 
   function testCurrentPageTokens() {
     $tokens = array(
diff --git a/src/Tests/TokenDateTest.php b/src/Tests/TokenDateTest.php
new file mode 100644
index 0000000..b299d2d
--- /dev/null
+++ b/src/Tests/TokenDateTest.php
@@ -0,0 +1,40 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Tests\TokenDateTest.
+ */
+
+namespace Drupal\token\Tests;
+
+/**
+ * Tests date tokens.
+ *
+ * @group token
+ */
+class TokenDateTest extends TokenKernelTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = ['system'];
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+    $this->installConfig(['system', 'token_test']);
+  }
+
+  function testDateTokens() {
+    $tokens = array(
+      'token_test' => '1984',
+      'invalid_format' => NULL,
+    );
+
+    $this->assertTokens('date', array('date' => 453859200), $tokens);
+  }
+}
diff --git a/src/Tests/TokenDateTestCase.php b/src/Tests/TokenDateTestCase.php
deleted file mode 100644
index a640832..0000000
--- a/src/Tests/TokenDateTestCase.php
+++ /dev/null
@@ -1,24 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains \Drupal\token\Tests\TokenDateTestCase.
- */
-namespace Drupal\token\Tests;
-
-/**
- * Tests date tokens.
- *
- * @group token
- */
-class TokenDateTestCase extends TokenTestBase {
-
-  function testDateTokens() {
-    $tokens = array(
-      'token_test' => '1984',
-      'invalid_format' => NULL,
-    );
-
-    $this->assertTokens('date', array('date' => 453859200), $tokens);
-  }
-}
diff --git a/src/Tests/TokenEntityTestCase.php b/src/Tests/TokenEntityTest.php
similarity index 82%
rename from src/Tests/TokenEntityTestCase.php
rename to src/Tests/TokenEntityTest.php
index 2324aba..f759708 100644
--- a/src/Tests/TokenEntityTestCase.php
+++ b/src/Tests/TokenEntityTest.php
@@ -2,10 +2,14 @@
 
 /**
  * @file
- * Contains \Drupal\token\Tests\TokenEntityTestCase.
+ * Contains \Drupal\token\Tests\TokenEntityTest.
  */
+
 namespace Drupal\token\Tests;
+
 use Drupal\Component\Utility\Unicode;
+use Drupal\node\Entity\Node;
+use Drupal\taxonomy\Entity\Vocabulary;
 use Drupal\taxonomy\VocabularyInterface;
 
 /**
@@ -13,21 +17,32 @@ use Drupal\taxonomy\VocabularyInterface;
  *
  * @group Token
  */
-class TokenEntityTestCase extends TokenTestBase {
-  protected static $modules = array('path', 'token', 'token_test', 'node', 'taxonomy');
+class TokenEntityTest extends TokenKernelTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = array('path', 'token', 'token_test', 'node', 'taxonomy', 'text');
 
   /**
    * {@inheritdoc}
    */
-  public function setUp($modules = array()) {
+  public function setUp() {
     parent::setUp();
 
     // Create the default tags vocabulary.
-    $vocabulary = entity_create('taxonomy_vocabulary', array(
+    $vocabulary = Vocabulary::create([
       'name' => 'Tags',
       'vid' => 'tags',
-    ));
+    ]);
     $vocabulary->save();
+
+    $this->installEntitySchema('taxonomy_term');
+    $this->installEntitySchema('user');
+    $this->installEntitySchema('node');
+
     $this->vocab = $vocabulary;
   }
 
@@ -65,7 +80,8 @@ class TokenEntityTestCase extends TokenTestBase {
    * Test the [entity:original:*] tokens.
    */
   function testEntityOriginal() {
-    $node = $this->drupalCreateNode(array('title' => 'Original title'));
+    $node = Node::create(['type' => 'page', 'title' => 'Original title']);
+    $node->save();
 
     $tokens = array(
       'nid' => $node->id(),
diff --git a/src/Tests/TokenFileTestCase.php b/src/Tests/TokenFileTest.php
similarity index 70%
rename from src/Tests/TokenFileTestCase.php
rename to src/Tests/TokenFileTest.php
index 8085d5e..c51309c 100644
--- a/src/Tests/TokenFileTestCase.php
+++ b/src/Tests/TokenFileTest.php
@@ -2,17 +2,32 @@
 
 /**
  * @file
- * Contains \Drupal\token\Tests\TokenFileTestCase.
+ * Contains \Drupal\token\Tests\TokenFileTest.
  */
 namespace Drupal\token\Tests;
+use Drupal\taxonomy\Entity\Vocabulary;
 
 /**
  * Tests file tokens.
  *
  * @group token
  */
-class TokenFileTestCase extends TokenTestBase {
-  protected static $modules = array('path', 'token', 'token_test', 'file');
+class TokenFileTest extends TokenKernelTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = array('file');
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp() {
+    parent::setUp();
+    $this->installEntitySchema('file');
+  }
 
   function testFileTokens() {
     // Create a test file object.
diff --git a/src/Tests/TokenKernelTestBase.php b/src/Tests/TokenKernelTestBase.php
new file mode 100644
index 0000000..ef9c346
--- /dev/null
+++ b/src/Tests/TokenKernelTestBase.php
@@ -0,0 +1,37 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\token\Tests\TokenKernelTestBase.
+ */
+
+namespace Drupal\token\Tests;
+
+use Drupal\simpletest\KernelTestBase;
+
+/**
+ * Helper test class with some added functions for testing.
+ */
+abstract class TokenKernelTestBase extends KernelTestBase {
+
+  use TokenTestTrait;
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = array('path', 'token', 'token_test', 'system', 'user');
+  
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+
+    $this->installSchema('system', ['router', 'url_alias']);
+    \Drupal::service('router.builder')->rebuild();
+    $this->installConfig(['system']);
+  }
+
+}
diff --git a/src/Tests/TokenMenuTestCase.php b/src/Tests/TokenMenuTest.php
similarity index 94%
rename from src/Tests/TokenMenuTestCase.php
rename to src/Tests/TokenMenuTest.php
index cb85f22..9ee0381 100644
--- a/src/Tests/TokenMenuTestCase.php
+++ b/src/Tests/TokenMenuTest.php
@@ -2,7 +2,7 @@
 
 /**
  * @file
- * Contains \Drupal\token\Tests\TokenMenuTestCase.
+ * Contains \Drupal\token\Tests\TokenMenuTest.
  */
 namespace Drupal\token\Tests;
 
@@ -11,8 +11,14 @@ namespace Drupal\token\Tests;
  *
  * @group token
  */
-class TokenMenuTestCase extends TokenTestBase {
-  protected static $modules = array('path', 'token', 'token_test', 'menu_ui', 'node');
+class TokenMenuTest extends TokenTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = array('path', 'token', 'token_test', 'menu_ui', 'node');
 
   function testMenuTokens() {
     // Add a menu.
diff --git a/src/Tests/TokenNodeTestCase.php b/src/Tests/TokenNodeTest.php
similarity index 62%
rename from src/Tests/TokenNodeTestCase.php
rename to src/Tests/TokenNodeTest.php
index 4994708..a9cfeb4 100644
--- a/src/Tests/TokenNodeTestCase.php
+++ b/src/Tests/TokenNodeTest.php
@@ -2,52 +2,60 @@
 
 /**
  * @file
- * Contains \Drupal\token\Tests\TokenNodeTestCase.
+ * Contains \Drupal\token\Tests\TokenNodeTest.
  */
 
 namespace Drupal\token\Tests;
 
+use Drupal\node\Entity\NodeType;
+use Drupal\node\Entity\Node;
+
 /**
  * Test the node and content type tokens.
  *
  * @group token
  */
-class TokenNodeTestCase extends TokenTestBase {
+class TokenNodeTest extends TokenKernelTestBase {
 
   /**
    * Modules to enable.
    *
    * @var array
    */
-  public static $modules = ['node'];
+  public static $modules = ['node', 'field', 'text'];
 
   /**
    * {@inheritdoc}
    */
   protected function setUp() {
     parent::setUp();
-    $this->drupalCreateContentType([
+
+    $this->installEntitySchema('user');
+    $this->installEntitySchema('node');
+
+    $node_type = NodeType::create([
       'type' => 'page',
       'name' => 'Basic page',
       'description' => "Use <em>basic pages</em> for your static content, such as an 'About us' page.",
     ]);
-    $this->drupalCreateContentType([
+    $node_type->save();
+    $node_type = NodeType::create([
       'type' => 'article',
       'name' => 'Article',
       'description' => "Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.",
     ]);
+    $node_type->save();
   }
 
   function testNodeTokens() {
-    $source_node = $this->drupalCreateNode(array('revision_log' => $this->randomMachineName(), 'path' => array('alias' => 'content/source-node')));
+    $page = Node::create(['type' => 'page', 'revision_log' => $this->randomMachineName(), 'path' => array('alias' => 'content/source-node')]);
+    $page->save();
     $tokens = array(
-      'source' => NULL,
-      'source:nid' => NULL,
-      'log' => $source_node->revision_log->value,
+      'log' => $page->revision_log->value,
       'url:path' => 'content/source-node',
-      'url:absolute' => \Drupal::url('entity.node.canonical', ['node' => $source_node->id()], array('absolute' => TRUE)),
-      'url:relative' => \Drupal::url('entity.node.canonical', ['node' => $source_node->id()], array('absolute' => FALSE)),
-      'url:unaliased:path' => "node/{$source_node->id()}",
+      'url:absolute' => \Drupal::url('entity.node.canonical', ['node' => $page->id()], array('absolute' => TRUE)),
+      'url:relative' => \Drupal::url('entity.node.canonical', ['node' => $page->id()], array('absolute' => FALSE)),
+      'url:unaliased:path' => "node/{$page->id()}",
       'content-type' => 'Basic page',
       'content-type:name' => 'Basic page',
       'content-type:machine-name' => 'page',
@@ -59,15 +67,16 @@ class TokenNodeTestCase extends TokenTestBase {
       'type-name' => 'Basic page',
       'url:alias' => 'content/source-node',
     );
-    $this->assertTokens('node', array('node' => $source_node), $tokens);
+    $this->assertTokens('node', array('node' => $page), $tokens);
 
-    $translated_node = $this->drupalCreateNode(array('type' => 'article'));
+    $article = Node::create(['type' => 'article']);
+    $article->save();
     $tokens = array(
       'log' => '',
-      'url:path' => "node/{$translated_node->id()}",
-      'url:absolute' => \Drupal::url('entity.node.canonical', ['node' => $translated_node->id()], array('absolute' => TRUE)),
-      'url:relative' => \Drupal::url('entity.node.canonical', ['node' => $translated_node->id()], array('absolute' => FALSE)),
-      'url:unaliased:path' => "node/{$translated_node->id()}",
+      'url:path' => "node/{$article->id()}",
+      'url:absolute' => \Drupal::url('entity.node.canonical', ['node' => $article->id()], array('absolute' => TRUE)),
+      'url:relative' => \Drupal::url('entity.node.canonical', ['node' => $article->id()], array('absolute' => FALSE)),
+      'url:unaliased:path' => "node/{$article->id()}",
       'content-type' => 'Article',
       'content-type:name' => 'Article',
       'content-type:machine-name' => 'article',
@@ -77,8 +86,8 @@ class TokenNodeTestCase extends TokenTestBase {
       // Deprecated tokens.
       'type' => 'article',
       'type-name' => 'Article',
-      'url:alias' => "node/{$translated_node->id()}",
+      'url:alias' => "node/{$article->id()}",
     );
-    $this->assertTokens('node', array('node' => $translated_node), $tokens);
+    $this->assertTokens('node', array('node' => $article), $tokens);
   }
 }
diff --git a/src/Tests/TokenRandomTestCase.php b/src/Tests/TokenRandomTest.php
similarity index 86%
rename from src/Tests/TokenRandomTestCase.php
rename to src/Tests/TokenRandomTest.php
index 82813f5..e806b2c 100644
--- a/src/Tests/TokenRandomTestCase.php
+++ b/src/Tests/TokenRandomTest.php
@@ -2,7 +2,7 @@
 
 /**
  * @file
- * Contains \Drupal\token\Tests\TokenRandomTestCase.
+ * Contains \Drupal\token\Tests\TokenRandomTest.
  */
 namespace Drupal\token\Tests;
 
@@ -11,7 +11,7 @@ namespace Drupal\token\Tests;
  *
  * @group token
  */
-class TokenRandomTestCase extends TokenTestBase {
+class TokenRandomTest extends TokenKernelTestBase {
 
   function testRandomTokens() {
     $tokens = array(
diff --git a/src/Tests/TokenTaxonomyTestCase.php b/src/Tests/TokenTaxonomyTest.php
similarity index 92%
rename from src/Tests/TokenTaxonomyTestCase.php
rename to src/Tests/TokenTaxonomyTest.php
index 8136cb4..1749f38 100644
--- a/src/Tests/TokenTaxonomyTestCase.php
+++ b/src/Tests/TokenTaxonomyTest.php
@@ -2,21 +2,29 @@
 
 /**
  * @file
- * Contains \Drupal\token\Tests\TokenTaxonomyTestCase.
+ * Contains \Drupal\token\Tests\TokenTaxonomyTest.
  */
+
 namespace Drupal\token\Tests;
+
 use Drupal\Component\Utility\String;
 use Drupal\Component\Utility\Unicode;
+use Drupal\taxonomy\Entity\Vocabulary;
 
 /**
  * Tests taxonomy tokens.
  *
  * @group token
  */
-class TokenTaxonomyTestCase extends TokenTestBase {
+class TokenTaxonomyTest extends TokenKernelTestBase {
   protected $vocab;
 
-  protected static $modules = array('path', 'token', 'token_test', 'taxonomy');
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = array('taxonomy', 'text');
 
   /**
    * {@inheritdoc}
@@ -24,11 +32,13 @@ class TokenTaxonomyTestCase extends TokenTestBase {
   public function setUp() {
     parent::setUp();
 
+    $this->installEntitySchema('taxonomy_term');
+
     // Create the default tags vocabulary.
-    $vocabulary = entity_create('taxonomy_vocabulary', array(
+    $vocabulary = Vocabulary::create([
       'name' => 'Tags',
       'vid' => 'tags',
-    ));
+    ]);
     $vocabulary->save();
     $this->vocab = $vocabulary;
   }
diff --git a/src/Tests/TokenTestBase.php b/src/Tests/TokenTestBase.php
index 73a5b6f..2e5be4a 100644
--- a/src/Tests/TokenTestBase.php
+++ b/src/Tests/TokenTestBase.php
@@ -6,111 +6,20 @@
  */
 namespace Drupal\token\Tests;
 
-use Drupal\Core\Entity\EntityInterface;
 use Drupal\simpletest\WebTestBase;
-use Drupal\Core\Language\Language;
 
 /**
  * Helper test class with some added functions for testing.
  */
 abstract class TokenTestBase extends WebTestBase {
 
-  protected static $modules = array('path', 'token', 'token_test');
-
-  function assertToken($type, array $data, $token, $expected, array $options = array()) {
-    return $this->assertTokens($type, $data, array($token => $expected), $options);
-  }
-
-  function assertTokens($type, array $data, array $tokens, array $options = array()) {
-    $input = $this->mapTokenNames($type, array_keys($tokens));
-    $replacements = \Drupal::token()->generate($type, $input, $data, $options);
-    foreach ($tokens as $name => $expected) {
-      $token = $input[$name];
-      if (!isset($expected)) {
-        $this->assertTrue(!isset($replacements[$token]), t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token)));
-      }
-      elseif (!isset($replacements[$token])) {
-        $this->fail(t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token)));
-      }
-      elseif (!empty($options['regex'])) {
-        $this->assertTrue(preg_match('/^' . $expected . '$/', $replacements[$token]), t("Token value for @token was '@actual', matching regular expression pattern '@expected'.", array('@type' => $type, '@token' => $token, '@actual' => $replacements[$token], '@expected' => $expected)));
-      }
-      else {
-        $this->assertIdentical($replacements[$token], $expected, t("Token value for @token was '@actual', expected value '@expected'.", array('@type' => $type, '@token' => $token, '@actual' => $replacements[$token], '@expected' => $expected)));
-      }
-    }
-
-    return $replacements;
-  }
-
-  function mapTokenNames($type, array $tokens = array()) {
-    $return = array();
-    foreach ($tokens as $token) {
-      $return[$token] = "[$type:$token]";
-    }
-    return $return;
-  }
-
-  function assertNoTokens($type, array $data, array $tokens, array $options = array()) {
-    $input = $this->mapTokenNames($type, $tokens);
-    $replacements = \Drupal::token()->generate($type, $input, $data, $options);
-    foreach ($tokens as $name) {
-      $token = $input[$name];
-      $this->assertTrue(!isset($replacements[$token]), t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token)));
-    }
-    return $values;
-  }
-
-  function saveAlias($source, $alias, $language = Language::LANGCODE_NOT_SPECIFIED) {
-    $alias = array(
-      'source' => $source,
-      'alias' => $alias,
-      'language' => $language,
-    );
-    \Drupal::service('path.alias_storage')->save($alias['source'], $alias['alias']);
-    return $alias;
-  }
-
-  function saveEntityAlias($entity_type, EntityInterface $entity, $alias, $language = Language::LANGCODE_NOT_SPECIFIED) {
-    $uri = $entity->urlInfo()->toArray();
-    return $this->saveAlias($uri['path'], $alias, $language);
-  }
+  use TokenTestTrait;
 
   /**
-   * Make a page request and test for token generation.
+   * Modules to enable.
+   *
+   * @var array
    */
-  function assertPageTokens($url, array $tokens, array $data = array(), array $options = array()) {
-    if (empty($tokens)) {
-      return TRUE;
-    }
-
-    $token_page_tokens = array(
-      'tokens' => $tokens,
-      'data' => $data,
-      'options' => $options,
-    );
-    \Drupal::state()->set('token_page_tokens', $token_page_tokens);
-
-    $options += array('url_options' => array());
-    $this->drupalGet($url, $options['url_options']);
-    $this->refreshVariables();
-    $result = \Drupal::state()->get('token_page_tokens', array());
-
-    if (!isset($result['values']) || !is_array($result['values'])) {
-      return $this->fail('Failed to generate tokens.');
-    }
-
-    foreach ($tokens as $token => $expected) {
-      if (!isset($expected)) {
-        $this->assertTrue(!isset($result['values'][$token]) || $result['values'][$token] === $token, t("Token value for @token was not generated.", array('@token' => $token)));
-      }
-      elseif (!isset($result['values'][$token])) {
-        $this->fail(t('Failed to generate token @token.', array('@token' => $token)));
-      }
-      else {
-        $this->assertIdentical($result['values'][$token], (string) $expected, t("Token value for @token was '@actual', expected value '@expected'.", array('@token' => $token, '@actual' => $result['values'][$token], '@expected' => $expected)));
-      }
-    }
-  }
+  public static $modules = array('path', 'token', 'token_test');
 
 }
diff --git a/src/Tests/TokenTestBase.php b/src/Tests/TokenTestTrait.php
similarity index 94%
copy from src/Tests/TokenTestBase.php
copy to src/Tests/TokenTestTrait.php
index 73a5b6f..c40326d 100644
--- a/src/Tests/TokenTestBase.php
+++ b/src/Tests/TokenTestTrait.php
@@ -2,20 +2,18 @@
 
 /**
  * @file
- * Contains \Drupal\token\Tests\TokenTestBase.
+ * Contains \Drupal\token\Tests\TokenTestTrait.
  */
+
 namespace Drupal\token\Tests;
 
 use Drupal\Core\Entity\EntityInterface;
-use Drupal\simpletest\WebTestBase;
 use Drupal\Core\Language\Language;
 
 /**
- * Helper test class with some added functions for testing.
+ * Helper test trait with some added functions for testing.
  */
-abstract class TokenTestBase extends WebTestBase {
-
-  protected static $modules = array('path', 'token', 'token_test');
+trait TokenTestTrait {
 
   function assertToken($type, array $data, $token, $expected, array $options = array()) {
     return $this->assertTokens($type, $data, array($token => $expected), $options);
diff --git a/src/Tests/TokenURLTestCase.php b/src/Tests/TokenURLTest.php
similarity index 85%
rename from src/Tests/TokenURLTestCase.php
rename to src/Tests/TokenURLTest.php
index 327db39..e21c0f5 100644
--- a/src/Tests/TokenURLTestCase.php
+++ b/src/Tests/TokenURLTest.php
@@ -2,9 +2,11 @@
 
 /**
  * @file
- * Contains \Drupal\token\Tests\TokenURLTestCase.
+ * Contains \Drupal\token\Tests\TokenURLTest.
  */
+
 namespace Drupal\token\Tests;
+
 use Drupal\Core\Url;
 
 /**
@@ -12,8 +14,14 @@ use Drupal\Core\Url;
  *
  * @group token
  */
-class TokenURLTestCase extends TokenTestBase {
-  protected static $modules = array('path', 'token', 'token_test', 'node');
+class TokenURLTest extends TokenTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = array('node');
 
   /**
    * {@inheritdoc}
diff --git a/src/Tests/TokenUnitTestCase.php b/src/Tests/TokenUnitTest.php
similarity index 91%
rename from src/Tests/TokenUnitTestCase.php
rename to src/Tests/TokenUnitTest.php
index d5097e9..5470684 100644
--- a/src/Tests/TokenUnitTestCase.php
+++ b/src/Tests/TokenUnitTest.php
@@ -2,7 +2,7 @@
 
 /**
  * @file
- * Contains \Drupal\token\Tests\TokenUnitTestCase.
+ * Contains \Drupal\token\Tests\TokenUnitTest.
  */
 namespace Drupal\token\Tests;
 
@@ -11,8 +11,14 @@ namespace Drupal\token\Tests;
  *
  * @group token
  */
-class TokenUnitTestCase extends TokenTestBase {
-  protected static $modules = array('path', 'token', 'token_test', 'file', 'node');
+class TokenUnitTest extends TokenKernelTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = array('file', 'node');
 
   /**
    * Test token_get_invalid_tokens() and token_get_invalid_tokens_by_context().
diff --git a/src/Tests/TokenUserTestCase.php b/src/Tests/TokenUserTest.php
similarity index 95%
rename from src/Tests/TokenUserTestCase.php
rename to src/Tests/TokenUserTest.php
index 641e03d..d207318 100644
--- a/src/Tests/TokenUserTestCase.php
+++ b/src/Tests/TokenUserTest.php
@@ -2,7 +2,7 @@
 
 /**
  * @file
- * Contains \Drupal\token\Tests\TokenUserTestCase.
+ * Contains \Drupal\token\Tests\TokenUserTest.
  */
 
 namespace Drupal\token\Tests;
@@ -15,7 +15,7 @@ use Drupal\field\Entity\FieldStorageConfig;
  *
  * @group token
  */
-class TokenUserTestCase extends TokenTestBase {
+class TokenUserTest extends TokenTestBase {
 
   /**
    * The user account.
@@ -29,7 +29,7 @@ class TokenUserTestCase extends TokenTestBase {
    *
    * @var array
    */
-  protected static $modules = array('token_user_picture');
+  public static $modules = array('token_user_picture');
 
   /**
    * {@inheritdoc}
-- 
1.9.3 (Apple Git-50)


From a546e07a6f7d19002c8557f68d2b88b95ff92437 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Thu, 15 Jan 2015 01:26:29 +0100
Subject: [PATCH 222/230] @group should be the (lowercase) module name

---
 src/Tests/TokenEntityTest.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Tests/TokenEntityTest.php b/src/Tests/TokenEntityTest.php
index f759708..1071358 100644
--- a/src/Tests/TokenEntityTest.php
+++ b/src/Tests/TokenEntityTest.php
@@ -15,7 +15,7 @@ use Drupal\taxonomy\VocabularyInterface;
 /**
  * Tests entity tokens.
  *
- * @group Token
+ * @group token
  */
 class TokenEntityTest extends TokenKernelTestBase {
 
-- 
1.9.3 (Apple Git-50)


From b6fdbb9113cd90266e098bdd65db3e974677ff18 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Mon, 2 Feb 2015 20:17:44 +0100
Subject: [PATCH 223/230] description is optional in Drupal 8

---
 token.install | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/token.install b/token.install
index 26d8ca1..7646b11 100644
--- a/token.install
+++ b/token.install
@@ -254,7 +254,7 @@ function token_get_token_problems() {
       'label' => t('The following tokens or token types are not defined as arrays:'),
     ),
     'missing-info' => array(
-      'label' => t('The following tokens or token types are missing required name and/or description information:'),
+      'label' => t('The following tokens or token types are missing the required name:'),
     ),
     'type-no-tokens' => array(
       'label' => t('The following token types do not have any tokens defined:'),
@@ -274,7 +274,7 @@ function token_get_token_problems() {
       $token_problems['not-array']['problems'][] = "\$info['types']['$type']";
       continue;
     }
-    elseif (!isset($type_info['name']) || !isset($type_info['description'])) {
+    elseif (!isset($type_info['name'])) {
       $token_problems['missing-info']['problems'][] = "\$info['types']['$type']";
     }
     elseif (empty($token_info['tokens'][$real_type])) {
@@ -294,10 +294,10 @@ function token_get_token_problems() {
           $token_problems['not-array']['problems'][] = "\$info['tokens']['$type']['$token']";
           continue;
         }
-        elseif (!isset($tokens[$token]['name']) || !isset($tokens[$token]['description'])) {
+        elseif (!isset($tokens[$token]['name'])) {
           $token_problems['missing-info']['problems'][] = "\$info['tokens']['$type']['$token']";
         }
-        elseif (is_array($tokens[$token]['name']) || is_array($tokens[$token]['description'])) {
+        elseif (is_array($tokens[$token]['name']) || isset($tokens[$token]['description']) && is_array($tokens[$token]['description'])) {
           $token_problems['duplicate']['problems'][] = "\$info['tokens']['$type']['$token']";
         }
       }
-- 
1.9.3 (Apple Git-50)


From 12023333c32049ce7175f93b6db76c55efa57def Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Tue, 3 Feb 2015 23:59:28 +0100
Subject: [PATCH 224/230] Remove dead code, no longer needed fixes and old
 hooks

---
 src/Controller/TokenAutocompleteController.php     | 20 +------
 src/Controller/TokenCacheController.php            | 36 ++----------
 src/Controller/TokenDevelController.php            |  1 -
 .../config/install/core.date_format.token_test.yml |  1 -
 token.drush.inc                                    |  4 +-
 token.module                                       | 59 +-------------------
 token.routing.yml                                  |  4 ++
 token.tokens.inc                                   | 65 ----------------------
 8 files changed, 14 insertions(+), 176 deletions(-)

diff --git a/src/Controller/TokenAutocompleteController.php b/src/Controller/TokenAutocompleteController.php
index 8aadff3..60e977a 100644
--- a/src/Controller/TokenAutocompleteController.php
+++ b/src/Controller/TokenAutocompleteController.php
@@ -8,30 +8,14 @@
 namespace Drupal\token\Controller;
 
 use Drupal\Component\Utility\Unicode;
-use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
-use Symfony\Component\DependencyInjection\ContainerInterface;
+use Drupal\Core\Controller\ControllerBase;
 use Symfony\Component\HttpFoundation\JsonResponse;
 use Symfony\Component\HttpFoundation\Request;
 
 /**
  * Returns autocomplete responses for tokens.
  */
-class TokenAutocompleteController implements ContainerInjectionInterface {
-
-  /**
-   * Constructs a new TokenAutocompleteController.
-   */
-  public function __construct() {
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public static function create(ContainerInterface $container) {
-    return new static(
-
-    );
-  }
+class TokenAutocompleteController extends ControllerBase {
 
   /**
    * Retrieves suggestions for block category autocompletion.
diff --git a/src/Controller/TokenCacheController.php b/src/Controller/TokenCacheController.php
index 279e614..a086906 100644
--- a/src/Controller/TokenCacheController.php
+++ b/src/Controller/TokenCacheController.php
@@ -8,47 +8,19 @@
 namespace Drupal\token\Controller;
 
 use Drupal\Core\Controller\ControllerBase;
-use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
-use Drupal\Core\Url;
-use Symfony\Cmf\Component\Routing\RouteObjectInterface;
-use Symfony\Component\DependencyInjection\ContainerInterface;
-use Symfony\Component\HttpFoundation\Request;
 
 /**
  * Clears cache for tokens.
  */
-class TokenCacheController extends ControllerBase implements ContainerInjectionInterface  {
+class TokenCacheController extends ControllerBase  {
 
   /**
-   * @var \Drupal\Core\Access\CsrfTokenGenerator
+   * Clear caches and redirect back to the frontpage.
    */
-  private $csrfToken;
-
-  /**
-   * Constructs a new TokenAutocompleteController.
-   */
-  public function __construct($csrf_token) {
-    $this->csrfToken = $csrf_token;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public static function create(ContainerInterface $container) {
-    return new static(
-      $container->get('csrf_token')
-    );
-  }
-
-  public function flush(Request $request) {
-    $current_url = Url::fromRoute('<current>');
-    if (!$request->query->has('token') || ! $this->csrfToken->validate($request->query->get('token'), $current_url->toString())) {
-      return MENU_NOT_FOUND;
-    }
-
+  public function flush() {
     token_clear_cache();
     drupal_set_message(t('Token registry caches cleared.'));
-    return $this->redirect($request->attributes->get(RouteObjectInterface::ROUTE_NAME), $request->attributes->get('_raw_variables', array()));
+    return $this->redirect('<front>');
   }
 
 }
diff --git a/src/Controller/TokenDevelController.php b/src/Controller/TokenDevelController.php
index 964bcb5..7f29048 100644
--- a/src/Controller/TokenDevelController.php
+++ b/src/Controller/TokenDevelController.php
@@ -8,7 +8,6 @@
 namespace Drupal\token\Controller;
 
 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
-use Drupal\Core\Extension\ModuleHandler;
 use Drupal\Core\Extension\ModuleHandlerInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\HttpFoundation\Request;
diff --git a/tests/token_test/config/install/core.date_format.token_test.yml b/tests/token_test/config/install/core.date_format.token_test.yml
index ca6dd1d..c05b275 100644
--- a/tests/token_test/config/install/core.date_format.token_test.yml
+++ b/tests/token_test/config/install/core.date_format.token_test.yml
@@ -1,5 +1,4 @@
 id: token_test
-uuid: 3A60E8ED-25C7-4402-8F2A-C305B8916B0E
 label: 'Token test'
 status: true
 langcode: en
diff --git a/token.drush.inc b/token.drush.inc
index fc32357..b31b8d7 100644
--- a/token.drush.inc
+++ b/token.drush.inc
@@ -9,9 +9,7 @@
  * Implements hook_drush_cache_clear().
  */
 function token_drush_cache_clear(&$types) {
-  if (function_exists('module_exists') && module_exists('token')) {
-    $types['token'] = 'drush_token_cache_clear_token_info';
-  }
+  $types['token'] = 'drush_token_cache_clear_token_info';
 }
 
 /**
diff --git a/token.module b/token.module
index 194c07e..8687a9c 100644
--- a/token.module
+++ b/token.module
@@ -57,62 +57,6 @@ function _token_core_supported_modules() {
 }
 
 /**
- * Implements hook_menu().
- */
-function token_menu() {
-
-  // Devel token pages.
-  if (\Drupal::moduleHandler()->moduleExists('devel')) {
-    $items['node/%node/devel/token'] = array(
-      'title' => 'Tokens',
-      'page callback' => 'token_devel_token_object',
-      'page arguments' => array('node', 1),
-      'access arguments' => array('access devel information'),
-      'type' => MENU_LOCAL_TASK,
-      'file' => 'token.pages.inc',
-      'weight' => 5,
-    );
-    $items['comment/%comment/devel/token'] = array(
-      'title' => 'Tokens',
-      'page callback' => 'token_devel_token_object',
-      'page arguments' => array('comment', 1),
-      'access arguments' => array('access devel information'),
-      'type' => MENU_LOCAL_TASK,
-      'file' => 'token.pages.inc',
-      'weight' => 5,
-    );
-    $items['taxonomy/term/%taxonomy_term/devel/token'] = array(
-      'title' => 'Tokens',
-      'page callback' => 'token_devel_token_object',
-      'page arguments' => array('taxonomy_term', 2),
-      'access arguments' => array('access devel information'),
-      'type' => MENU_LOCAL_TASK,
-      'file' => 'token.pages.inc',
-      'weight' => 5,
-    );
-    $items['user/%user/devel/token'] = array(
-      'title' => 'Tokens',
-      'page callback' => 'token_devel_token_object',
-      'page arguments' => array('user', 1),
-      'access arguments' => array('access devel information'),
-      'type' => MENU_LOCAL_TASK,
-      'file' => 'token.pages.inc',
-      'weight' => 5,
-    );
-  }
-
-  // Admin menu callback to clear token caches.
-  $items['token/flush-cache'] = array(
-    'page callback' => 'token_flush_cache_callback',
-    'access arguments' => array('flush caches'),
-    'type' => MENU_CALLBACK,
-    'file' => 'token.pages.inc',
-  );
-
-  return $items;
-}
-
-/**
  * Implements hook_admin_menu_output_alter().
  */
 function token_admin_menu_output_alter(&$content) {
@@ -142,6 +86,7 @@ function token_theme() {
       'empty' => '',
       'caption' => '',
     ),
+    'function' => 'theme_tree_table',
     'file' => 'token.pages.inc',
   );
   $info['token_tree'] = array(
@@ -153,6 +98,7 @@ function token_theme() {
       'recursion_limit' => 3,
       'dialog' => FALSE,
     ),
+    'function' => 'theme_token_tree',
     'file' => 'token.pages.inc',
   );
   $info['token_tree_link'] = array(
@@ -161,6 +107,7 @@ function token_theme() {
       'options' => array(),
       'dialog' => TRUE,
     ),
+    'function' => 'theme_token_tree_link',
     'file' => 'token.pages.inc',
   );
 
diff --git a/token.routing.yml b/token.routing.yml
index c571c87..dc61416 100644
--- a/token.routing.yml
+++ b/token.routing.yml
@@ -11,12 +11,16 @@ token.autocomplete:
     _controller: '\Drupal\token\Controller\TokenAutocompleteController::autocomplete'
   requirements:
     _access: 'TRUE'
+
 token.flush_cache:
   path: '/token/flush-cache'
   defaults:
     _controller: '\Drupal\token\Controller\TokenCacheController::flush'
   requirements:
     _permission: 'flush caches'
+    _csrf_token: 'TRUE'
+    _module_dependencies: 'admin_menu'
+
 token.devel_node_token:
   path: '/node/{node}/devel/token'
   defaults:
diff --git a/token.tokens.inc b/token.tokens.inc
index 4863eae..f18cf0b 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -938,71 +938,6 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
 }
 
 /**
- * Implements hook_tokens_alter().
- *
- * Fix existing core tokens that do not work correctly.
- */
-function token_tokens_alter(array &$replacements, array $context) {
-  $options = $context['options'];
-
-  $sanitize = !empty($options['sanitize']);
-  $langcode = !empty($options['language']->language) ? $options['language']->language : NULL;
-
-  // Comment token fixes.
-  if ($context['type'] == 'comment' && !empty($context['data']['comment'])) {
-    $comment = $context['data']['comment'];
-
-    foreach ($context['tokens'] as $name => $original) {
-      switch ($name) {
-        case 'name':
-        case 'author':
-          // @todo Remove when http://drupal.org/node/920056 is fixed.
-          if (!empty($comment->uid)) {
-            $account = user_load($comment->uid->value);
-          }
-          else {
-            $account = drupal_anonymous_user();
-            $account->name = $comment->name;
-          }
-          $name = $account->getUsername();
-          $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
-          break;
-      }
-    }
-  }
-
-  // Node token fixes.
-  if ($context['type'] == 'node' && !empty($context['data']['node'])) {
-    $node = $context['data']['node'];
-
-    foreach ($context['tokens'] as $name => $original) {
-      switch ($name) {
-        case 'author':
-          $account = user_load($node->uid->value);
-          $name = $account->getUsername();
-          $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
-          break;
-      }
-    }
-  }
-
-  // File token fixes.
-  if ($context['type'] == 'file' && !empty($context['data']['file'])) {
-    $file = $context['data']['file'];
-
-    foreach ($context['tokens'] as $name => $original) {
-      switch ($name) {
-        case 'owner':
-          $account = user_load($file->uid->value);
-          $name = $account->getUsername();
-          $replacements[$original] = $sanitize ? String::checkPlain($name) : $name;
-          break;
-      }
-    }
-  }
-}
-
-/**
  * Implements hook_token_info() on behalf of book.module.
  */
 function book_token_info() {
-- 
1.9.3 (Apple Git-50)


From 69fe017b58358159fe29fe22d4bd8773b83b35e1 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 4 Feb 2015 00:10:40 +0100
Subject: [PATCH 225/230] Remove autocomplete callback functions

---
 token.pages.inc | 44 --------------------------------------------
 1 file changed, 44 deletions(-)

diff --git a/token.pages.inc b/token.pages.inc
index 220a925..d4e3858 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -277,48 +277,4 @@ function token_devel_token_object($entity_type, $entity, $token_type = NULL) {
   return $build;
 }
 
-function token_autocomplete() {
-  $args = func_get_args();
-  $string = implode('/', $args);
-
-  $token_info = \Drupal::token()->getInfo();
-
-  preg_match_all('/\[([^\s\]:]*):?([^\s\]]*)?\]?/', $string, $matches);
-  $types = $matches[1];
-  $tokens = $matches[2];
-
-  foreach ($types as $index => $type) {
-    if (!empty($tokens[$index]) || isset($token_info['types'][$type])) {
-      token_autocomplete_token($type, $tokens[$index]);
-    }
-    else {
-      token_autocomplete_type($type);
-    }
-  }
-
-}
-
-function token_autocomplete_type($string = '') {
-  $token_info = \Drupal::token()->getInfo();
-  $types = $token_info['types'];
-  $matches = array();
-
-  foreach ($types as $type => $info) {
-    if (!$string || strpos($type, $string) === 0) {
-      $type_key = "[{$type}:";
-      $matches[$type_key] = levenshtein($type, $string);
-    }
-  }
-
-  if ($string) {
-    asort($matches);
-  }
-  else {
-    ksort($matches);
-  }
-
-  $keys = array_keys($matches);
-  $matches = array_combine($keys, $keys);
-  drupal_json_output($matches);
-}
 
-- 
1.9.3 (Apple Git-50)


From 109dad3d82effc22cc45c0a9cf17532987017c56 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 4 Feb 2015 00:12:44 +0100
Subject: [PATCH 226/230] Avoid error because token_tokens_alter() was removed

---
 token.module | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/token.module b/token.module
index 0ac42c9..d0ca1e7 100644
--- a/token.module
+++ b/token.module
@@ -342,8 +342,10 @@ function token_module_implements_alter(&$implementations, $hook) {
     }
     // Move token.module to get included first since it is responsible for
     // other modules.
-    unset($implementations['token']);
-    $implementations = array_merge(array('token' => 'tokens'), $implementations);
+    if (isset($implementations['token'])) {
+      unset($implementations['token']);
+      $implementations = array_merge(array('token' => 'tokens'), $implementations);
+    }
   }
 }
 
-- 
1.9.3 (Apple Git-50)


From 56c9401bf634d99ea38c46170e8e700d892baba6 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 4 Feb 2015 00:36:20 +0100
Subject: [PATCH 227/230] Fix getDescription() method name

---
 token.module | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.module b/token.module
index d0ca1e7..49c97b1 100644
--- a/token.module
+++ b/token.module
@@ -164,7 +164,7 @@ function token_form_block_form_alter(&$form, FormStateInterface $form_state) {
 function token_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
   if (!empty($element['#description']) && is_string($element['#description'])) {
     /* @var \Drupal\Core\Field\FieldItemListInterface $context['items'] */
-    $element['#description'] = Xss::filterAdmin(\Drupal::token()->replace($context['items']->getFieldDefinition()->getFieldDescription()));
+    $element['#description'] = Xss::filterAdmin(\Drupal::token()->replace($context['items']->getFieldDefinition()->getDescription()));
   }
 }
 
-- 
1.9.3 (Apple Git-50)


From 4f62a94663ac4c969756c99387f9488d764ca24b Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 4 Feb 2015 00:36:30 +0100
Subject: [PATCH 228/230] Replace removed drupal_array_diff_assoc_recursive()

---
 token.pages.inc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/token.pages.inc b/token.pages.inc
index d4e3858..5b5679f 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -5,6 +5,7 @@
  * User page callbacks for the token module.
  */
 use Drupal\Component\Serialization\Json;
+use Drupal\Component\Utility\DiffArray;
 use Drupal\Core\Url;
 use Drupal\Core\Utility\Token;
 
@@ -25,7 +26,7 @@ function theme_token_tree_link($variables) {
 
   $info = token_theme();
   $tree_variables = array_intersect_key($variables, $info['token_tree']['variables']);
-  $tree_variables = drupal_array_diff_assoc_recursive($tree_variables, $info['token_tree']['variables']);
+  $tree_variables = DiffArray::diffAssocRecursive($tree_variables, $info['token_tree']['variables']);
   if (!isset($variables['options']['query']['options'])) {
     $variables['options']['query']['options'] = array();
   }
-- 
1.9.3 (Apple Git-50)


From 8ce3cc2e143c85f1a669cb012fe636989b0388d0 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Wed, 4 Feb 2015 00:57:32 +0100
Subject: [PATCH 229/230] Disable broken render cache

---
 token.pages.inc | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/token.pages.inc b/token.pages.inc
index 5b5679f..988ec5e 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -76,7 +76,9 @@ function theme_tree_table($variables) {
     $output['#attached']['library'][] = 'token/jquery.treeTable';
   }
   $output['#type'] = 'table';
-  $output['#variables'] = $variables;
+  foreach ($variables as $key => $value) {
+    $output['#' . $key] = $value;
+  }
   /** @var \Drupal\Core\Render\RendererInterface $renderer */
   $renderer = \Drupal::service('renderer');
   return $renderer->render($output);
@@ -114,9 +116,11 @@ function theme_token_tree($variables) {
       'tags' => array(Token::TOKEN_INFO_CACHE_TAG),
     ),
   );
-  if ($cached_output = token_render_cache_get($element)) {
+
+  // @todo Find a way to use the render cache for this.
+  /*if ($cached_output = token_render_cache_get($element)) {
     return $cached_output;
-  }
+  }*/
 
   $options = array(
     'flat' => TRUE,
@@ -173,7 +177,7 @@ function theme_token_tree($variables) {
   }
 
   $output = drupal_render($element);
-  token_render_cache_set($output, $element);
+  //token_render_cache_set($output, $element);
   return $output;
 }
 
-- 
1.9.3 (Apple Git-50)


From afbb23b8b521fd4f95fe5d4aec7f70a48c79326f Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Wed, 4 Feb 2015 10:20:54 +1000
Subject: [PATCH 230/230] Remove travis

---
 .travis.yml | 98 -------------------------------------------------------------
 1 file changed, 98 deletions(-)
 delete mode 100644 .travis.yml

diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 62e4acc..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,98 +0,0 @@
-language: php
-cache:
-  bundler: true
-  directories:
-    - $HOME/tmp/drush
-    - $HOME/.bundle
-  apt: true
-
-php:
-  - 5.4
-  - 5.5
-
-env:
-  - PATH=$PATH:/home/travis/.composer/vendor/bin
-
-# This will create the database
-mysql:
-  database: drupal
-  username: root
-  encoding: utf8
-
-# To be able to run a webbrowser
-# If we need anything more powerful
-# than e.g. phantomjs
-before_install:
-  - "export DISPLAY=:99.0"
-  - "sh -e /etc/init.d/xvfb start"
-
-install:
-  # Grab Drush
-  - composer global require drush/drush:dev-master --prefer-source
-  - cd /home/travis/.composer/vendor/drush/drush && cd -
-  # Make sure we don't fail when checking out projects
-  - echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
-  # LAMP package installation (mysql is already started)
-  - sudo apt-get update
-  - sudo apt-get install apache2 libapache2-mod-fastcgi
-  # enable php-fpm, travis does not support any other method with php and apache
-  - sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf
-  - sudo a2enmod rewrite actions fastcgi alias
-  - echo "cgi.fix_pathinfo = 1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
-  - ~/.phpenv/versions/$(phpenv version-name)/sbin/php-fpm
-  # Make sure the apache root is in our wanted directory
-  - echo "$(curl -fsSL https://gist.githubusercontent.com/nickveenhof/11386315/raw/b8abaf9304fe12b5cc7752d39c29c1edae8ac2e6/gistfile1.txt)" | sed -e "s,PATH,$TRAVIS_BUILD_DIR/../drupal,g" | sudo tee /etc/apache2/sites-available/default > /dev/null
-  # Set sendmail so drush doesn't throw an error during site install.
-  - echo "sendmail_path='true'" >> `php --ini | grep "Loaded Configuration" | awk '{print $4}'`
-  # Forward the errors to the syslog so we can print them
-  - echo "error_log=syslog" >> `php --ini | grep "Loaded Configuration" | awk '{print $4}'`
-  # Get latest drupal 8 core
-  - cd $TRAVIS_BUILD_DIR/..
-  - git clone --depth 1 --branch 8.0.x http://git.drupal.org/project/drupal.git
-  # Restart apache and test it
-  - sudo service apache2 restart
-  - curl -v "http://localhost"
-  # Re-enable when trying to get CodeSniffer doesn't return a 403 anymore.
-  #- composer global require drupal/coder:\>7
-
-before_script:
-  - cd $TRAVIS_BUILD_DIR/../drupal
-  # Update drupal core
-  - git pull origin 8.0.x
-  # Install the site
-  - drush -v site-install minimal --db-url=mysql://root:@localhost/drupal --yes
-  - drush en --yes simpletest
-  - drush cr
-  - phpenv rehash
-
-script:
-  # go to our Drupal module directory
-  - mkdir $TRAVIS_BUILD_DIR/../drupal/modules/token
-  - cp -R $TRAVIS_BUILD_DIR/* $TRAVIS_BUILD_DIR/../drupal/modules/token/
-  # go to our Drupal main directory
-  - cd $TRAVIS_BUILD_DIR/../drupal
-  - ls -la $TRAVIS_BUILD_DIR/../drupal/sites/default
-  # Run the tests
-  - php core/scripts/run-tests.sh --verbose --color --concurrency 4 --php `which php` --url http://localhost "token" | tee /tmp/test.txt
-  - TEST_EXIT=${PIPESTATUS[0]}
-  - echo $TEST_EXIT
-  # Check if we had fails in the run-tests.sh script
-  # Exit with the inverted value, because if there are no fails found, it will exit with 1 and for us that\
-  # is a good thing so invert it to 0. Travis has some issues with the exclamation mark in front so we have to fiddle a
-  # bit.
-  # Also make the grep case insensitive and fail on run-tests.sh regular fails as well on fatal errors.
-  - TEST_OUTPUT=$(! egrep -i "([0-9]+ fails)|(PHP Fatal error)|([0-9]+ exceptions)" /tmp/test.txt > /dev/null)$?
-  - echo $TEST_OUTPUT
-  - cd $TRAVIS_BUILD_DIR/../drupal/core
-  - ./vendor/bin/phpunit --verbose --debug ../modules/token/
-  - TEST_PHPUNIT=$?
-  - echo $TEST_PHPUNIT
-  # if the TEST_EXIT status is 0 AND the TEST_OUTPUT status is also 0 it means we succeeded, in all other cases we
-  # failed.
-  # Re-enable when trying to get CodeSniffer doesn't return a 403 anymore.
-  #- /home/travis/.composer/vendor/bin/phpcs --standard=/home/travis/.composer/vendor/drupal/coder/coder_sniffer/Drupal --extensions=php,inc,test,module,install --ignore=css/ $TRAVIS_BUILD_DIR/../drupal/modules/search_api
-  - php -i | grep 'php.ini'
-  - sudo cat /var/log/apache2/error.log
-  - sudo cat /var/log/syslog | grep 'php'
-  # Exit the build
-  - if [ $TEST_EXIT -eq 0 ] && [ $TEST_OUTPUT -eq 0 ] && [ $TEST_PHPUNIT -eq 0 ]; then exit 0; else exit 1; fi
-- 
1.9.3 (Apple Git-50)

