You are here

public function View::buildConfigurationForm in Entity Browser 8

Same name in this branch
  1. 8 src/Plugin/EntityBrowser/Widget/View.php \Drupal\entity_browser\Plugin\EntityBrowser\Widget\View::buildConfigurationForm()
  2. 8 src/Plugin/EntityBrowser/SelectionDisplay/View.php \Drupal\entity_browser\Plugin\EntityBrowser\SelectionDisplay\View::buildConfigurationForm()
Same name and namespace in other branches
  1. 8.2 src/Plugin/EntityBrowser/Widget/View.php \Drupal\entity_browser\Plugin\EntityBrowser\Widget\View::buildConfigurationForm()

Implements PluginFormInterface::buildConfigurationForm().

Overrides WidgetBase::buildConfigurationForm

File

src/Plugin/EntityBrowser/Widget/View.php, line 253

Class

View
Uses a view to provide entity listing in a browser's widget.

Namespace

Drupal\entity_browser\Plugin\EntityBrowser\Widget

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildConfigurationForm($form, $form_state);
  $options = [];

  // Get only those enabled Views that have entity_browser displays.
  $displays = Views::getApplicableViews('entity_browser_display');
  foreach ($displays as $display) {
    list($view_id, $display_id) = $display;
    $view = $this->entityTypeManager
      ->getStorage('view')
      ->load($view_id);
    $options[$view_id . '.' . $display_id] = $this
      ->t('@view : @display', [
      '@view' => $view
        ->label(),
      '@display' => $view
        ->get('display')[$display_id]['display_title'],
    ]);
  }
  $form['view'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('View : View display'),
    '#default_value' => $this->configuration['view'] . '.' . $this->configuration['view_display'],
    '#options' => $options,
    '#empty_option' => $this
      ->t('- Select a view -'),
    '#required' => TRUE,
  ];
  return $form;
}