You are here

protected function MetatagManager::getFieldTags in Metatag 8

Returns a list of the meta tags with values from a field.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The ContentEntityInterface object.

string $field_name: The name of the field to work on.

Return value

array Array of field tags.

1 call to MetatagManager::getFieldTags()
MetatagManager::tagsFromEntity in src/MetatagManager.php
Extracts all tags of a given entity.

File

src/MetatagManager.php, line 356

Class

MetatagManager
Class MetatagManager.

Namespace

Drupal\metatag

Code

protected function getFieldTags(ContentEntityInterface $entity, $field_name) {
  $tags = [];
  foreach ($entity->{$field_name} as $item) {

    // Get serialized value and break it into an array of tags with values.
    $serialized_value = $item
      ->get('value')
      ->getValue();
    if (!empty($serialized_value)) {
      $tags += unserialize($serialized_value);
    }
  }
  return $tags;
}