Same name in other branches
  1. 8.x-3.x src/Form/QuickTabsInstanceEditForm.php \Drupal\quicktabs\Form\QuickTabsInstanceEditForm::validate()

File

src/Form/QuickTabsInstanceEditForm.php, line 263

Class

QuickTabsInstanceEditForm
Class QuickTabsInstanceEditForm.

Namespace

Drupal\quicktabs\Form

Code

public function validate(array $form, FormStateInterface $form_state) {
    $id = $form_state->getValue('id');
    if (empty($id)) {
        $form_state->setErrorByName('machine_name', $this->t('The quicktabs machine name is required.'));
    }
    elseif (!preg_match('!^[a-z0-9_]+$!', $id)) {
        $form_state->setErrorByName('machine_name', $this->t('The quicktabs machine name must contain only lowercase letters, numbers, and underscores.'));
    }
    $tabs = $form_state->getValue('tabs');
    if (!isset($tabs)) {
        $form_state->setErrorByName('', $this->t('At least one tab should be created.'));
    }
    else {
        foreach ($tabs as $j => $tab) {
            if (empty($tab['title'])) {
                $form_state->setErrorByName('tabs][' . $j . '][title', $this->t('Title is required for each tab.'));
            }
        }
    }
}