Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Token Aliases

No security coverage Under active development 1 sites

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.

Drupal 8–10 · not 11

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.

Activity

Tracked releases
2
Tracked since
Jul 2023
Latest release
3 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core PHP Release date
1.0.0 Stable 8–10 Jul 5, 2023
1.0.x-dev Dev 8–10 Jul 5, 2023