public function MetatagManager::getEntityDefaultMetatags in Metatag 8
Returns default meta tags for an entity.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to work with.
Return value
array The appropriate default meta tags.
1 call to MetatagManager::getEntityDefaultMetatags()
- MetatagManager::getDefaultMetatags in src/
MetatagManager.php - Returns default meta tags for an entity.
File
- src/
MetatagManager.php, line 460
Class
- MetatagManager
- Class MetatagManager.
Namespace
Drupal\metatagCode
public function getEntityDefaultMetatags(ContentEntityInterface $entity) {
/** @var \Drupal\metatag\Entity\MetatagDefaults $entity_metatags */
$entity_metatags = $this->metatagDefaults
->load($entity
->getEntityTypeId());
$metatags = [];
if ($entity_metatags != NULL && $entity_metatags
->status()) {
// Merge with global defaults.
$metatags = array_merge($metatags, $entity_metatags
->get('tags'));
}
// Finally, check if we should apply bundle overrides.
/** @var \Drupal\metatag\Entity\MetatagDefaults $bundle_metatags */
$bundle_metatags = $this->metatagDefaults
->load($entity
->getEntityTypeId() . '__' . $entity
->bundle());
if ($bundle_metatags != NULL && $bundle_metatags
->status()) {
// Merge with existing defaults.
$metatags = array_merge($metatags, $bundle_metatags
->get('tags'));
}
return $metatags;
}