Tokens as a Service
No security coverage
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.
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.