public function LanguageFormBase::validateCommon in Drupal 10
Same name and namespace in other branches
- 8 core/modules/language/src/Form/LanguageFormBase.php \Drupal\language\Form\LanguageFormBase::validateCommon()
- 9 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\FormCode
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'],
]));
}
}