public function LanguageAddForm::validateCustom in Zircon Profile 8
Same name and namespace in other branches
- 8.0 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 115 - Contains \Drupal\language\Form\LanguageAddForm.
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.', array(
'%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.'));
}
}