Loading core/modules/taxonomy/taxonomy.tokens.inc +25 −0 Changes for core/modules/taxonomy/taxonomy.tokens.inc: 25 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -5,6 +5,8 @@ * Builds placeholder replacement tokens for taxonomy terms and vocabularies. */ use Drupal\Core\Datetime\Entity\DateFormat; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Render\BubbleableMetadata; use Drupal\taxonomy\Entity\Vocabulary; Loading Loading @@ -78,6 +80,11 @@ function taxonomy_token_info() { 'description' => t("The parent term of the taxonomy term, if one exists."), 'type' => 'term', ]; $term['changed'] = [ 'name' => t("Date changed"), 'description' => t("The date the taxonomy was most recently updated."), 'type' => 'date', ]; return [ 'types' => $types, Loading @@ -94,6 +101,14 @@ function taxonomy_token_info() { function taxonomy_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) { $token_service = \Drupal::token(); if (isset($options['langcode'])) { $url_options['language'] = \Drupal::languageManager()->getLanguage($options['langcode']); $langcode = $options['langcode']; } else { $langcode = LanguageInterface::LANGCODE_DEFAULT; } $replacements = []; if ($type == 'term' && !empty($data['term'])) { $term = $data['term']; Loading Loading @@ -140,6 +155,12 @@ function taxonomy_tokens($type, $tokens, array $data, array $options, Bubbleable $replacements[$original] = $parent->getName(); } break; case 'changed': $date_format = DateFormat::load('medium'); $bubbleable_metadata->addCacheableDependency($date_format); $replacements[$original] = \Drupal::service('date.formatter')->format($term->getChangedTime(), 'medium', '', NULL, $langcode); break; } } Loading @@ -155,6 +176,10 @@ function taxonomy_tokens($type, $tokens, array $data, array $options, Bubbleable $replacements += $token_service->generate('term', $vocabulary_tokens, ['term' => $parent], $options, $bubbleable_metadata); } } if ($changed_tokens = $token_service->findWithPrefix($tokens, 'changed')) { $replacements += $token_service->generate('date', $changed_tokens, ['date' => $term->getChangedTime()], $options, $bubbleable_metadata); } } elseif ($type == 'vocabulary' && !empty($data['vocabulary'])) { Loading core/modules/taxonomy/tests/src/Kernel/TokenReplaceTest.php +6 −0 Changes for core/modules/taxonomy/tests/src/Kernel/TokenReplaceTest.php: 6 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -120,6 +120,9 @@ public function testTaxonomyTokenReplacement() { $tests['[term:url]'] = $term1->toUrl('canonical', ['absolute' => TRUE])->toString(); $tests['[term:node-count]'] = 0; $tests['[term:parent:name]'] = '[term:parent:name]'; /** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */ $date_formatter = $this->container->get('date.formatter'); $tests['[term:changed:since]'] = $date_formatter->formatTimeDiffSince($term1->getChangedTime(), ['langcode' => $language_interface->getId()]); $tests['[term:vocabulary:name]'] = $this->vocabulary->label(); $tests['[term:vocabulary]'] = $this->vocabulary->label(); Loading @@ -135,6 +138,8 @@ public function testTaxonomyTokenReplacement() { $bubbleable_metadata = clone $base_bubbleable_metadata; $metadata_tests['[term:vocabulary:name]'] = $bubbleable_metadata->addCacheTags($this->vocabulary->getCacheTags()); $metadata_tests['[term:vocabulary]'] = $bubbleable_metadata->addCacheTags($this->vocabulary->getCacheTags()); $bubbleable_metadata = clone $base_bubbleable_metadata; $metadata_tests['[term:changed:since]'] = $bubbleable_metadata->setCacheMaxAge(0); foreach ($tests as $input => $expected) { $bubbleable_metadata = new BubbleableMetadata(); Loading @@ -153,6 +158,7 @@ public function testTaxonomyTokenReplacement() { $tests['[term:parent:name]'] = $term1->getName(); $tests['[term:parent:url]'] = $term1->toUrl('canonical', ['absolute' => TRUE])->toString(); $tests['[term:parent:parent:name]'] = '[term:parent:parent:name]'; $tests['[term:changed:since]'] = $date_formatter->formatTimeDiffSince($term2->getChangedTime(), ['langcode' => $language_interface->getId()]); $tests['[term:vocabulary:name]'] = $this->vocabulary->label(); // Test to make sure that we generated something for each token. Loading Loading
core/modules/taxonomy/taxonomy.tokens.inc +25 −0 Changes for core/modules/taxonomy/taxonomy.tokens.inc: 25 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -5,6 +5,8 @@ * Builds placeholder replacement tokens for taxonomy terms and vocabularies. */ use Drupal\Core\Datetime\Entity\DateFormat; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Render\BubbleableMetadata; use Drupal\taxonomy\Entity\Vocabulary; Loading Loading @@ -78,6 +80,11 @@ function taxonomy_token_info() { 'description' => t("The parent term of the taxonomy term, if one exists."), 'type' => 'term', ]; $term['changed'] = [ 'name' => t("Date changed"), 'description' => t("The date the taxonomy was most recently updated."), 'type' => 'date', ]; return [ 'types' => $types, Loading @@ -94,6 +101,14 @@ function taxonomy_token_info() { function taxonomy_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) { $token_service = \Drupal::token(); if (isset($options['langcode'])) { $url_options['language'] = \Drupal::languageManager()->getLanguage($options['langcode']); $langcode = $options['langcode']; } else { $langcode = LanguageInterface::LANGCODE_DEFAULT; } $replacements = []; if ($type == 'term' && !empty($data['term'])) { $term = $data['term']; Loading Loading @@ -140,6 +155,12 @@ function taxonomy_tokens($type, $tokens, array $data, array $options, Bubbleable $replacements[$original] = $parent->getName(); } break; case 'changed': $date_format = DateFormat::load('medium'); $bubbleable_metadata->addCacheableDependency($date_format); $replacements[$original] = \Drupal::service('date.formatter')->format($term->getChangedTime(), 'medium', '', NULL, $langcode); break; } } Loading @@ -155,6 +176,10 @@ function taxonomy_tokens($type, $tokens, array $data, array $options, Bubbleable $replacements += $token_service->generate('term', $vocabulary_tokens, ['term' => $parent], $options, $bubbleable_metadata); } } if ($changed_tokens = $token_service->findWithPrefix($tokens, 'changed')) { $replacements += $token_service->generate('date', $changed_tokens, ['date' => $term->getChangedTime()], $options, $bubbleable_metadata); } } elseif ($type == 'vocabulary' && !empty($data['vocabulary'])) { Loading
core/modules/taxonomy/tests/src/Kernel/TokenReplaceTest.php +6 −0 Changes for core/modules/taxonomy/tests/src/Kernel/TokenReplaceTest.php: 6 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -120,6 +120,9 @@ public function testTaxonomyTokenReplacement() { $tests['[term:url]'] = $term1->toUrl('canonical', ['absolute' => TRUE])->toString(); $tests['[term:node-count]'] = 0; $tests['[term:parent:name]'] = '[term:parent:name]'; /** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */ $date_formatter = $this->container->get('date.formatter'); $tests['[term:changed:since]'] = $date_formatter->formatTimeDiffSince($term1->getChangedTime(), ['langcode' => $language_interface->getId()]); $tests['[term:vocabulary:name]'] = $this->vocabulary->label(); $tests['[term:vocabulary]'] = $this->vocabulary->label(); Loading @@ -135,6 +138,8 @@ public function testTaxonomyTokenReplacement() { $bubbleable_metadata = clone $base_bubbleable_metadata; $metadata_tests['[term:vocabulary:name]'] = $bubbleable_metadata->addCacheTags($this->vocabulary->getCacheTags()); $metadata_tests['[term:vocabulary]'] = $bubbleable_metadata->addCacheTags($this->vocabulary->getCacheTags()); $bubbleable_metadata = clone $base_bubbleable_metadata; $metadata_tests['[term:changed:since]'] = $bubbleable_metadata->setCacheMaxAge(0); foreach ($tests as $input => $expected) { $bubbleable_metadata = new BubbleableMetadata(); Loading @@ -153,6 +158,7 @@ public function testTaxonomyTokenReplacement() { $tests['[term:parent:name]'] = $term1->getName(); $tests['[term:parent:url]'] = $term1->toUrl('canonical', ['absolute' => TRUE])->toString(); $tests['[term:parent:parent:name]'] = '[term:parent:parent:name]'; $tests['[term:changed:since]'] = $date_formatter->formatTimeDiffSince($term2->getChangedTime(), ['langcode' => $language_interface->getId()]); $tests['[term:vocabulary:name]'] = $this->vocabulary->label(); // Test to make sure that we generated something for each token. Loading