You are here

function _image_replace_image_fields in Image Replace 8

Collect info for all image field instances on a given entity_type/bundle.

Parameters

string $entity_type: The entity type, e.g. node, for which the info shall be returned.

string $bundle: The bundle name for which to return instances.

Return value

array An associative array of instance arrays keyed by the field name.

2 calls to _image_replace_image_fields()
image_replace_entity_presave in ./image_replace.module
Implements hook_field_attach_presave().
image_replace_form_field_config_edit_form_alter in ./image_replace.module
Implements hook_form_FORM_ID_alter() for 'field_config_edit_form'.

File

./image_replace.module, line 173
Provides an image style effect replacing the whole image with another one.

Code

function _image_replace_image_fields($entity_type, $bundle) {
  $image_fields = [];
  $field_definitions = \Drupal::service('entity_field.manager')
    ->getFieldDefinitions($entity_type, $bundle);
  foreach ($field_definitions as $field_name => $field_definition) {
    if ($field_definition
      ->getType() == 'image') {
      $field_config = FieldConfig::loadByName($entity_type, $bundle, $field_name);
      if (isset($field_config)) {
        $image_fields[$field_name] = $field_config;
      }
    }
  }
  return $image_fields;
}