1 token.inc | token_get_token_problems() |
Retrieves the current list of all site tokens and checks for common problems.
Return value
array: An array with problems detected. Each item is keyed by a machine name for the error and includes:
- label: A description of the problem.
- problems: An array of the problematic tokens.
See also
File
- core/
includes/ token.inc, line 404 - Backdrop placeholder/token replacement system.
Code
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:'),
),
'missing-info' => array(
'label' => t('The following tokens or token types are missing required name and/or description information:'),
),
'type-no-tokens' => array(
'label' => t('The following token types do not have any tokens defined:'),
),
'tokens-no-type' => array(
'label' => t('The following token types are not defined but have tokens:'),
),
'duplicate' => array(
'label' => t('The following token or token types are defined by multiple modules:')
),
);
// Check token types for problems.
foreach ($token_info['types'] as $type => $type_info) {
$real_type = !empty($type_info['type']) ? $type_info['type'] : $type;
if (!is_array($type_info)) {
$token_problems['not-array']['problems'][] = "\$info['types']['$type']";
continue;
}
elseif (!isset($type_info['name']) || !isset($type_info['description'])) {
$token_problems['missing-info']['problems'][] = "\$info['types']['$type']";
}
elseif (empty($token_info['tokens'][$real_type])) {
$token_problems['type-no-tokens']['problems'][] = "\$info['tokens']['$real_type']";
}
}
// Check tokens for problems.
foreach ($token_info['tokens'] as $type => $tokens) {
if (!is_array($tokens)) {
$token_problems['not-array']['problems'][] = "\$info['tokens']['$type']";
continue;
}
else {
foreach (array_keys($tokens) as $token) {
if (!is_array($tokens[$token])) {
$token_problems['not-array']['problems'][] = "\$info['tokens']['$type']['$token']";
continue;
}
elseif (!isset($tokens[$token]['name']) || !isset($tokens[$token]['description'])) {
$token_problems['missing-info']['problems'][] = "\$info['tokens']['$type']['$token']";
}
elseif (is_array($tokens[$token]['name']) || is_array($tokens[$token]['description'])) {
$token_problems['duplicate']['problems'][] = "\$info['tokens']['$type']['$token']";
}
}
}
if (!isset($token_info['types'][$type])) {
$token_problems['tokens-no-type']['problems'][] = "\$info['types']['$type']";
}
}
return $token_problems;
}