You are here

public static function BackgroundImageFormTrait::attachValidationHandler in Background Image 8

Same name and namespace in other branches
  1. 2.x src/BackgroundImageFormTrait.php \Drupal\background_image\BackgroundImageFormTrait::attachValidationHandler()
  2. 2.0.x src/BackgroundImageFormTrait.php \Drupal\background_image\BackgroundImageFormTrait::attachValidationHandler()

Attaches a submit handler to the given form.

Parameters

callable $handler: The handler to attach.

array $form: The form.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

1 call to BackgroundImageFormTrait::attachValidationHandler()
BackgroundImageForm::build in src/Form/BackgroundImageForm.php
Builds the Background Image form.

File

src/BackgroundImageFormTrait.php, line 237

Class

BackgroundImageFormTrait
Trait BackgroundImageFormTrait.

Namespace

Drupal\background_image

Code

public static function attachValidationHandler(callable $handler, &$form, FormStateInterface $form_state) {
  if (!empty($form['#background_image_validate_handler'])) {
    return;
  }
  $form['#background_image_validate_handler'] = TRUE;
  if (!isset($form['#validate'])) {
    $form['#validate'] = [];
  }
  if (!in_array($handler, $form['#validate'])) {
    array_unshift($form['#validate'], $handler);
  }
}