FilterFormatFormBase::validateForm

public FilterFormatFormBase::validateForm(array &$form, FormStateInterface $form_state)

Form validation handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormBase::validateForm

File

core/modules/filter/src/FilterFormatFormBase.php, line 201

Class

FilterFormatFormBase
Provides a base form for a filter format.

Namespace

Drupal\filter

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);

  // @todo Move trimming upstream.
  $format_format = trim($form_state->getValue('format'));
  $format_name = trim($form_state->getValue('name'));

  // Ensure that the values to be saved later are exactly the ones validated.
  $form_state->setValueForElement($form['format'], $format_format);
  $form_state->setValueForElement($form['name'], $format_name);

  $format_exists = $this->queryFactory
    ->get('filter_format')
    ->condition('format', $format_format, '<>')
    ->condition('name', $format_name)
    ->execute();
  if ($format_exists) {
    $form_state->setErrorByName('name', $this->t('Text format names must be unique. A format named %name already exists.', array('%name' => $format_name)));
  }
}
doc_Drupal
2016-10-29 09:14:43
Comments
Leave a Comment

Please login to continue.