You are here

public function SlickForm::validateForm in Slick Carousel 8.2

Same name and namespace in other branches
  1. 8 slick_ui/src/Form/SlickForm.php \Drupal\slick_ui\Form\SlickForm::validateForm()

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

slick_ui/src/Form/SlickForm.php, line 949

Class

SlickForm
Extends base form for slick instance configuration form.

Namespace

Drupal\slick_ui\Form

Code

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

  // Update CSS Bezier version.
  $override = $form_state
    ->getValue([
    'options',
    'settings',
    'cssEaseOverride',
  ]);
  if ($override) {
    $override = $this
      ->getBezier($override);
  }

  // Update cssEaseBezier value based on cssEaseOverride.
  $form_state
    ->setValue([
    'options',
    'settings',
    'cssEaseBezier',
  ], $override);

  // Check if rows is set to 1 and show a warning.
  // See: https://www.drupal.org/project/slick/issues/3123787#comment-13532059
  if (isset($form['settings']['rows']['#value']) && $form['settings']['rows']['#value'] == 1) {
    $message = $this
      ->t('Hint: You set Slicks "rows" option to "1" (optionset: %optionset), this will result in markup issues on Slick versions >1.9.0. Consider to set it to "0" instead, or leave it as if not using >1.9.0. Check out <a href=":url">this issue</a> for further information.', [
      ':url' => 'https://www.drupal.org/project/slick/issues/3123787',
      '%optionset' => $form['name']['#value'],
    ]);
    $this
      ->messenger()
      ->addMessage($message, 'warning');
  }

  // Check if slidesPerRow is set to 0 and show a warning.
  // See: https://www.drupal.org/project/slick/issues/3123787#comment-13532059
  if (isset($form['settings']['slidesPerRow']['#value']) && $form['settings']['slidesPerRow']['#value'] == 0) {
    $message = $this
      ->t('Important: You set Slicks "slidesPerRow" option to "0" (optionset: %optionset), this will result in browser crashes >1.9.0. Consider to set it to "1" instead. Consider to set it to "0" instead, or leave it as if not using >1.9.0. Check out <a href=":url">this issue</a> for further information.', [
      ':url' => 'https://www.drupal.org/project/slick/issues/3123787',
      '%optionset' => $form['name']['#value'],
    ]);
    $this
      ->messenger()
      ->addMessage($message, 'warning');
  }
}