You are here

public function BynderSearch::getForm in Bynder 4.0.x

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

Overrides BynderWidgetBase::getForm

File

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

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 getForm(array &$original_form, FormStateInterface $form_state, array $additional_widget_parameters) {
  $form = parent::getForm($original_form, $form_state, $additional_widget_parameters);
  if ($form_state
    ->getValue('errors')) {
    $form['actions']['submit']['#access'] = FALSE;
    return $form;
  }
  $form['bynder_selection'] = [
    '#type' => 'hidden',
    '#weight' => -1,
  ];
  $form['#attached']['library'][] = 'bynder/search_view';
  $form['#attached']['drupalSettings']['bynder']['domain'] = $this->config
    ->get('bynder.settings')
    ->get('account_domain');
  $form['#attached']['drupalSettings']['bynder']['types'] = [];
  if ($this->configuration['media_type']) {
    $form['#attached']['drupalSettings']['bynder']['types'][] = 'image';
  }
  if ($this->configuration['media_type_document']) {
    $form['#attached']['drupalSettings']['bynder']['types'][] = 'document';
  }
  if ($this->configuration['media_type_video']) {
    $form['#attached']['drupalSettings']['bynder']['types'][] = 'video';
  }
  $form['actions']['submit']['#attributes']['class'][] = 'js-hide';
  $form['browser']['#markup'] = Markup::create('<div style="position: fixed; top: 44px; left: 0; right: 0; bottom: 0;" id="bynder-compactview"><div style="display: flex; height: 100%;"></div></div>');
  return $form;
}