You are here

public function SuperfishBlock::blockValidate in Superfish 8

Overrides \Drupal\block\BlockBase::blockValiate().

Overrides BlockPluginTrait::blockValidate

File

src/Plugin/Block/SuperfishBlock.php, line 765

Class

SuperfishBlock
Provides a "Superfish" block.

Namespace

Drupal\superfish\Plugin\Block

Code

public function blockValidate($form, FormStateInterface $form_state) {
  $touch = $form_state
    ->getValue([
    'sf-plugins',
    'sf-touchscreen',
    'sf-touchscreen-useragent',
    'superfish_touch',
  ]);
  $touchbp = $form_state
    ->getValue([
    'sf-plugins',
    'sf-touchscreen',
    'sf-touchscreen-windowwidth',
    'superfish_touchbp',
  ]);
  $touchua = $form_state
    ->getValue([
    'sf-plugins',
    'sf-touchscreen',
    'sf-touchscreen-useragent',
    'superfish_touchua',
  ]);
  $touchual = $form_state
    ->getValue([
    'sf-plugins',
    'sf-touchscreen',
    'sf-touchscreen-useragent',
    'superfish_touchual',
  ]);
  $small = $form_state
    ->getValue([
    'sf-plugins',
    'sf-smallscreen',
    'sf-smallscreen-useragent',
    'superfish_small',
  ]);
  $smallbp = $form_state
    ->getValue([
    'sf-plugins',
    'sf-smallscreen',
    'sf-smallscreen-windowwidth',
    'superfish_smallbp',
  ]);
  $smallua = $form_state
    ->getValue([
    'sf-plugins',
    'sf-smallscreen',
    'sf-smallscreen-useragent',
    'superfish_smallua',
  ]);
  $smallual = $form_state
    ->getValue([
    'sf-plugins',
    'sf-smallscreen',
    'sf-smallscreen-useragent',
    'superfish_smallual',
  ]);
  $minwidth = $form_state
    ->getValue([
    'sf-plugins',
    'sf-supersubs',
    'superfish_minwidth',
  ]);
  $maxwidth = $form_state
    ->getValue([
    'sf-plugins',
    'sf-supersubs',
    'superfish_maxwidth',
  ]);
  $speed = $form_state
    ->getValue([
    'sf-advanced',
    'sf-settings',
    'superfish_speed',
  ]);
  $delay = $form_state
    ->getValue([
    'sf-advanced',
    'sf-settings',
    'superfish_delay',
  ]);
  if (!is_numeric($speed) && !in_array($speed, [
    'slow',
    'normal',
    'fast',
  ])) {
    $form_state
      ->setErrorByName('superfish_speed', t('Unacceptable value entered for the "Animation speed" option.'));
  }
  if (!is_numeric($delay)) {
    $form_state
      ->setErrorByName('superfish_delay', t('Unacceptable value entered for the "Mouse delay" option.'));
  }
  if ($touch == 2 && $touchbp == '') {
    $form_state
      ->setErrorByName('superfish_touchbp', t('"sfTouchscreen Breakpoint" option cannot be empty.'));
  }
  if (!is_numeric($touchbp)) {
    $form_state
      ->setErrorByName('superfish_touchbp', t('Unacceptable value enterd for the "sfTouchscreen Breakpoint" option.'));
  }
  if ($touch == 3 && $touchua == 1 && $touchual == '') {
    $form_state
      ->setErrorByName('superfish_touchual', t('List of the touch-screen user agents cannot be empty.'));
  }
  if ($small == 2 && $smallbp == '') {
    $form_state
      ->setErrorByName('superfish_smallbp', t('"sfSmallscreen Breakpoint" option cannot be empty.'));
  }
  if (!is_numeric($smallbp)) {
    $form_state
      ->setErrorByName('superfish_smallbp', t('Unacceptable value entered for the "sfSmallscreen Breakpoint" option.'));
  }
  if ($small == 3 && $smallua == 1 && $smallual == '') {
    $form_state
      ->setErrorByName('superfish_smallual', t('List of the small-screen user agents cannot be empty.'));
  }
  $supersubs_error = FALSE;
  if (!is_numeric($minwidth)) {
    $form_state
      ->setErrorByName('superfish_minwidth', t('Unacceptable value entered for the "Supersubs minimum width" option.'));
    $supersubs_error = TRUE;
  }
  if (!is_numeric($maxwidth)) {
    $form_state
      ->setErrorByName('superfish_maxwidth', t('Unacceptable value entered for the "Supersubs maximum width" option.'));
    $supersubs_error = TRUE;
  }
  if ($supersubs_error !== TRUE && $minwidth > $maxwidth) {
    $form_state
      ->setErrorByName('superfish_maxwidth', t('Supersubs "maximum width" has to be bigger than the "minimum width".'));
  }
}