You are here

public function MetatagManager::getDefaultMetatags in Metatag 8

Returns default meta tags for an entity.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to work on.

Return value

array The default meta tags appropriate for this entity.

File

src/MetatagManager.php, line 378

Class

MetatagManager
Class MetatagManager.

Namespace

Drupal\metatag

Code

public function getDefaultMetatags(ContentEntityInterface $entity = NULL) {

  // Get general global metatags.
  $metatags = $this
    ->getGlobalMetatags();

  // If that is empty something went wrong.
  if (!$metatags) {
    return;
  }

  // Check if this is a special page.
  $special_metatags = $this
    ->getSpecialMetatags();

  // Merge with all globals defaults.
  if ($special_metatags) {
    $metatags
      ->set('tags', array_merge($metatags
      ->get('tags'), $special_metatags
      ->get('tags')));
  }
  else {
    if (is_null($entity)) {
      $entity = metatag_get_route_entity();
    }
    if (!empty($entity)) {

      // Get default meta tags for a given entity.
      $entity_defaults = $this
        ->getEntityDefaultMetatags($entity);
      if ($entity_defaults != NULL) {
        $metatags
          ->set('tags', array_merge($metatags
          ->get('tags'), $entity_defaults));
      }
    }
  }
  return $metatags
    ->get('tags');
}