You are here

public function LanguageAddForm::validatePredefined in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 133
Contains \Drupal\language\Form\LanguageAddForm.

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.', array(
        '%language' => $language
          ->getName(),
        '%langcode' => $langcode,
      )));
    }
  }
}