- ๐จ๐ฆCanada joseph.olstad
RTBC
We've been using this patch for years, the patch 21 is the best one yet and I approve! Fixes an issue that was present in a previous version of the patch. I recommend going forward with patch #21 asap.
- Status changed to Needs work
about 1 year ago 10:17am 21 October 2023 - ๐จ๐ญSwitzerland berdir Switzerland
+++ b/token.tokens.inc @@ -1227,6 +1227,9 @@ function book_tokens($type, $tokens, array $data, array $options, BubbleableMeta $child_node = Node::load($book['nid']); + if (!empty($options['langcode']) && $child_node->hasTranslation($options['langcode'])) { + $child_node = \Drupal::service('entity.repository')->getTranslationFromContext($child_node, $options['langcode']); + } @@ -1237,42 +1240,52 @@ function book_tokens($type, $tokens, array $data, array $options, BubbleableMeta + if (isset($book_node)) { + if (!empty($options['langcode']) && $book_node->hasTranslation($options['langcode'])) { + $book_node = \Drupal::service('entity.repository')->getTranslationFromContext($book_node, $options['langcode']); + } + foreach ($tokens as $name => $original) { + switch ($name) { ... + if (!empty($book['pid'])) { + $parent_node = Node::load($book['pid']); + if (!empty($options['langcode']) && $parent_node->hasTranslation($options['langcode'])) { + $parent_node = \Drupal::service('entity.repository')->getTranslationFromContext($parent_node, $options['langcode']); + }
As said in #18, these 3 case check the if the translation exists, which is different from whether there is a langcode.
I agree that the langcode options make sense, but not the hasTranslationCheck(), because there are use cases where language fallbacks are explicitly desired and this won't work with that.
I'm also a bit confused about the issue title and summary and the patch. The patch is solely about book tokens, but the issue title and description is at least partially about entity reference tokens. I'm fine with making this specifically about book tokens, there's at least one other issue about entity reference fields, but then at least the issue title should be updated to reflect that.
- ๐ซ๐ฎFinland heikkiy Oulu
We seem to be encountering a similar issue where we are using a taxonomy term token to generate a path for a content type.
This works fine when we save the node but if we bulk generate paths it seems to replace the term with the default language term. Bulk saving the content fixes the issue again.
But I agree with #23 that the issue title and summary and the patch seem to be doing a different thing. I am also a bit worried that #2648252: entity reference field token does not get translated โ is marked as being a duplicate of this issue and this issue patch seems to solve it only for a certain use case.
We can still test this patch and see if it fixes our issue.
- ๐ซ๐ฎFinland heikkiy Oulu
We found another similar issue which is not linked as a relationship here.
- ๐จ๐ฆCanada joseph.olstad
There's a few remaining nits to resolve with patch #21 as mentioned by @berdir.
- ๐ฎ๐ณIndia pradhumanjainOSL
pradhumanjain2311 โ made their first commit to this issueโs fork.
- Merge request !72Issue #2906445 by joseph.olstad, Rajab Natshah, ankithashetty, vidorado: Token... โ (Open) created by Unnamed author
- last update
7 months ago 78 pass