You are here

public function SynonymsEntity::buildExtraOptionsForm in Synonyms 8

Same name and namespace in other branches
  1. 2.0.x modules/synonyms_views_filter/src/Plugin/views/filter/SynonymsEntity.php \Drupal\synonyms_views_filter\Plugin\views\filter\SynonymsEntity::buildExtraOptionsForm()

Provide a form for setting options.

Overrides HandlerBase::buildExtraOptionsForm

File

synonyms_views_filter/src/Plugin/views/filter/SynonymsEntity.php, line 94

Class

SynonymsEntity
Filter entity by its name or one of its synonyms.

Namespace

Drupal\synonyms_views_filter\Plugin\views\filter

Code

public function buildExtraOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildExtraOptionsForm($form, $form_state);
  $form['widget'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Widget'),
    '#options' => [
      'autocomplete' => $this
        ->t('Autocomplete'),
      'select' => $this
        ->t('Select'),
    ],
    '#default_value' => $this->options['widget'],
    '#required' => TRUE,
    '#description' => $this
      ->t('Choose what widget to use in order to specify entity.'),
  ];
  if ($this->entityTypeManager
    ->getDefinition($this->definition['entity_type'])
    ->hasKey('bundle')) {
    $options = array_map(function ($item) {
      return $item['label'];
    }, $this->entityTypeBundleInfo
      ->getBundleInfo($this->definition['entity_type']));
    $form['target_bundles'] = [
      '#type' => 'checkboxes',
      '#title' => $this
        ->t('Bundles'),
      '#description' => $this
        ->t('Limit the possible values down to specific subset of bundles. Leave empty to have no filter by bundles.'),
      '#default_value' => $this->options['target_bundles'],
      '#options' => $options,
    ];
  }
}