You are here

public function FeedTypeForm::validateForm in Feeds 8.3

Form validation handler.

Parameters

array $form: An associative array containing the structure of the form.

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

Overrides FormBase::validateForm

File

src/FeedTypeForm.php, line 300

Class

FeedTypeForm
Form controller for the feed type edit forms.

Namespace

Drupal\feeds

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  if ($form_state
    ->getErrors()) {
    return;
  }
  $values =& $form_state
    ->getValues();

  // Moved advanced settings to regular settings.
  foreach (array_keys($this->entity
    ->getPlugins()) as $type) {
    if (isset($values[$type . '_wrapper']['advanced'])) {
      if (!isset($values[$type . '_configuration'])) {
        $values[$type . '_configuration'] = [];
      }
      $values[$type . '_configuration'] += $values[$type . '_wrapper']['advanced'];
    }
    unset($values[$type . '_wrapper']);
  }
  foreach ($this
    ->getPluginForms() as $type => $plugin) {
    if (!isset($form[$type . '_configuration'])) {

      // When switching from a non-configurable plugin to a configurable
      // plugin, no form is yet available. So skip validating it to avoid
      // fatal errors.
      continue;
    }
    $plugin_state = $this
      ->createSubFormState($type . '_configuration', $form_state);
    $plugin
      ->validateConfigurationForm($form[$type . '_configuration'], $plugin_state);
    $form_state
      ->setValue($type . '_configuration', $plugin_state
      ->getValues());
    $this
      ->moveFormStateErrors($plugin_state, $form_state);
  }

  // Build the feed type object from the submitted values.
  parent::validateForm($form, $form_state);
}