Part of the Token ecosystem · 21 projects
This module allows you to use token replacements with custom aliases for data sources. It enables you to define aliases in your token strings and map them to specific entities, making token usage more flexible.
# Token Aliases
This modules allows it to use Token replacements, were the data is provided via $data argument, with aliases.
Motivation:
https://www.drupal.org/project/drupal/issues/1920688#comment-15137142
$token_service = \Drupal::service('token_aliases');
$string = 'Hello [user1:username], we have news from [user2:username] see [node:title] and [my_node:title] for more info.';
// Fully loaded Drupal entities which are keys with the aliases used in the string.
$data = [
'user1' => $user1,
'user2' => $user2,
'node' => $node,
'my_node' => $my_node,
];
$result = $token_service->plainReplace($string, $data);
Note: It uses a multi-pass approach to achieve that. Which means, it utilizes the original Token doReplace() method as much as possible, by converting aliases back to the original entity types almost one by one.
Ask your assistant about Token Aliases
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.
More in the Token ecosystem
Most installed first