Commit 37b3fee2 authored by dabblela's avatar dabblela Committed by Sascha Grossenbacher
Browse files

Issue #2816693 by hswong3i, gaurav.kapoor, chipway, timcosgrove, herved,...

Issue #2816693 by hswong3i, gaurav.kapoor, chipway, timcosgrove, herved, nironan, abu-zakham, dabblela, Qusai Taha: Add [term:source] for source translation
parent bef22ecf
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -134,6 +134,10 @@ class TaxonomyTest extends KernelTestBase {
      'name' => 'german-parent-term',
    ])->save();

    // Check translation source tokens.
    $this->assertTokens('term', ['term' => $parent_term], ['source:name' => 'english-parent-term']);
    $this->assertTokens('term', ['term' => $parent_term], ['source:name' => 'english-parent-term'], ['langcode' => 'de']);

    // Create a term related to the parent term.
    $child_term = $this->addTerm($this->vocab, [
      'name' => 'english-child-term',
+10 −0
Original line number Diff line number Diff line
@@ -177,6 +177,11 @@ function token_token_info() {

  // Taxonomy term and vocabulary tokens.
  if (\Drupal::moduleHandler()->moduleExists('taxonomy')) {
    $info['tokens']['term']['source'] = [
      'name' => t('Translation source term'),
      'description' => t("The source term for this current term's translation set."),
      'type' => 'term',
    ];
    $info['tokens']['term']['edit-url'] = [
      'name' => t('Edit URL'),
      'description' => t("The URL of the taxonomy term's edit page."),
@@ -613,6 +618,11 @@ function token_tokens($type, array $tokens, array $data, array $options, Bubblea
    }

    // Chained token relationships.
    if (($parent_tokens = \Drupal::token()->findWithPrefix($tokens, 'source')) && $source_term = \Drupal::service('entity.repository')->getTranslationFromContext($term, LanguageInterface::LANGCODE_DEFAULT)) {
      $replacements += \Drupal::token()->generate('term', $parent_tokens, [
        'term' => $source_term,
      ], ['langcode' => $source_term->language()->getId()] + $options, $bubbleable_metadata);
    }
    if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
      $replacements += \Drupal::token()->generate('url', $url_tokens, ['url' => $term->toUrl()], $options, $bubbleable_metadata);
    }