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

This module makes it cleaner and more convenient to create custom tokens by defining them as a service.

Requirements

This module requires the following modules to be installed:

  • Drupal core ^10 || ^11
  • Token

Installation

Usage

Create a class MyToken


namespace Drupal\my_module\Token;

use Drupal\taas\Token\TokenInterface;

class MyToken implements TokenInterface {

  public function getValue(array $data, array $options): MarkupInterface|string|null {
    return 'My token value'
  }
}

Define the token in your services.yml

  my_module.token.my_token:
    class: Drupal\my_module\Token\MyToken
    tags:
      - name: taas.token
        type: 'node'
        token: '[node:my-token]'
        title: 'My Token'

Now you can use the custom token as [node:my-token]

Support

This is a contrib module and as such, it's not officially supported by the
Drupal community. However, you can open an issue on the module's page on
drupal.org if you find any bugs or have any feature requests.

Project information

  • caution Minimally maintained
    Maintainers monitor issues, but fast responses are not guaranteed.
  • caution Maintenance fixes only
    Considered feature-complete by its maintainers.
  • Project categories: Developer tools
  • chart icon13 sites report using this module
  • Created by yoerioptr 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