updated pathauto token
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,9 @@ core = 7.x
|
||||
files[] = token_test.module
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-02-06
|
||||
version = "7.x-1.4+6-dev"
|
||||
; Information added by Drupal.org packaging script on 2017-01-25
|
||||
version = "7.x-1.7"
|
||||
core = "7.x"
|
||||
project = "token"
|
||||
datestamp = "1360159412"
|
||||
datestamp = "1485316088"
|
||||
|
||||
|
13
sites/all/modules/token/tests/token_test.tokens.inc
Normal file
13
sites/all/modules/token/tests/token_test.tokens.inc
Normal file
@@ -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;
|
||||
}
|
@@ -3,9 +3,9 @@ description = Provides a user interface for the Token API and some missing core
|
||||
core = 7.x
|
||||
files[] = token.test
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-02-06
|
||||
version = "7.x-1.4+6-dev"
|
||||
; Information added by Drupal.org packaging script on 2017-01-25
|
||||
version = "7.x-1.7"
|
||||
core = "7.x"
|
||||
project = "token"
|
||||
datestamp = "1360159412"
|
||||
datestamp = "1485316088"
|
||||
|
||||
|
@@ -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']";
|
||||
}
|
||||
}
|
||||
|
@@ -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');
|
||||
}
|
||||
|
@@ -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.
|
||||
@@ -179,7 +180,7 @@ function token_theme() {
|
||||
'text' => NULL,
|
||||
'options' => array(),
|
||||
'dialog' => TRUE,
|
||||
),
|
||||
) + $info['token_tree']['variables'],
|
||||
'file' => 'token.pages.inc',
|
||||
);
|
||||
|
||||
@@ -265,15 +266,19 @@ 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());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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']));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,7 +394,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);
|
||||
@@ -411,12 +416,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'])) {
|
||||
@@ -646,6 +657,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);
|
||||
|
||||
@@ -708,15 +723,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);
|
||||
}
|
||||
|
||||
@@ -724,7 +737,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))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -742,7 +755,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;
|
||||
}
|
||||
|
||||
@@ -972,7 +985,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]
|
||||
|
@@ -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.
|
||||
@@ -57,7 +62,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();
|
||||
}
|
||||
@@ -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]',
|
||||
|
@@ -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