This project is not covered by Drupal’s security advisory policy.

# 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.

Project information

  • caution Minimally maintained
    Maintainers monitor issues, but fast responses are not guaranteed.
  • Project categories: Developer tools
  • Ecosystem: Token
  • Created by ro-no-lo on , updated
  • shield alertThis project is not covered by the security advisory policy.
    Use at your own risk! It may have publicly disclosed vulnerabilities.

Releases