You are here

protected function MetatagManager::getFields in Metatag 8

Returns a list of the Metatag fields on an entity.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to examine.

Return value

array The fields from the entity which are Metatag fields.

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

File

src/MetatagManager.php, line 320

Class

MetatagManager
Class MetatagManager.

Namespace

Drupal\metatag

Code

protected function getFields(ContentEntityInterface $entity) {
  $field_list = [];
  if ($entity instanceof ContentEntityInterface) {

    // Get a list of the metatag field types.
    $field_types = $this
      ->fieldTypes();

    // Get a list of the field definitions on this entity.
    $definitions = $entity
      ->getFieldDefinitions();

    // Iterate through all the fields looking for ones in our list.
    foreach ($definitions as $field_name => $definition) {

      // Get the field type, ie: metatag.
      $field_type = $definition
        ->getType();

      // Check the field type against our list of fields.
      if (isset($field_type) && in_array($field_type, $field_types)) {
        $field_list[$field_name] = $definition;
      }
    }
  }
  return $field_list;
}