You are here

public function PagererPresetEditForm::validateForm in Pagerer 8

Same name and namespace in other branches
  1. 8.2 src/Form/PagererPresetEditForm.php \Drupal\pagerer\Form\PagererPresetEditForm::validateForm()

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/Form/PagererPresetEditForm.php, line 138

Class

PagererPresetEditForm
Base form handler for Pagerer Presets.

Namespace

Drupal\pagerer\Form

Code

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

  // Check 'Config' was invoked without selecting a style.
  if (strpos($form_state
    ->getTriggeringElement()['#name'], 'config', 0) === 0) {
    $e = explode('_', $form_state
      ->getTriggeringElement()['#name']);
    $pane = $e[1];
    if ($form_state
      ->getValue([
      'panes_container',
      $pane,
      'style',
    ]) == 'none') {
      $form_state
        ->setErrorByName('panes_container][' . $pane . '][style', $this
        ->t("Select a style before clicking 'Configure'."));
    }
  }

  // Check 'Reset' was invoked without selecting a style.
  if (strpos($form_state
    ->getTriggeringElement()['#name'], 'reset', 0) === 0) {
    $e = explode('_', $form_state
      ->getTriggeringElement()['#name']);
    $pane = $e[1];
    if ($form_state
      ->getValue([
      'panes_container',
      $pane,
      'style',
    ]) == 'none') {
      $form_state
        ->setErrorByName('panes_container][' . $pane . '][style', $this
        ->t("Select a style before clicking 'Reset'."));
    }
  }
}