You are here

public function LanguageFormBase::validateCommon in Zircon Profile 8

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

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('@^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$@', $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>.', array(
      '%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.', array(
      '%field' => $form['label']['#title'],
    )));
  }
}