- ๐บ๐ธUnited States smustgrave
Open thread in the MR.
Also why in the MR did you add phpstan-baseline update? Don't see that in the patch before.
- ๐ฎ๐ณIndia bhanu951
@smustgrave
Updated baseline due to this PHPStan error https://www.drupal.org/pift-ci-job/2558692 โ
Running PHPStan on *all* files. ------ ---------------------------------------------------------------------- Line core/lib/Drupal/Core/Utility/Token.php ------ ---------------------------------------------------------------------- Ignored error pattern #^Variable \$aliased_token_name might not be defined\.$# in path /var/www/html/core/lib/Drupal/Core/Utility/Token.php was not matched in reported errors. 269 Variable $alias_tokens_mapping might not be defined. ------ ----------------------------------------------------------------------
- ๐บ๐ธUnited States smustgrave
That seems like a valid warning that may need to be addressed vs ignored.
Would have to compare to previous patch though and see whatโs different in the MR.
- ๐จ๐ญSwitzerland berdir Switzerland
Agreed, new problems should not be ignored but fixed.
- ๐ฉ๐ชGermany ro-no-lo
Hi, for everyone coming to this issue after 10+ years, I have created a small Token extension module, were aliased tokens can be used in a programmatically way. It is a different approach, in syntax, but if you are desperate you might give it a try.
https://www.drupal.org/project/token_aliases โ
(You may have to use it from the git directly.)
Usage:
$token_service = \Drupal::service('token_aliases'); $string = 'Hello [user1:username], we have news from [user2:username] see [node:title] and [my_node:title] for more info.'; // Fully loaded User entities which are keys with the aliases used in the string. $data = [ 'user1' => $user1, 'user2' => $user2, 'node' => $node, 'my_node' => $my_node, ]; $result = $token_service->plainReplace($string, $data);
- last update
over 1 year ago Custom Commands Failed - last update
over 1 year ago Custom Commands Failed - last update
over 1 year ago 29,804 pass - last update
over 1 year ago 29,804 pass - ๐ง๐ชBelgium Grayle
There's a bug with the latest MR. The variables should be reset a loop deeper.
I do not have time to make a patch or MR, but the main block should look like this:
foreach ($text_token_aliases as $type => $text_token_alias) { foreach ($text_token_alias as $alias => $tokens) { // Reset the variables in this loop. $alias_tokens_mapping = []; $data_for_current_token = []; $unaliased_tokens = []; foreach ($tokens as $token => $unaliased_token_name) { $unaliased_tokens[$token] = "[{$unaliased_token_name}]"; $alias_tokens_mapping["[{$unaliased_token_name}]"] = "{$type}{{$alias}}:$token"; } // @todo Check if need to add else condition ? if (isset($data["{$type}{{$alias}}"])) { $data_for_current_token[$type] = $data["{$type}{{$alias}}"]; $replacements_unaliased = $this->generate($type, $unaliased_tokens, $data_for_current_token, $options, $bubbleable_metadata); foreach ($replacements_unaliased as $unaliased_token_name => $value) { $aliased_token_name = $alias_tokens_mapping[$unaliased_token_name]; $replacements["[{$aliased_token_name}]"] = $value; } } } }
Otherwise you get very weird issues. Easy way to test:
function test_token_reps() { $data = [ 'user{target}' => User::load(1), 'user{source}' => User::load(0), 'user{thirdy}' => User::load(6), ]; $text = " Target UID: [user{target}:uid] Target Name: [user{target}:name] Source Name: [user{source}:name] Thirdy UID: [user{thirdy}:uid] Source Name: [user{source}:name] Target Mail: [user{target}:mail] Thirdy Mail: [user{thirdy}:mail] "; $text = Drupal::token()->replace($text, $data); echo $text; }
The thing is that you can't use the same fields for all the aliases, gotta have some diffs. Then it goes haywire.
- ๐ช๐ธSpain unstatu
unstatu โ changed the visibility of the branch 1920688-support-multiple-instances to hidden.
- Status changed to Needs review
5 months ago 4:03pm 8 July 2024 - ๐ช๐ธSpain unstatu
I have created a new MR (https://git.drupalcode.org/project/drupal/-/merge_requests/8706) with the following changes:
- Changed the test to return different tokens depending on the passed entity so we don't rely on the onConsecutiveCalls() approach. IMO the new approach is more consistent.
- Reseted the $alias_tokens_mapping array on the inner loop as suggested in #82
- ๐ช๐ธSpain unstatu
Adding a patch with the latest status of https://git.drupalcode.org/project/drupal/-/merge_requests/8706
- Status changed to Needs work
5 months ago 4:28pm 8 July 2024 The Needs Review Queue Bot โ tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide โ to find step-by-step guides for working with issues.
- ๐บ๐ธUnited States smustgrave
Hiding patches from bot.
MR should be updated to 11.x also as current development branch.
- Status changed to Needs review
5 months ago 6:17pm 8 July 2024 - Status changed to Needs work
5 months ago 6:18pm 8 July 2024 - ๐ช๐ธSpain unstatu
I have changed the base branch from the issue. I'm going to change the base dev branch from the MR as well
- Merge request !87071920688 - Support multiple instances of the same token type in token replacement โ (Open) created by unstatu
- Status changed to Needs review
5 months ago 6:36pm 8 July 2024 - ๐ช๐ธSpain unstatu
Created a new MR based on 11.x and fixed the bot reported problems: https://git.drupalcode.org/project/drupal/-/merge_requests/8707
- ๐ช๐ธSpain unstatu
The pipeline finally passed. This patch matches the latest state of the MR https://git.drupalcode.org/project/drupal/-/merge_requests/8707 with the pipeline in green.
- Status changed to Needs work
4 months ago 10:54pm 9 August 2024 - ๐บ๐ธUnited States smustgrave
Ran the test-only feature https://git.drupalcode.org/issue/drupal-1920688/-/jobs/2066476 which shows the coverage.
Think instead of updating the baseline though should fix the error around alias_tokens_mapping, maybe setting a default like
$data_for_current_token = [];
$unaliased_tokens = [];