function token_token_info in Token 8
Same name and namespace in other branches
- 7 token.tokens.inc \token_token_info()
Implements hook_token_info().
File
- ./
token.tokens.inc, line 134 - Token callbacks for the token module.
Code
function token_token_info() {
// Node tokens.
if (\Drupal::moduleHandler()
->moduleExists('node')) {
$info['tokens']['node']['source'] = [
'name' => t('Translation source node'),
'description' => t("The source node for this current node's translation set."),
'type' => 'node',
];
$info['tokens']['node']['log'] = [
'name' => t('Revision log message'),
'description' => t('The explanation of the most recent changes made to the node.'),
];
$info['tokens']['node']['content-type'] = [
'name' => t('Content type'),
'description' => t('The content type of the node.'),
'type' => 'content-type',
];
// Content type tokens.
$info['types']['content-type'] = [
'name' => t('Content types'),
'description' => t('Tokens related to content types.'),
'needs-data' => 'node_type',
];
$info['tokens']['content-type']['name'] = [
'name' => t('Name'),
'description' => t('The name of the content type.'),
];
$info['tokens']['content-type']['machine-name'] = [
'name' => t('Machine-readable name'),
'description' => t('The unique machine-readable name of the content type.'),
];
$info['tokens']['content-type']['description'] = [
'name' => t('Description'),
'description' => t('The optional description of the content type.'),
];
$info['tokens']['content-type']['node-count'] = [
'name' => t('Node count'),
'description' => t('The number of nodes belonging to the content type.'),
];
$info['tokens']['content-type']['edit-url'] = [
'name' => t('Edit URL'),
'description' => t("The URL of the content type's edit page."),
];
}
// Taxonomy term and vocabulary tokens.
if (\Drupal::moduleHandler()
->moduleExists('taxonomy')) {
$info['tokens']['term']['edit-url'] = [
'name' => t('Edit URL'),
'description' => t("The URL of the taxonomy term's edit page."),
];
$info['tokens']['term']['parents'] = [
'name' => t('Parents'),
'description' => t("An array of all the term's parents, starting with the root."),
'type' => 'array',
];
$info['tokens']['term']['root'] = [
'name' => t('Root term'),
'description' => t("The root term of the taxonomy term."),
'type' => 'term',
];
$info['tokens']['vocabulary']['machine-name'] = [
'name' => t('Machine-readable name'),
'description' => t('The unique machine-readable name of the vocabulary.'),
];
$info['tokens']['vocabulary']['edit-url'] = [
'name' => t('Edit URL'),
'description' => t("The URL of the vocabulary's edit page."),
];
}
// File tokens.
$info['tokens']['file']['basename'] = [
'name' => t('Base name'),
'description' => t('The base name of the file.'),
];
$info['tokens']['file']['extension'] = [
'name' => t('Extension'),
'description' => t('The extension of the file.'),
];
$info['tokens']['file']['size-raw'] = [
'name' => t('File byte size'),
'description' => t('The size of the file, in bytes.'),
];
// User tokens.
// Add information on the restricted user tokens.
$info['tokens']['user']['cancel-url'] = [
'name' => t('Account cancellation URL'),
'description' => t('The URL of the confirm delete page for the user account.'),
'restricted' => TRUE,
];
$info['tokens']['user']['one-time-login-url'] = [
'name' => t('One-time login URL'),
'description' => t('The URL of the one-time login page for the user account.'),
'restricted' => TRUE,
];
$info['tokens']['user']['roles'] = [
'name' => t('Roles'),
'description' => t('The user roles associated with the user account.'),
'type' => 'array',
];
// Current user tokens.
$info['tokens']['current-user']['ip-address'] = [
'name' => t('IP address'),
'description' => t('The IP address of the current user.'),
];
// Menu link tokens (work regardless if menu module is enabled or not).
$info['types']['menu-link'] = [
'name' => t('Menu links'),
'description' => t('Tokens related to menu links.'),
'needs-data' => 'menu-link',
];
$info['tokens']['menu-link']['mlid'] = [
'name' => t('Link ID'),
'description' => t('The unique ID of the menu link.'),
];
$info['tokens']['menu-link']['title'] = [
'name' => t('Title'),
'description' => t('The title of the menu link.'),
];
$info['tokens']['menu-link']['url'] = [
'name' => t('URL'),
'description' => t('The URL of the menu link.'),
'type' => 'url',
];
$info['tokens']['menu-link']['parent'] = [
'name' => t('Parent'),
'description' => t("The menu link's parent."),
'type' => 'menu-link',
];
$info['tokens']['menu-link']['parents'] = [
'name' => t('Parents'),
'description' => t("An array of all the menu link's parents, starting with the root."),
'type' => 'array',
];
$info['tokens']['menu-link']['root'] = [
'name' => t('Root'),
'description' => t("The menu link's root."),
'type' => 'menu-link',
];
// Language tokens.
$info['types']['language'] = [
'name' => t('Language'),
'description' => t('Tokens related to site language.'),
];
$info['tokens']['language']['name'] = [
'name' => t('Language name'),
'description' => t('The language name.'),
];
$info['tokens']['language']['langcode'] = [
'name' => t('Language code'),
'description' => t('The language code.'),
];
$info['tokens']['language']['direction'] = [
'name' => t('Direction'),
'description' => t('Whether the language is written left-to-right (ltr) or right-to-left (rtl).'),
];
$info['tokens']['language']['domain'] = [
'name' => t('Domain'),
'description' => t('The domain name to use for the language.'),
];
$info['tokens']['language']['prefix'] = [
'name' => t('Path prefix'),
'description' => t('Path prefix for URLs in the language.'),
];
// Current page tokens.
$info['types']['current-page'] = [
'name' => t('Current page'),
'description' => t('Tokens related to the current page request.'),
];
$info['tokens']['current-page']['title'] = [
'name' => t('Title'),
'description' => t('The title of the current page.'),
];
$info['tokens']['current-page']['url'] = [
'name' => t('URL'),
'description' => t('The URL of the current page.'),
'type' => 'url',
];
$info['tokens']['current-page']['page-number'] = [
'name' => t('Page number'),
'description' => t('The page number of the current page when viewing paged lists.'),
];
$info['tokens']['current-page']['query'] = [
'name' => t('Query string value'),
'description' => t('The value of a specific query string field of the current page.'),
'dynamic' => TRUE,
];
$info['tokens']['current-page']['interface-language'] = [
'name' => t('Interface language'),
'description' => t('The active user interface language.'),
'type' => 'language',
];
$info['tokens']['current-page']['content-language'] = [
'name' => t('Content language'),
'description' => t('The active content language.'),
'type' => 'language',
];
// URL tokens.
$info['types']['url'] = [
'name' => t('URL'),
'description' => t('Tokens related to URLs.'),
'needs-data' => 'path',
];
$info['tokens']['url']['path'] = [
'name' => t('Path'),
'description' => t('The path component of the URL.'),
];
$info['tokens']['url']['relative'] = [
'name' => t('Relative URL'),
'description' => t('The relative URL.'),
];
$info['tokens']['url']['absolute'] = [
'name' => t('Absolute URL'),
'description' => t('The absolute URL.'),
];
$info['tokens']['url']['brief'] = [
'name' => t('Brief URL'),
'description' => t('The URL without the protocol and trailing backslash.'),
];
$info['tokens']['url']['unaliased'] = [
'name' => t('Unaliased URL'),
'description' => t('The unaliased URL.'),
'type' => 'url',
];
$info['tokens']['url']['args'] = [
'name' => t('Arguments'),
'description' => t("The specific argument of the current page (e.g. 'arg:1' on the page 'node/1' returns '1')."),
'type' => 'array',
];
// Array tokens.
$info['types']['array'] = [
'name' => t('Array'),
'description' => t('Tokens related to arrays of strings.'),
'needs-data' => 'array',
'nested' => TRUE,
];
$info['tokens']['array']['first'] = [
'name' => t('First'),
'description' => t('The first element of the array.'),
];
$info['tokens']['array']['last'] = [
'name' => t('Last'),
'description' => t('The last element of the array.'),
];
$info['tokens']['array']['count'] = [
'name' => t('Count'),
'description' => t('The number of elements in the array.'),
];
$info['tokens']['array']['reversed'] = [
'name' => t('Reversed'),
'description' => t('The array reversed.'),
'type' => 'array',
];
$info['tokens']['array']['keys'] = [
'name' => t('Keys'),
'description' => t('The array of keys of the array.'),
'type' => 'array',
];
$info['tokens']['array']['join'] = [
'name' => t('Imploded'),
'description' => t('The values of the array joined together with a custom string in-between each value.'),
'dynamic' => TRUE,
];
$info['tokens']['array']['value'] = [
'name' => t('Value'),
'description' => t('The specific value of the array.'),
'dynamic' => TRUE,
];
// Random tokens.
$info['types']['random'] = [
'name' => t('Random'),
'description' => t('Tokens related to random data.'),
];
$info['tokens']['random']['number'] = [
'name' => t('Number'),
'description' => t('A random number from 0 to @max.', [
'@max' => mt_getrandmax(),
]),
];
$info['tokens']['random']['hash'] = [
'name' => t('Hash'),
'description' => t('A random hash. The possible hashing algorithms are: @hash-algos.', [
'@hash-algos' => implode(', ', hash_algos()),
]),
'dynamic' => TRUE,
];
// Define image_with_image_style token type.
if (\Drupal::moduleHandler()
->moduleExists('image')) {
$info['types']['image_with_image_style'] = [
'name' => t('Image with image style'),
'needs-data' => 'image_with_image_style',
'module' => 'token',
'nested' => TRUE,
];
// Provide tokens for the ImageStyle attributes.
$info['tokens']['image_with_image_style']['mimetype'] = [
'name' => t('MIME type'),
'description' => t('The MIME type (image/png, image/bmp, etc.) of the image.'),
];
$info['tokens']['image_with_image_style']['filesize'] = [
'name' => t('File size'),
'description' => t('The file size of the image.'),
];
$info['tokens']['image_with_image_style']['height'] = [
'name' => t('Height'),
'description' => t('The height the image, in pixels.'),
];
$info['tokens']['image_with_image_style']['width'] = [
'name' => t('Width'),
'description' => t('The width of the image, in pixels.'),
];
$info['tokens']['image_with_image_style']['uri'] = [
'name' => t('URI'),
'description' => t('The URI to the image.'),
];
$info['tokens']['image_with_image_style']['url'] = [
'name' => t('URL'),
'description' => t('The URL to the image.'),
];
}
return $info;
}