Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Tokens as a Service

No security coverage Maintenance fixes only 10 sites

This module provides a simpler way to create custom tokens in Drupal by defining them as services. It allows you to easily integrate your custom token logic into Drupal's token system.

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.

Drupal 10–11 PHP >=8.0

Ask your assistant about Tokens as a Service

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

  • token Drupal core

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
3
Tracked since
Nov 2024
Latest release
2 weeks ago
Releases (12 mo)
1 ▼ from 2
Maintenance
Active

Release Timeline

Releases

Version Type Core PHP Release date
1.0.1 Stable 10–11 PHP >=8.0 Sep 23, 2026
1.0.0 Stable 10–11 Nov 16, 2024
1.0.x-dev Dev 10–11 Nov 16, 2024