Same name and namespace in other branches
  1. 8.x-2.x src/Plugin/Field/FieldWidget/ExifWidgetBase.php \Drupal\exif\Plugin\Field\FieldWidget\ExifWidgetBase::retrieveImageFieldFromBundle() 1 comment

Retrieve list of image field labels by key of image field.

Parameters

string $entity_type: Entity Type name.

string $bundle_name: Name bundle.

Return value

array Map of all images fields contained in this bundle by key and description.

1 call to ExifWidgetBase::retrieveImageFieldFromBundle()
ExifWidgetBase::settingsForm in src/Plugin/Field/FieldWidget/ExifWidgetBase.php

File

src/Plugin/Field/FieldWidget/ExifWidgetBase.php, line 133

Class

ExifWidgetBase
Base class for 'Exif Field widget' plugin implementations.

Namespace

Drupal\exif\Plugin\Field\FieldWidget

Code

protected function retrieveImageFieldFromBundle($entity_type, $bundle_name) {
    $fields_of_bundle = Drupal::getContainer()->get('entity_field.manager')
        ->getFieldDefinitions($entity_type, $bundle_name);
    $result = [];
    foreach ($fields_of_bundle as $key => $value) {
        if ($value instanceof FieldConfig) {
            if (in_array($value->getType(), [
                'image',
                'media',
                'file',
            ])) {
                $result[$key] = $value->getLabel() . " (" . $key . ")";
            }
        }
    }
    return $result;
}