You are here

public function AnimateAnyForm::validateForm in Animate Any 8

Validate for Animate Any Settings Form.

Overrides FormBase::validateForm

File

src/Form/AnimateAnyForm.php, line 140

Class

AnimateAnyForm
Provides the Animate Any form.

Namespace

Drupal\animate_any\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $op = (string) $form_state
    ->getValue('op');
  if ($op == $this
    ->t('Save Settings')) {
    $parent = $form_state
      ->getValue('parent_class');
    if (empty($parent)) {
      $form_state
        ->setRebuild();
      $form_state
        ->setErrorByName("parent_class", $this
        ->t("Please select parent class"));
    }
    foreach ($form_state
      ->getValue('animate_fieldset') as $key => $value) {
      if (empty($value['section_identity'])) {
        $form_state
          ->setRebuild();
        $form_state
          ->setErrorByName("animate_fieldset][{$key}][section_identity", $this
          ->t("Please select section identity for row @key", [
          '@key' => $key,
        ]));
      }
      if ($value['section_event'] == 'none') {
        $form_state
          ->setRebuild();
        $form_state
          ->setErrorByName("animate_fieldset][{$key}][section_event", $this
          ->t("Please select section event for row @key", [
          '@key' => $key,
        ]));
      }
      if ($value['section_animation'] == 'none') {
        $form_state
          ->setRebuild();
        $form_state
          ->setErrorByName("animate_fieldset][{$key}][section_animation", $this
          ->t("Please select section animation for row @key", [
          '@key' => $key,
        ]));
      }
    }
  }
}