Skip to content
Snippets Groups Projects
Verified Commit 900ea3f6 authored by Dave Long's avatar Dave Long
Browse files

Issue #3161892 by Abhijith S, purushotam.rai, smustgrave: Taxonomy term...

Issue #3161892 by Abhijith S, purushotam.rai, smustgrave: Taxonomy term [term:changed] token not available
parent f50c6a35
No related branches found
No related tags found
26 merge requests!8528Issue #3456871 by Tim Bozeman: Support NULL services,!3878Removed unused condition head title for views,!38582585169-10.1.x,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #87185 canceled
......@@ -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;
......@@ -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,
......@@ -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'];
......@@ -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;
}
}
......@@ -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'])) {
......
......@@ -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();
......@@ -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();
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment