You are here

public function BackgroundMedia::buildConfigurationForm in Bootstrap Styles 1.0.x

Overrides StylePluginBase::buildConfigurationForm

File

src/Plugin/BootstrapStyles/Style/BackgroundMedia.php, line 84

Class

BackgroundMedia
Class BackgroundMedia.

Namespace

Drupal\bootstrap_styles\Plugin\BootstrapStyles\Style

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config();

  // Background image media bundle.
  $media_bundles = [];
  $media_bundles_info = $this->entityTypeBundleInfo
    ->getBundleInfo('media');

  // Ignore if match any of the following names.
  $disabled_bundles = [
    'audio',
    'audio_file',
    'instagram',
    'tweet',
    'document',
    'remote_video',
  ];
  foreach ($media_bundles_info as $key => $bundle) {
    if (!in_array($key, $disabled_bundles)) {
      $media_bundles[$key] = $bundle['label'] . ' (' . $key . ')';
    }
  }
  $form['background']['background_image_bundle'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Image background media bundle'),
    '#options' => $media_bundles,
    '#description' => $this
      ->t('Image background media entity bundle.'),
    '#default_value' => $config
      ->get('background_image.bundle'),
    '#ajax' => [
      'callback' => __CLASS__ . '::getFields',
      'event' => 'change',
      'method' => 'html',
      'wrapper' => 'media_image_bundle_fields',
      'progress' => [
        'type' => 'throbber',
        'message' => NULL,
      ],
    ],
  ];
  $form['background']['background_image_field'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Image background media field'),
    '#options' => $this
      ->getFieldsByBundle($config
      ->get('background_image.bundle')),
    '#description' => $this
      ->t('Image background media entity field.'),
    '#default_value' => $config
      ->get('background_image.field'),
    '#attributes' => [
      'id' => 'media_image_bundle_fields',
    ],
    '#validated' => TRUE,
  ];
  $form['background']['background_local_video_bundle'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Local video background media bundle'),
    '#options' => $media_bundles,
    '#description' => $this
      ->t('Background for local video media entity bundle.'),
    '#default_value' => $config
      ->get('background_local_video.bundle'),
    '#ajax' => [
      'callback' => __CLASS__ . '::getFields',
      'event' => 'change',
      'method' => 'html',
      'wrapper' => 'media_local_video_bundle_fields',
      'progress' => [
        'type' => 'throbber',
        'message' => NULL,
      ],
    ],
  ];
  $form['background']['background_local_video_field'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Local video background media field'),
    '#options' => $this
      ->getFieldsByBundle($config
      ->get('background_local_video.bundle')),
    '#description' => $this
      ->t('Local video background media entity field.'),
    '#default_value' => $config
      ->get('background_local_video.field'),
    '#attributes' => [
      'id' => 'media_local_video_bundle_fields',
    ],
    '#validated' => TRUE,
  ];
  return $form;
}