You are here

protected function MediaElementVideoFieldFormatter::getImageFieldOptions in MediaElement 8

Returns array of any image fields defined on the current entity type.

Return value

array The image fields as [field_name => Label].

1 call to MediaElementVideoFieldFormatter::getImageFieldOptions()
MediaElementVideoFieldFormatter::settingsForm in src/Plugin/Field/FieldFormatter/MediaElementVideoFieldFormatter.php
Returns a form to configure settings for the formatter.

File

src/Plugin/Field/FieldFormatter/MediaElementVideoFieldFormatter.php, line 145

Class

MediaElementVideoFieldFormatter
Plugin implementation of the 'mediaelement_file_video' formatter.

Namespace

Drupal\mediaelement\Plugin\Field\FieldFormatter

Code

protected function getImageFieldOptions() {

  // Set the option for no poster image.
  $options = [
    'none' => $this
      ->t('No Poster'),
  ];

  // Get all the image fields used on the site and filter for only ones used
  // on this entity type and bundle.
  $entity_id = $this->fieldDefinition
    ->getTargetEntityTypeId();
  $bundle = $this->fieldDefinition
    ->getTargetBundle();
  $image_fields = $this->entityFieldManager
    ->getFieldMapByFieldType('image');
  $entity_fields = $image_fields[$entity_id] ?? [];
  $bundle_fields = $this->entityFieldManager
    ->getFieldDefinitions($entity_id, $bundle);
  foreach ($entity_fields as $field_name => $field_info) {
    if (in_array($bundle, $field_info['bundles'])) {
      $options[$field_name] = $this
        ->t('@field_label (@field_name)', [
        '@field_label' => $bundle_fields[$field_name]
          ->getLabel(),
        '@field_name' => $field_name,
      ]);
    }
  }
  return $options;
}