You are here

public function BynderSearch::buildConfigurationForm in Bynder 8.3

Same name and namespace in other branches
  1. 8 src/Plugin/EntityBrowser/Widget/BynderSearch.php \Drupal\bynder\Plugin\EntityBrowser\Widget\BynderSearch::buildConfigurationForm()
  2. 8.2 src/Plugin/EntityBrowser/Widget/BynderSearch.php \Drupal\bynder\Plugin\EntityBrowser\Widget\BynderSearch::buildConfigurationForm()
  3. 4.0.x src/Plugin/EntityBrowser/Widget/BynderSearch.php \Drupal\bynder\Plugin\EntityBrowser\Widget\BynderSearch::buildConfigurationForm()

Overrides BynderWidgetBase::buildConfigurationForm

File

src/Plugin/EntityBrowser/Widget/BynderSearch.php, line 37

Class

BynderSearch
Uses a Bynder API to search and provide entity listing in a browser's widget.

Namespace

Drupal\bynder\Plugin\EntityBrowser\Widget

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildConfigurationForm($form, $form_state);
  $form['submit_text']['#access'] = FALSE;
  foreach ($this->entityTypeManager
    ->getStorage('media_type')
    ->loadMultiple() as $type) {

    /** @var \Drupal\media\MediaTypeInterface $type */
    if ($type
      ->getSource() instanceof Bynder) {
      $form['media_type']['#options'][$type
        ->id()] = $type
        ->label();
    }
  }
  $form['media_type']['#title'] = $this
    ->t('Media type (Image)');
  if (empty($form['media_type']['#options'])) {
    $form['media_type']['#disabled'] = TRUE;
    $form['media_type']['#description'] = $this
      ->t('You must @create_type before using this widget.', [
      '@create_type' => Link::createFromRoute($this
        ->t('create a Bynder media type'), 'entity.media_type.add_form')
        ->toString(),
    ]);
  }
  else {
    $form['media_type']['#required'] = FALSE;
    $form['media_type']['#empty_option'] = $this
      ->t('- Hide images -');
    $form['media_type_document'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Media type (Document)'),
      '#default_value' => $this->configuration['media_type_document'],
      '#required' => FALSE,
      '#options' => $form['media_type']['#options'],
      '#empty_option' => $this
        ->t('- Hide documents -'),
    ];
  }
  return $form;
}