function LanguageAddForm::validateCustom

Same name and namespace in other branches
  1. 9 core/modules/language/src/Form/LanguageAddForm.php \Drupal\language\Form\LanguageAddForm::validateCustom()
  2. 8.9.x core/modules/language/src/Form/LanguageAddForm.php \Drupal\language\Form\LanguageAddForm::validateCustom()
  3. 11.x 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\Form

Code

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.'));
  }
}

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