You are here

public function AddHierarchy::validateConfigurationForm in Search API 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 complete form.

Overrides PluginFormTrait::validateConfigurationForm

See also

\Drupal\Core\Plugin\PluginFormInterface::validateConfigurationForm()

File

src/Plugin/search_api/processor/AddHierarchy.php, line 247

Class

AddHierarchy
Adds all ancestors' IDs to a hierarchical field.

Namespace

Drupal\search_api\Plugin\search_api\processor

Code

public function validateConfigurationForm(array &$form, FormStateInterface $formState) {
  $fields = [];
  foreach ($formState
    ->getValue('fields', []) as $field_id => $values) {
    if (!empty($values['status'])) {
      if (empty($values['property'])) {
        $formState
          ->setError($form['fields'][$field_id]['property'], $this
          ->t('You need to select a nested property to use for the hierarchy data.'));
      }
      else {
        $fields[$field_id] = $values['property'];
      }
    }
  }
  $formState
    ->setValue('fields', $fields);
  if (!$fields) {
    $formState
      ->setError($form['fields'], $this
      ->t('You need to select at least one field for which to add hierarchy data.'));
  }
}