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
- Install the module as you would normally install a contributed Drupal module. Visit https://www.drupal.org/docs/8/extending-drupal-8/installing-contributed-... for further information.
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.
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.