protected function EntityAnalyser::replaceContextAwareTokens in Real-time SEO for Drupal 8.2
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.
Parameters
array $metatags: The metatags array that contains the tokens.
\Drupal\Core\Entity\EntityInterface $entity: The entity to use as context.
1 call to EntityAnalyser::replaceContextAwareTokens()
- EntityAnalyser::createEntityPreview in src/
EntityAnalyser.php - Takes an entity, renders it and adds the metatag values.
File
- src/
EntityAnalyser.php, line 159
Class
- EntityAnalyser
- Provides a preview renderer for entities.
Namespace
Drupal\yoast_seoCode
protected function replaceContextAwareTokens(array &$metatags, EntityInterface $entity) {
foreach ($metatags as $tag => $value) {
$metatags[$tag] = str_replace('[current-page:title]', $entity
->getTitle(), $value);
// URL metatags cause issues for new nodes as they don't have a URL yet.
if ($entity
->isNew() && substr($tag, -4) === '_url') {
$metatags[$tag] = '';
}
}
}