You are here

public function EntityReference::buildOptionsForm in Views Entity Reference Filter 8

Provide the basic form which calls through to subforms. If overridden, it is best to call through to the parent, or to at least make sure all of the functions in this form are called.

Overrides FilterPluginBase::buildOptionsForm

File

src/Plugin/views/filter/EntityReference.php, line 117

Class

EntityReference
Provides a Views filter for entity reference fields.

Namespace

Drupal\verf\Plugin\views\filter

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  if (!$this->targetEntityType
    ->hasKey('bundle')) {
    return $form;
  }
  $options = [];
  $bundleInfo = $this->entityTypeBundleInfo
    ->getBundleInfo($this->targetEntityType
    ->id());
  foreach ($bundleInfo as $id => $info) {
    $options[$id] = $info['label'];
  }
  $form['verf_target_bundles'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Target entity bundles to filter by'),
    '#options' => $options,
    '#default_value' => array_filter($this->options['verf_target_bundles']),
  ];
  return $form;
}