LanguageFormBase::validateCommon

public LanguageFormBase::validateCommon(array $form, FormStateInterface $form_state)

Validates the language editing element.

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('@^[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'])));
  }
}
doc_Drupal
2016-10-29 09:22:27
Comments
Leave a Comment

Please login to continue.