function LanguageFormBase::validateCommon

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

Validates the language editing element.

1 call to LanguageFormBase::validateCommon()
LanguageAddForm::validateCustom in core/modules/language/src/Form/LanguageAddForm.php
Validates the language addition form on custom language button.

File

core/modules/language/src/Form/LanguageFormBase.php, line 96

Class

LanguageFormBase
Base form for language add and edit forms.

Namespace

Drupal\language\Form

Code

public function validateCommon(array $form, FormStateInterface $form_state) {
    // Ensure sane field values for langcode and name.
    if (!isset($form['langcode_view']) && !preg_match('@^' . LanguageInterface::VALID_LANGCODE_REGEX . '$@', $form_state->getValue('langcode'))) {
        $form_state->setErrorByName('langcode', $this->t('%field must be a valid language tag as <a href=":url">defined by the W3C</a>.', [
            '%field' => $form['langcode']['#title'],
            ':url' => 'http://www.w3.org/International/articles/language-tags/',
        ]));
    }
    if ($form_state->getValue('label') != Html::escape($form_state->getValue('label'))) {
        $form_state->setErrorByName('label', $this->t('%field cannot contain any markup.', [
            '%field' => $form['label']['#title'],
        ]));
    }
}

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