? patches
? token_profile.inc
Index: token.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/token/token.install,v
retrieving revision 1.2.2.1
diff -u -p -r1.2.2.1 token.install
--- token.install	28 Jun 2008 15:10:22 -0000	1.2.2.1
+++ token.install	24 Sep 2010 19:07:36 -0000
@@ -8,6 +8,31 @@
  * @ingroup token
  */
 
+/**
+ * Implements hook_requirements().
+ */
+function token_requirements($phase = 'runtime') {
+  $requirements = array();
+  $t = get_t();
+
+  // Check for duplicate tokens.
+  if ($phase == 'runtime') {
+    if ($duplicate_tokens = token_find_duplicate_tokens()) {
+      foreach ($duplicate_tokens as $token => $modules) {
+        $duplicate_tokens[$token] = t('@token (defined by modules: @modules)', array('@token' => $token, '@modules' => implode(', ', $modules)));
+      }
+      $requirements['token_duplicates'] = array(
+        'title' => $t('Duplicate tokens'),
+        'value' => $t('The following tokens are defined by multiple modules and may cause problems when performing token replacement.'),
+        'severity' => REQUIREMENT_WARNING,
+        'description' => theme('item_list', $duplicate_tokens),
+      );
+    }
+  }
+
+  return $requirements;
+}
+
 function token_install() {
   db_query("UPDATE {system} SET weight = 10 WHERE name = 'token'");
 }
@@ -16,4 +41,4 @@ function token_update_1() {
   $ret = array();
   $ret[] = update_sql("UPDATE {system} SET weight = 10 WHERE name = 'token'");
   return $ret;
-}
\ No newline at end of file
+}
Index: token.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/token/token.module,v
retrieving revision 1.7.4.35
diff -u -p -r1.7.4.35 token.module
--- token.module	19 Sep 2010 22:46:58 -0000	1.7.4.35
+++ token.module	24 Sep 2010 19:07:37 -0000
@@ -39,6 +39,7 @@ function token_help($path, $arg) {
  * Impelments hook_menu().
  */
 function token_menu() {
+  $items = array();
   if (module_exists('devel')) {
     $items['node/%node/devel/token'] = array(
       'title' => 'Tokens',
@@ -58,8 +59,8 @@ function token_menu() {
       'file' => 'token.pages.inc',
       'weight' => 5,
     );
-    return $items;
   }
+  return $items;
 }
 
 /**
@@ -347,7 +348,7 @@ function token_get_values($type = 'globa
     $tokens['global']['default'] = module_invoke_all('token_values', 'global');
   }
 
-  $all = _token_array_merge($tokens['global']['default'], $tokens[$type][$id]);
+  $all = array_merge($tokens['global']['default'], $tokens[$type][$id]);
 
   $result = new stdClass();
   $result->tokens = array_keys($all);
@@ -358,37 +359,12 @@ function token_get_values($type = 'globa
   return $result;
 }
 
-/**
- * Merge two arrays of token values, checking and warning for duplication.
- *
- * Because array_merge will combinue elements that have the same key into an
- * array instead of overriding the existing element, this causes problems since
- * we need the values to always be a string.
- *
- * @param $array1
- *   An array of token values keyed by token name.
- * @param $array2
- *   An array of token values keyed by token name.
- * @return
- *   A merged array of token values keyed by token name.
- */
-function _token_array_merge($array1, $array2) {
-  static $warned = array();
-
-  $merged = array_merge($array1, $array2);
-  foreach ($merged as $key => $value) {
-    if (is_array($value)) {
-      if (empty($warned[$key])) {
-        // Only warn once about duplicate token.
-        watchdog('token', 'More than one module has defined the %key token.', array('%key' => $key), WATCHDOG_WARNING);
-        $warned[$key] = TRUE;
-      }
-      // Use the last-defined value (module with lowest weight).
-      $merged[$key] = array_pop($value);
-    }
+function _token_get_values($type, $object = NULL, $options = array()) {
+  $tokens = array();
+  foreach (module_implements('token_values') as $module) {
+    $tokens[$module] = module_invoke($module, 'token_values', $type, $object, $options);
   }
-
-  return $merged;
+  return $tokens;
 }
 
 /**
@@ -644,3 +620,31 @@ function token_element_validate_token_co
   }
   return $element;
 }
+
+/**
+ * Find tokens that have been declared twice by different modules.
+ */
+function token_find_duplicate_tokens() {
+  token_include();
+  $all_tokens = array();
+
+  foreach (module_implements('token_list') as $module) {
+    $module_tokens = module_invoke($module, 'token_list', 'all');
+    if (in_array($module, array('node', 'taxonomy', 'comment', 'user'))) {
+      $module = 'token';
+    }
+    foreach ($module_tokens as $type => $tokens) {
+      foreach (array_keys($tokens) as $token) {
+        $all_tokens[$type . ':' . $token][] = $module;
+      }
+    }
+  }
+
+  foreach ($all_tokens as $token => $modules) {
+    if (count($modules) < 2) {
+      unset($all_tokens[$token]);
+    }
+  }
+
+  return $all_tokens;
+}
