hook_token_info()
Provide information about available placeholder tokens and token types.
Tokens are placeholders that can be put into text by using the syntax [type:token], where type is the machine-readable name of a token type, and token is the machine-readable name of a token within this group. This hook provides a list of types and tokens to be displayed on text editing screens, so that people editing text can see what their token options are.
The actual token replacement is done by \Drupal\Core\Utility\Token::replace(), which invokes hook_tokens(). Your module will need to implement that hook in order to generate token replacements from the tokens defined here.
An associative array of available tokens and token types. The outer array has two components:
function hook_token_info() { $type = array( 'name' => t('Nodes'), 'description' => t('Tokens related to individual nodes.'), 'needs-data' => 'node', ); // Core tokens for nodes. $node['nid'] = array( 'name' => t("Node ID"), 'description' => t("The unique ID of the node."), ); $node['title'] = array( 'name' => t("Title"), ); $node['edit-url'] = array( 'name' => t("Edit URL"), 'description' => t("The URL of the node's edit page."), ); // Chained tokens for nodes. $node['created'] = array( 'name' => t("Date created"), 'type' => 'date', ); $node['author'] = array( 'name' => t("Author"), 'type' => 'user', ); return array( 'types' => array('node' => $type), 'tokens' => array('node' => $node), ); }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Utility!token.api.php/function/hook_token_info/8.1.x