You are here

public function SettingsForm::validateForm in Floating block 8

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

src/Form/SettingsForm.php, line 49
Contains \Drupal\floating_block\Form\SettingsForm.

Class

SettingsForm
Defines a form that configures floating_block settings.

Namespace

Drupal\floating_block\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  $array = _floating_block_admin_convert_text_to_array($values['blocks']);
  $string = _floating_block_admin_convert_array_to_text($array);

  // Compare that floating block settings string to array conversion is
  // idempotent. New line characters \n and \r get make comparison difficult.
  if (str_replace(array(
    "\n",
    "\r",
  ), '', $string) != str_replace(array(
    "\n",
    "\r",
  ), '', $values['blocks'])) {
    $form_state
      ->setErrorByName('blocks', $this
      ->t('Each line must of the format: <code>selector|setting_key=setting_value,setting_key=setting_value,...</code>'));
  }
}