You are here

function _image_field_caption_get_image_field_names in Image Field Caption 8

Determines the image fields on an entity.

Parameters

\Drupal\Core\Entity\FieldableEntityInterface $entity: An entity whose fields to analyze.

Return value

array The names of the fields on this entity that support formatted text.

2 calls to _image_field_caption_get_image_field_names()
image_field_caption_entity_delete in ./image_field_caption.module
Implements hook_entity_delete().
image_field_caption_entity_update in ./image_field_caption.module
Implements hook_entity_update().

File

./image_field_caption.module, line 314
Provides a caption textarea for image fields.

Code

function _image_field_caption_get_image_field_names(FieldableEntityInterface $entity) {

  // Check if fields definitions are available.
  $field_definitions = $entity
    ->getFieldDefinitions();
  if (empty($field_definitions)) {
    return [];
  }

  // Only return image fields.
  return array_keys(array_filter($field_definitions, function (FieldDefinitionInterface $definition) {
    return in_array($definition
      ->getType(), [
      'image',
    ], TRUE);
  }));
}