Drupal is a registered trademark of Dries Buytaert
Release: Drupal 10.3.6 Update released for Drupal core (10.3.6)! Release: Drupal 11.0.5 Update released for Drupal core (11.0.5)! Release: Drupal 10.2.9 Update released for Drupal core (10.2.9)! Release: Drupal 10.2.10 Update released for Drupal core (10.2.10)! Release: Drupal 10.3.7 Update released for Drupal core (10.3.7)! Release: Drupal 11.0.6 Update released for Drupal core (11.0.6)! Release: Drupal 10.3.8 Update released for Drupal core (10.3.8)! Release: Drupal 11.0.7 Update released for Drupal core (11.0.7)! Module Revived: Translation Management Tool 8.x-1.19 Module tmgmt updated after 7 months of inactivity (8.x-1.19). Usage Milestone: Account field split Module account_field_split crossed 10,000 active installs.

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.

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
Nov 2024
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 2
Maintenance
Dormant

Releases

Version Type Core Release date
1.0.0 Stable Nov 16, 2024
1.0.x-dev Dev Nov 16, 2024