What is the problem to solve?
I want to create this feature
✨
Allow to pass variables to aiprompt programatically
Active
and find tokens system old and difficult to work with (and documentation also very confusing scattered all over the place).
It could be modernized: tokens could be defined as plugins OOP based.
Providing tokens could be as simple as:
$children = [];
// [node:...]
$node_token1 = new NodeToken();
$token->setName('node');
$token->setData($node);
$children[] = node_token1;
// [another_node:...]
$node_token2 = new NodeToken();
$token->setName('another_node');
$token->setData($node2);
$children[] = $node_token2;
$tokens = [];
// tokens available as [custom:node:...] and [custom:another_node:...]
$custom_token = new CustomToken();
$custom_token->setName('custom');
$custom_token->setDescription('This is custom wrapper token');
$custom_token->setData($children);
$tokens[] = $custom_token;
$text = "This is [custom:node:title] and [custom:another_node:title]";
$token_service = \Drupal::service('token');
$build = [];
$build['tokens'] = [
'#theme' => 'token_tree_link',
'#tokens' => $tokens
];
$build['tokenized_text']['#markup'] = $token_service->replace($text, $tokens, $options);
Note: Because I want to generate tokens from user defined arguments, I don't know in advance what those tokens will be and want to generate tokens in place in a simple way like example above. And in my particular case:
[arguments:some_custom_named_entity_token:...]
Question: What it takes to achieve the same with current (which is still Drupal 7 remnant) system?
Who is this for?
Drupal module developers. And by extension, users, which will be using new modules which were simpler to develop.
New Drupal developers who would like to develop with more modern simpler API.
Result: what will be the outcome?
Example above looks easy, while at the same time, I don't know how do it with the old system. Old is probably very complex.
So outcome will be new API, easy to document, understand and work with.
It could probably be done as a module, and then later transferred to Drupal core.
How can we know the desired result is achieved
// TBD