You are here

public function SwitchShortcutSet::validateForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/shortcut/src/Form/SwitchShortcutSet.php \Drupal\shortcut\Form\SwitchShortcutSet::validateForm()
  2. 10 core/modules/shortcut/src/Form/SwitchShortcutSet.php \Drupal\shortcut\Form\SwitchShortcutSet::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

core/modules/shortcut/src/Form/SwitchShortcutSet.php, line 160

Class

SwitchShortcutSet
Builds the shortcut set switch form.

Namespace

Drupal\shortcut\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  if ($form_state
    ->getValue('set') == 'new') {

    // Check to prevent creating a shortcut set with an empty title.
    if (trim($form_state
      ->getValue('label')) == '') {
      $form_state
        ->setErrorByName('label', $this
        ->t('The new set label is required.'));
    }
  }
}