added some modules, updated some others
This commit is contained in:
@@ -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)
|
||||
@@ -5,9 +5,8 @@ core = 7.x
|
||||
files[] = token_test.module
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-02-24
|
||||
version = "7.x-1.5"
|
||||
; Information added by Drupal.org packaging script on 2021-03-02
|
||||
version = "7.x-1.8"
|
||||
core = "7.x"
|
||||
project = "token"
|
||||
datestamp = "1361665026"
|
||||
|
||||
datestamp = "1614719852"
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_token_info()
|
||||
*/
|
||||
function token_test_token_info() {
|
||||
$info['tokens']['node']['colons:in:name'] = array(
|
||||
'name' => t('A test token with colons in the name'),
|
||||
'description' => NULL,
|
||||
);
|
||||
|
||||
return $info;
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
name = Token
|
||||
description = Provides a user interface for the Token API and some missing core tokens.
|
||||
core = 7.x
|
||||
dependencies[] = system (>=7.23)
|
||||
files[] = token.test
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-02-24
|
||||
version = "7.x-1.5"
|
||||
; Information added by Drupal.org packaging script on 2021-03-02
|
||||
version = "7.x-1.8"
|
||||
core = "7.x"
|
||||
project = "token"
|
||||
datestamp = "1361665026"
|
||||
|
||||
datestamp = "1614719852"
|
||||
|
||||
@@ -21,18 +21,12 @@ function token_requirements($phase = 'runtime') {
|
||||
$problems = array_unique($problem['problems']);
|
||||
$problems = array_map('check_plain', $problems);
|
||||
$token_problems[$problem_key] = $problem['label'] . theme('item_list', array('items' => $problems));
|
||||
$requirements['token-' . $problem_key] = array(
|
||||
'title' => $problem['label'],
|
||||
'value' => theme('item_list', array('items' => $problems)),
|
||||
'severity' => $problem['severity'],
|
||||
);
|
||||
}
|
||||
else {
|
||||
unset($token_problems[$problem_key]);
|
||||
}
|
||||
}
|
||||
if (!empty($token_problems)) {
|
||||
$requirements['token_problems'] = array(
|
||||
'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)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,19 +266,24 @@ function token_get_token_problems() {
|
||||
$token_info = token_info();
|
||||
$token_problems = array(
|
||||
'not-array' => array(
|
||||
'label' => t('The following tokens or token types are not defined as arrays:'),
|
||||
'label' => t('Tokens or token types not defined as arrays'),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
),
|
||||
'missing-info' => array(
|
||||
'label' => t('The following tokens or token types are missing required name and/or description information:'),
|
||||
'label' => t('Tokens or token types missing name property'),
|
||||
'severity' => REQUIREMENT_WARNING,
|
||||
),
|
||||
'type-no-tokens' => array(
|
||||
'label' => t('The following token types do not have any tokens defined:'),
|
||||
'label' => t('Token types do not have any tokens defined'),
|
||||
'severity' => REQUIREMENT_INFO,
|
||||
),
|
||||
'tokens-no-type' => array(
|
||||
'label' => t('The following token types are not defined but have tokens:'),
|
||||
'label' => t('Token types are not defined but have tokens'),
|
||||
'severity' => REQUIREMENT_INFO,
|
||||
),
|
||||
'duplicate' => array(
|
||||
'label' => t('The following token or token types are defined by multiple modules:')
|
||||
'label' => t('Token or token types are defined by multiple modules'),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -295,9 +294,12 @@ 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 (is_array($type_info['name'])) {
|
||||
$token_problems['duplicate']['problems'][] = "\$info['types']['$type']";
|
||||
}
|
||||
elseif (empty($token_info['tokens'][$real_type])) {
|
||||
$token_problems['type-no-tokens']['problems'][] = "\$info['tokens']['$real_type']";
|
||||
}
|
||||
@@ -315,10 +317,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'])) {
|
||||
$token_problems['duplicate']['problems'][] = "\$info['tokens']['$type']['$token']";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,6 +161,8 @@ function token_theme() {
|
||||
'attributes' => array(),
|
||||
'empty' => '',
|
||||
'caption' => '',
|
||||
'colgroups' => array(),
|
||||
'sticky' => TRUE,
|
||||
),
|
||||
'file' => 'token.pages.inc',
|
||||
);
|
||||
@@ -180,7 +182,7 @@ function token_theme() {
|
||||
'text' => NULL,
|
||||
'options' => array(),
|
||||
'dialog' => TRUE,
|
||||
),
|
||||
) + $info['token_tree']['variables'],
|
||||
'file' => 'token.pages.inc',
|
||||
);
|
||||
|
||||
@@ -273,8 +275,12 @@ 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'])) {
|
||||
$instance = $context['instance'];
|
||||
if (module_exists('i18n_field')) {
|
||||
$instance = i18n_string_object_translate('field_instance', $instance);
|
||||
}
|
||||
$element['#description'] = field_filter_xss(token_replace($instance['description']));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -412,12 +418,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'])) {
|
||||
@@ -647,6 +659,10 @@ function token_get_invalid_tokens($type, $tokens) {
|
||||
$invalid_tokens = array();
|
||||
|
||||
foreach ($tokens as $token => $full_token) {
|
||||
if (isset($token_info['tokens'][$type][$token])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Split token up if it has chains.
|
||||
$parts = explode(':', $token, 2);
|
||||
|
||||
@@ -709,15 +725,13 @@ 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));
|
||||
$error = format_plural($element['#min_tokens'], '%name must contain at least one token.', '%name must contain at least @count tokens.', array('%name' => $title));
|
||||
form_error($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));
|
||||
$error = format_plural($element['#max_tokens'], '%name must contain at most one token.', '%name must contain at most @count tokens.', array('%name' => $title));
|
||||
form_error($element, $error);
|
||||
}
|
||||
|
||||
@@ -725,7 +739,7 @@ function token_element_validate(&$element, &$form_state) {
|
||||
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))));
|
||||
form_error($element, t('%name is using the following invalid tokens: @invalid-tokens.', array('%name' => $title, '@invalid-tokens' => implode(', ', $invalid_tokens))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -973,7 +987,7 @@ function _token_build_tree($token_type, array $options) {
|
||||
// parent.
|
||||
$token_parents[] = $token_type;
|
||||
}
|
||||
elseif (in_array($token, array_slice($token_parents, 1))) {
|
||||
elseif (in_array($token, array_slice($token_parents, 1), TRUE)) {
|
||||
// Prevent duplicate recursive tokens. For example, this will prevent
|
||||
// the tree from generating the following tokens or deeper:
|
||||
// [comment:parent:parent]
|
||||
@@ -1216,7 +1230,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 && $plid != $mlid && $parent = token_menu_link_load($plid)) {
|
||||
$cache[$mlid] = array($plid => $parent['title']) + $cache[$mlid];
|
||||
$plid = $parent['plid'];
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -194,7 +199,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.
|
||||
@@ -202,6 +207,7 @@ function _token_token_tree_format_row($token, array $token_info, $is_group = FAL
|
||||
}
|
||||
else {
|
||||
// This is a token.
|
||||
$row['data']['token'] = array();
|
||||
$row['data']['token']['data'] = $token;
|
||||
$row['data']['token']['class'][] = 'token-key';
|
||||
if (isset($token_info['value'])) {
|
||||
|
||||
@@ -137,6 +137,7 @@ class TokenUnitTestCase extends TokenTestHelper {
|
||||
'[node:created:short]',
|
||||
'[node:created:custom:invalid]',
|
||||
'[node:created:custom:mm-YYYY]',
|
||||
'[node:colons:in:name]',
|
||||
'[site:name]',
|
||||
'[site:slogan]',
|
||||
'[current-date:short]',
|
||||
@@ -147,6 +148,7 @@ class TokenUnitTestCase extends TokenTestHelper {
|
||||
'[node:title:invalid]',
|
||||
'[node:created:invalid]',
|
||||
'[node:created:short:invalid]',
|
||||
'[node:colons:in:name:invalid]',
|
||||
'[invalid:title]',
|
||||
'[site:invalid]',
|
||||
'[user:ip-address]',
|
||||
@@ -166,6 +168,7 @@ class TokenUnitTestCase extends TokenTestHelper {
|
||||
'[node:created:short]',
|
||||
'[node:created:custom:invalid]',
|
||||
'[node:created:custom:mm-YYYY]',
|
||||
'[node:colons:in:name]',
|
||||
'[site:name]',
|
||||
'[site:slogan]',
|
||||
'[user:uid]',
|
||||
@@ -176,6 +179,7 @@ class TokenUnitTestCase extends TokenTestHelper {
|
||||
'[node:title:invalid]',
|
||||
'[node:created:invalid]',
|
||||
'[node:created:short:invalid]',
|
||||
'[node:colons:in:name:invalid]',
|
||||
'[invalid:title]',
|
||||
'[site:invalid]',
|
||||
'[user:ip-address]',
|
||||
@@ -952,6 +956,7 @@ class TokenArrayTestCase extends TokenTestHelper {
|
||||
'last' => 'b',
|
||||
'value:0' => 'a',
|
||||
'value:2' => 'c',
|
||||
'value:#property' => NULL,
|
||||
'count' => 4,
|
||||
'keys' => '2, 0, 4, 1',
|
||||
'keys:value:3' => '1',
|
||||
@@ -1076,7 +1081,7 @@ class TokenBlockTestCase extends TokenTestHelper {
|
||||
$edit['body[value]'] = 'This is the test token title block.';
|
||||
$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].');
|
||||
$this->assertText('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';
|
||||
|
||||
@@ -848,7 +848,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')) {
|
||||
foreach ($value_tokens as $key => $original) {
|
||||
if ($key[0] !== '#' && isset($array[$key])) {
|
||||
if (array_key_exists($key, $array) && in_array($key, $keys)) {
|
||||
$replacements[$original] = token_render_array_value($array[$key], $options);
|
||||
}
|
||||
}
|
||||
@@ -1392,7 +1392,6 @@ function field_token_info_alter(&$info) {
|
||||
*/
|
||||
function field_tokens($type, $tokens, array $data = array(), array $options = array()) {
|
||||
$replacements = array();
|
||||
$sanitize = !empty($options['sanitize']);
|
||||
$langcode = isset($options['language']) ? $options['language']->language : NULL;
|
||||
|
||||
// Entity tokens.
|
||||
@@ -1437,7 +1436,7 @@ function field_tokens($type, $tokens, array $data = array(), array $options = ar
|
||||
/**
|
||||
* Pre-render callback for field output used with tokens.
|
||||
*/
|
||||
function token_pre_render_field_token(&$elements) {
|
||||
function token_pre_render_field_token($elements) {
|
||||
// Remove the field theme hook, attachments, and JavaScript states.
|
||||
unset($elements['#theme']);
|
||||
unset($elements['#states']);
|
||||
|
||||
Reference in New Issue
Block a user