You are here

public function BlazyEntityMediaBase::getScopedFormElements in Blazy 8.2

Defines the scope for the form elements.

Overrides BlazyEntityBase::getScopedFormElements

2 calls to BlazyEntityMediaBase::getScopedFormElements()
BlazyEntityReferenceBase::getScopedFormElements in src/Dejavu/BlazyEntityReferenceBase.php
Defines the scope for the form elements.
BlazyMediaFormatter::getScopedFormElements in src/Plugin/Field/FieldFormatter/BlazyMediaFormatter.php
Defines the scope for the form elements.
2 methods override BlazyEntityMediaBase::getScopedFormElements()
BlazyEntityReferenceBase::getScopedFormElements in src/Dejavu/BlazyEntityReferenceBase.php
Defines the scope for the form elements.
BlazyMediaFormatter::getScopedFormElements in src/Plugin/Field/FieldFormatter/BlazyMediaFormatter.php
Defines the scope for the form elements.

File

src/Dejavu/BlazyEntityMediaBase.php, line 200

Class

BlazyEntityMediaBase
Base class for Media entity reference formatters with field details.

Namespace

Drupal\blazy\Dejavu

Code

public function getScopedFormElements() {
  $target_type = $this
    ->getFieldSetting('target_type');
  $views_ui = $this
    ->getFieldSetting('handler') == 'default';
  $bundles = $views_ui ? [] : $this
    ->getFieldSetting('handler_settings')['target_bundles'];
  $captions = $this
    ->admin()
    ->getFieldOptions($bundles, [], $target_type);
  $images = [];
  if ($bundles) {

    // @todo figure out to not hard-code stock bundle image.
    if (in_array('image', $bundles)) {
      $captions['title'] = $this
        ->t('Image Title');
      $captions['alt'] = $this
        ->t('Image Alt');
    }

    // Only provides poster if media contains rich media.
    $media = [
      'audio',
      'remote_video',
      'video',
      'instagram',
      'soundcloud',
    ];
    if (count(array_intersect($bundles, $media)) > 0) {
      $images['images'] = $this
        ->admin()
        ->getFieldOptions($bundles, [
        'image',
      ], $target_type);
    }
  }

  // @todo better way than hard-coding field name.
  unset($captions['field_image'], $captions['field_media_image']);
  return [
    'background' => TRUE,
    'box_captions' => TRUE,
    'captions' => $captions,
    'fieldable_form' => TRUE,
    'image_style_form' => TRUE,
    'media_switch_form' => TRUE,
    'multimedia' => TRUE,
  ] + parent::getScopedFormElements() + $images;
}