You are here

protected function SynonymsEntity::valueForm 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::valueForm()

Options form subform for setting options.

This should be overridden by all child classes and it must define $form['value']

Overrides FilterPluginBase::valueForm

See also

buildOptionsForm()

File

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

Class

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

Namespace

Drupal\synonyms_views_filter\Plugin\views\filter

Code

protected function valueForm(&$form, FormStateInterface $form_state) {
  if (!empty($this->value)) {
    $default_value = $this
      ->getEntityStorage()
      ->loadMultiple($this->value);
  }
  else {
    $default_value = [];
  }
  switch ($this->options['widget']) {
    case 'autocomplete':
      $form['value'] = [
        '#type' => 'synonyms_entity_autocomplete',
        '#title' => $this
          ->t('Entity'),
        '#target_type' => $this->definition['entity_type'],
        '#target_bundles' => $this->options['target_bundles'],
        '#default_value' => $default_value,
      ];
      break;
    case 'select':
      $form['value'] = [
        '#type' => 'synonyms_entity_select',
        '#title' => $this
          ->t('Entity'),
        '#key_column' => 'target_id',
        '#target_type' => $this->definition['entity_type'],
        '#target_bundles' => $this->options['target_bundles'],
        '#default_value' => array_keys($default_value),
        '#multiple' => TRUE,
        '#empty_option' => '',
      ];
      break;
  }
}