You are here

public function ViewportSettingsForm::validateForm in Viewport 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/ViewportSettingsForm.php, line 98

Class

ViewportSettingsForm
Class to configure viewport settings for this site.

Namespace

Drupal\viewport\Form

Code

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

  // Basic validation on viewport values to assure they're entered properly.
  foreach ($form_state
    ->getValues() as $key => $value) {

    // User_scalable is a checkbox, no need to check for commas.
    if (in_array($key, Element::children($form['viewport'])) && $key != 'user_scalable') {
      if (strstr($value, ',')) {
        $form_state
          ->setErrorByName($key, $this
          ->t('Commas are not allowed for the %field_name field.
            Please, ensure you are using dots (".") when entering decimal values,
            and avoid any commas after the values', array(
          '%field_name' => $form['viewport'][$key]['#title'],
        )));
      }
    }
  }
}