We have [node:source] now for content translation source handling, but don't have [term:source] for term and [term:vocabulary:source] for vocabulary translation source handling.

This patch clone the similar logic from the chained token relationships of node to term and vocabulary.

Comments

hswong3i created an issue. See original summary.

hswong3i’s picture

darrenwh’s picture

Status: Needs review » Needs work
  1. +++ b/token.tokens.inc
    @@ -558,6 +569,9 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
    +      $replacements += \Drupal::token()->generate('term', $parent_tokens, array('term' => $source_term), $options, $bubbleable_metadata);
    

    This line is long and could benefit from having the array's values on separate lines.

  2. +++ b/token.tokens.inc
    @@ -590,6 +604,11 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
    +      $replacements += \Drupal::token()->generate('vocabulary', $parent_tokens, array('vocabulary' => $source_vocabulary), $options, $bubbleable_metadata);
    

    Similar comment as above.

chipway’s picture

Status: Needs work » Needs review
FileSize
2.75 KB
1.47 KB

Thanks hswong3i and darrenwh. Here is a new patch.

darrenwh’s picture

+++ b/token.tokens.inc
@@ -169,6 +170,11 @@ function token_token_info() {
+      'description' => t("The source term for this current term's translation set."),

Very trivial but the speech marks in the translation blocks are not consistent (" or ')?

chipway’s picture

Thanks darrenwh,
Because we have term's with a ' inside the string.

Berdir’s picture

Status: Needs review » Needs work
  1. +++ b/token.tokens.inc
    @@ -169,6 +170,11 @@ function token_token_info() {
       if (\Drupal::moduleHandler()->moduleExists('taxonomy')) {
    +    $info['tokens']['term']['source'] = array(
    +      'name' => t('Translation source term'),
    +      'description' => t("The source term for this current term's translation set."),
    +      'type' => 'term',
    +    );
         $info['tokens']['term']['edit-url'] = array(
           'name' => t('Edit URL'),
    

    Drupal 8 doesn't have translation sets, it has entity translation.

  2. +++ b/token.tokens.inc
    @@ -590,6 +606,13 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
    +
    +    // Chained token relationships.
    +    if (($parent_tokens = \Drupal::token()->findWithPrefix($tokens, 'source')) && $source_vocabulary = \Drupal::service('entity.repository')->getTranslationFromContext($vocabulary, LanguageInterface::LANGCODE_DEFAULT)) {
    +      $replacements += \Drupal::token()->generate('vocabulary', $parent_tokens, array(
    +        'vocabulary' => $source_vocabulary),
    +        $options, $bubbleable_metadata);
    

    And config entities don't have entity translations, not like that. Shouldn't be exposed for vocabularies.

    This feels like a duplicate of another issue.

gaurav.kapoor’s picture

Status: Needs work » Needs review
FileSize
1017 bytes
3.1 KB

Minor fixes.