function LanguageAddForm::validatePredefined

Same name in other branches
  1. 8.9.x core/modules/language/src/Form/LanguageAddForm.php \Drupal\language\Form\LanguageAddForm::validatePredefined()
  2. 10 core/modules/language/src/Form/LanguageAddForm.php \Drupal\language\Form\LanguageAddForm::validatePredefined()
  3. 11.x core/modules/language/src/Form/LanguageAddForm.php \Drupal\language\Form\LanguageAddForm::validatePredefined()

Element specific validator for the Add language button.

File

core/modules/language/src/Form/LanguageAddForm.php, line 131

Class

LanguageAddForm
Controller for language addition forms.

Namespace

Drupal\language\Form

Code

public function validatePredefined($form, FormStateInterface $form_state) {
    $langcode = $form_state->getValue('predefined_langcode');
    if ($langcode == 'custom') {
        $form_state->setErrorByName('predefined_langcode', $this->t('Fill in the language details and save the language with <em>Add custom language</em>.'));
    }
    else {
        if ($language = $this->languageManager
            ->getLanguage($langcode)) {
            $form_state->setErrorByName('predefined_langcode', $this->t('The language %language (%langcode) already exists.', [
                '%language' => $language->getName(),
                '%langcode' => $langcode,
            ]));
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.