You are here

public function CoreViewsFacetSourceBase::validateConfigurationForm in Core Views Facets 8

Form validation handler.

Parameters

array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Overrides FacetSourcePluginBase::validateConfigurationForm

File

src/Plugin/facets/facet_source/CoreViewsFacetSourceBase.php, line 190

Class

CoreViewsFacetSourceBase
Provide common functions for core Views based facet sources.

Namespace

Drupal\core_views_facets\Plugin\facets\facet_source

Code

public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  $facet_source_id = $this->facet
    ->getFacetSourceId();
  $triggering_element = $form_state
    ->getTriggeringElement();
  if (!empty($triggering_element['#name']) && $triggering_element['#name'] === 'facet_source_configure') {
    return;
  }
  $views_filters = $this
    ->getFields();
  $field_identifier = $form_state
    ->getValue('facet_source_configs')[$facet_source_id]['field_identifier'];
  if (empty($field_identifier) || empty($views_filters[$field_identifier])) {
    $form_state
      ->setErrorByName('facet_source_id', t('Please select a valid field.'));
  }
}