Commit c9419570 authored by Kingdutch's avatar Kingdutch Committed by Kingdutch

Issue #2941283 by Kingdutch, edurenye: Support context specific Metatags such...

Issue #2941283 by Kingdutch, edurenye: Support context specific Metatags such as [current-page:title]
parent 6497b555
......@@ -154,6 +154,8 @@ class EntityAnalyser {
];
\Drupal::service('module_handler')->alter('metatags', $metatags, $context);
$this->replaceContextAwareTokens($metatags, $entity);
// Resolve the metatags from tokens into actual values.
$data = $this->metatagManager->generateRawElements($metatags, $entity);
......@@ -260,6 +262,24 @@ class EntityAnalyser {
return $entity;
}
/**
* Replace context aware tokens in a metatags array.
*
* Replaces context aware tokens in a metatags with an entity specific
* version. This causes things like [current-page:title] to show the entity
* page title instead of the entity create/edit form title.
*
* @param array $metatags
* The metatags array that contains the tokens.
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to use as context
*/
protected function replaceContextAwareTokens(array &$metatags, EntityInterface $entity) {
foreach ($metatags as $tag => $value) {
$metatags[$tag] = str_replace('[current-page:title]', $entity->getTitle(), $value);
}
}
/**
* Returns an array of mappings from metatag to Yoast.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment