function EntityReference::validateExtraOptionsForm

Same name and namespace in other branches
  1. main core/modules/views/src/Plugin/views/filter/EntityReference.php \Drupal\views\Plugin\views\filter\EntityReference::validateExtraOptionsForm()

Validate the options form.

Parameters

array $form: Associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides HandlerBase::validateExtraOptionsForm

File

core/modules/views/src/Plugin/views/filter/EntityReference.php, line 312

Class

EntityReference
Filters a view by entity references.

Namespace

Drupal\views\Plugin\views\filter

Code

public function validateExtraOptionsForm($form, FormStateInterface $form_state) : void {
  $options = $form_state->getValue('options');
  $sub_handler = $options['sub_handler'];
  $subform = $form[static::SUBFORM_PREFIX . $sub_handler];
  $subform_state = SubformState::createForSubform($subform, $form, $form_state);
  // Copy handler_settings from options to settings to be compatible with
  // selection plugins.
  $subform_options = $form_state->getValue([
    'options',
    static::SUBFORM_PREFIX . $sub_handler,
  ]);
  $subform_state->setValue([
    'settings',
  ], $subform_options);
  $this->getSelectionHandler($sub_handler)
    ->validateConfigurationForm($subform, $subform_state);
  // Store the sub handler options in sub_handler_settings.
  $form_state->setValue([
    'options',
    'sub_handler_settings',
  ], $subform_options);
  // Remove options that are not from the selected sub_handler.
  foreach (array_keys($this->getSubHandlerOptions()) as $sub_handler_option) {
    if (isset($options[static::SUBFORM_PREFIX . $sub_handler_option])) {
      $form_state->unsetValue([
        'options',
        static::SUBFORM_PREFIX . $sub_handler_option,
      ]);
    }
  }
  parent::validateExtraOptionsForm($form, $form_state);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.