You are here

public function ElevateZoomPlusForm::validateForm in ElevateZoom Plus 8

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

modules/ui/src/Form/ElevateZoomPlusForm.php, line 587

Class

ElevateZoomPlusForm
Extends base form for elevatezoomplus instance configuration form.

Namespace

Drupal\elevatezoomplus_ui\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);

  // Cleanups unused/ empty settings.
  $form_state
    ->unsetValue([
    'options',
    'options__active_tab',
  ]);
  $form_state
    ->unsetValue([
    'options',
    'settings',
    'respond',
    'actions',
  ]);
  $responds = $form_state
    ->getValue([
    'options',
    'settings',
    'respond',
  ]);
  $responds = $form_state
    ->hasValue([
    'options',
    'settings',
    'respond',
  ]) ? $responds : [];
  if ($responds) {
    foreach ($responds as $key => $respond) {
      if (empty($respond['range'])) {
        $form_state
          ->unsetValue([
          'options',
          'settings',
          'respond',
          $key,
        ]);
      }
    }
    $responds = $form_state
      ->getValue([
      'options',
      'settings',
      'respond',
    ]);
    if (count($responds) > 0) {
      $form_state
        ->setValue([
        'options',
        'settings',
        'responsive',
      ], 1);
    }
  }
}