TypedData Tokens
Provided by PlaceholderResolver service to parse and replace these tokens. Like core token service, except instead of core tokens like [node:title] we use Twig-like tokens with typed data variables enclosed within {{ and }}, e.g. {{node.title}} Note that unlike core tokens, which must be strings, we may use any typed data datatype inside these new tokens. Making data available is as simple as creating a typed data datatype and does not involve implementing hooks as core tokens do.
# PlaceholderResolver needed to parse tokens
typed_data.placeholder_resolver:
class: Drupal\typed_data\PlaceholderResolver
arguments: ['@typed_data.data_fetcher', '@plugin.manager.typed_data_filter']
As part of the PlaceholderResolver we have a new plugin type, TypedDataFilter, which may be used to transform a typed data value in a typed data token. For example, {{node.title|lower}} will be the lower case version of the node title. Or, as an example non-string typed data, {{account|entity_url}} will resolve to the canonical URL of the entity.
These TypedDataFilter plugins provide a powerful mechanism to manipulate the typed data values. The Twig syntax makes them consistent with Drupal front-end templates, which makes it easier for site builders to create Rules.
# Token filters
plugin.manager.typed_data_filter:
class: Drupal\typed_data\DataFilterManager
parent: default_plugin_manager
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion