You are here

public function ShadowboxGlobalSettingsForm::validateForm in Shadowbox 8

Implements \Drupal\Core\Form\FormInterface::validateForm().

Overrides FormBase::validateForm

File

lib/Drupal/shadowbox/Form/ShadowboxGlobalSettingsForm.php, line 389
Contains \Drupal\shadowbox\Form\ShadowboxGlobalSettingsForm.

Class

ShadowboxGlobalSettingsForm
Configure the settings for Shadowbox.

Namespace

Drupal\shadowbox\Form

Code

public function validateForm(array &$form, array &$form_state) {
  parent::validateForm($form, $form_state);
  $color = $form_state['values']['shadowbox_overlay_color'];
  $opacity = $form_state['values']['shadowbox_overlay_opacity'];
  $slideshow_delay = $form_state['values']['shadowbox_slideshow_delay'];
  $resize_duration = $form_state['values']['shadowbox_resize_duration'];
  $fade_duration = $form_state['values']['shadowbox_fade_duration'];
  $viewport_padding = $form_state['values']['shadowbox_viewport_padding'];
  $initial_height = $form_state['values']['shadowbox_initial_height'];
  $initial_width = $form_state['values']['shadowbox_initial_width'];
  $counter_limit = $form_state['values']['shadowbox_counter_limit'];
  if (!is_numeric($resize_duration) || $resize_duration < 0 || $resize_duration > 10) {
    $this
      ->setFormError('shadowbox_resize_duration', $form_state, $this
      ->t('You must enter a number between 0 and 10.'));
  }
  if (!is_numeric($fade_duration) || $fade_duration < 0 || $fade_duration > 10) {
    $this
      ->setFormError('shadowbox_fade_duration', $form_state, $this
      ->t('You must enter a number between 0 and 10.'));
  }
  if (!is_numeric($initial_height)) {
    $this
      ->setFormError('shadowbox_initial_height', $form_state, $this
      ->t('You must enter a number.'));
  }
  else {
    $form_state['values']['shadowbox_initial_height'] = floor($initial_height);
  }
  if (!is_numeric($initial_width)) {
    $this
      ->setFormError('shadowbox_initial_width', $form_state, $this
      ->t('You must enter a number.'));
  }
  else {
    $form_state['values']['shadowbox_initial_width'] = floor($initial_width);
  }
  if (!$this
    ->validateHexColor($color)) {
    $this
      ->setFormError('shadowbox_overlay_color', $form_state, $this
      ->t('You must enter a properly formed hex value (e.g. 000 or 000000 for black.)'));
  }
  if ($opacity == '' || floor($opacity) != 0 && $opacity != 1) {
    $this
      ->setFormError('shadowbox_overlay_opacity', $form_state, $this
      ->t('You must enter a decimal number between 0 and 1.'));
  }
  if (!is_numeric($viewport_padding) || $viewport_padding < 0 || $viewport_padding > 200) {
    $this
      ->setFormError('shadowbox_viewport_padding', $form_state, $this
      ->t('You must enter a number between 0 and 200.'));
  }
  else {
    $form_state['values']['shadowbox_viewport_padding'] = (int) $viewport_padding;
  }
}