public function LanguageAddForm::validateCustom in Drupal 8
Same name and namespace in other branches
- 9 core/modules/language/src/Form/LanguageAddForm.php \Drupal\language\Form\LanguageAddForm::validateCustom()
- 10 core/modules/language/src/Form/LanguageAddForm.php \Drupal\language\Form\LanguageAddForm::validateCustom()
Validates the language addition form on custom language button.
File
- core/
modules/ language/ src/ Form/ LanguageAddForm.php, line 113
Class
- LanguageAddForm
- Controller for language addition forms.
Namespace
Drupal\language\FormCode
public function validateCustom(array $form, FormStateInterface $form_state) {
if ($form_state
->getValue('predefined_langcode') == 'custom') {
$langcode = $form_state
->getValue('langcode');
// Reuse the editing form validation routine if we add a custom language.
$this
->validateCommon($form['custom_language'], $form_state);
if ($language = $this->languageManager
->getLanguage($langcode)) {
$form_state
->setErrorByName('langcode', $this
->t('The language %language (%langcode) already exists.', [
'%language' => $language
->getName(),
'%langcode' => $langcode,
]));
}
}
else {
$form_state
->setErrorByName('predefined_langcode', $this
->t('Use the <em>Add language</em> button to save a predefined language.'));
}
}