diff -u b/token.tokens.inc b/token.tokens.inc --- b/token.tokens.inc +++ b/token.tokens.inc @@ -348,7 +348,7 @@ $info['tokens']['current-page'][$entity_type_id] = [ 'name' => t('The current %type', ['%type' => $entity_type->getLabel()]), - 'description' => t("The current page object if that's a %type", ['%type' => $entity_type_id]), + 'description' => t("The current page object if that's a %type", ['%type' => $entity_type->getLabel()]), 'type' => \Drupal::service('token.entity_mapper')->getTokenTypeForEntityType($entity_type_id), ]; } @@ -900,41 +900,41 @@ $entity_type = $parts[0]; if (!$entity_type_manager->hasDefinition($entity_type)) { break; - } + } - // Entity type is valid. Add url.path cache context. We need to - // do this regardless of whether or not the entity in question - // exists for the current page. - $bubbleable_metadata->addCacheContexts(['url.path']); + // Entity type is valid. Add url.path cache context. We need to + // do this regardless of whether or not the entity in question + // exists for the current page. + $bubbleable_metadata->addCacheContexts(['url.path']); - // Load entity if it exists. - $entity_id = \Drupal::routeMatch()->getRawParameter($entity_type); - if ($entity_id) { - $entity = $entity_type_manager->getStorage($entity_type)->load($entity_id); - } - if (!isset($entity)) { - break; - } + // Load entity if it exists. + $entity_id = \Drupal::routeMatch()->getRawParameter($entity_type); + if ($entity_id) { + $entity = $entity_type_manager->getStorage($entity_type)->load($entity_id); + } + if (!isset($entity)) { + break; + } - // No child properties, so load the entity label. - // For example [current-page:node]. - if ($name == $entity_type) { - $label = $entity->label(); - $replacements[$original] = $label; - $bubbleable_metadata->addCacheableDependency($entity); - } - // Load child properties via recursive tokens. - // For example [current-page:node:nid]. - else { - $entity_tokens = \Drupal::token()->findWithPrefix($tokens, $entity_type); - $token_type = \Drupal::service('token.entity_mapper')->getTokenTypeForEntityType($entity_type); - if (!empty($langcode) && $entity->hasTranslation($langcode)) { - $options['langcode'] = $langcode; + // No child properties, so load the entity label. + // For example [current-page:node]. + if ($name == $entity_type) { + $label = $entity->label(); + $replacements[$original] = $label; + $bubbleable_metadata->addCacheableDependency($entity); + } + // Load child properties via recursive tokens. + // For example [current-page:node:nid]. + else { + $entity_tokens = \Drupal::token()->findWithPrefix($tokens, $entity_type); + $token_type = \Drupal::service('token.entity_mapper')->getTokenTypeForEntityType($entity_type); + if (!empty($langcode) && $entity->hasTranslation($langcode)) { + $options['langcode'] = $langcode; + } + $replacements += \Drupal::token()->generate($token_type, $entity_tokens, [$token_type => $entity], $options, $bubbleable_metadata); } - $replacements += \Drupal::token()->generate($token_type, $entity_tokens, [$token_type => $entity], $options, $bubbleable_metadata); - } - break; + break; } // [current-page:interface-language:*] chained tokens. if ($language_interface_tokens = \Drupal::token()->findWithPrefix($tokens, 'interface-language')) {