public function MetatagManager::defaultTagsFromEntity in Metatag 8
Extracts all appropriate default tags for an entity.
From sitewide, per-entity-type, and per-bundle defaults.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The content entity for which to calculate defaults.
Return value
array Array of metatags.
Overrides MetatagManagerInterface::defaultTagsFromEntity
1 call to MetatagManager::defaultTagsFromEntity()
- MetatagManager::tagsFromEntityWithDefaults in src/
MetatagManager.php - Extracts all tags of a given entity.
File
- src/
MetatagManager.php, line 137
Class
- MetatagManager
- Class MetatagManager.
Namespace
Drupal\metatagCode
public function defaultTagsFromEntity(ContentEntityInterface $entity) {
/** @var \Drupal\metatag\Entity\MetatagDefaults $metatags */
$metatags = $this->metatagDefaults
->load('global');
if (!$metatags || !$metatags
->status()) {
return [];
}
// Add/overwrite with tags set on the entity type.
/** @var \Drupal\metatag\Entity\MetatagDefaults $entity_type_tags */
$entity_type_tags = $this->metatagDefaults
->load($entity
->getEntityTypeId());
if (!is_null($entity_type_tags) && $entity_type_tags
->status()) {
$metatags
->overwriteTags($entity_type_tags
->get('tags'));
}
// Add/overwrite with tags set on the entity bundle.
/** @var \Drupal\metatag\Entity\MetatagDefaults $bundle_metatags */
$bundle_metatags = $this->metatagDefaults
->load($entity
->getEntityTypeId() . '__' . $entity
->bundle());
if (!is_null($bundle_metatags) && $bundle_metatags
->status()) {
$metatags
->overwriteTags($bundle_metatags
->get('tags'));
}
return $metatags
->get('tags');
}