Entity Token Support
Last updated on
14 October 2016
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
Drupal 7
Integration with the Token module is achieved by enabling "Entity Token", which is a sub-module that ships with the Entity module (in Drupal 7).
Relies on Token module.
Drupal 7 Entity Token Example
$type = 'node';
$eid = 1;
$inc = module_load_include('inc', 'entity_token', 'entity_token.tokens');
// print well formatted debugging info - disable if you do not have "Devel" module enabled
//dpm($inc,'result of module_load_include');
$tokens = entity_token_types();
echo "<b>Tokens Types: </b>" . implode(', ', $tokens) . "<hr>";
//dpm(arg()," entity_load_single($type, $eid)");
if ($type and $eid) {
$e = entity_load_single($type, $eid);
//dpm($e," entity_load_single($type, $eid)");
$tokens = entity_token_types();
//dpm($tokens,'tokens after entity load');
$text = "Type: [$type:type] Name: [$type:title] User: [site:current-user:name]";
$replace = token_replace($text, array($type => $e));
echo $text . ' = ' . $replace;
}
Drupal 8
Drupal 8 Entity Token Example
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.