You are here

public static function BackgroundImageFormTrait::prependCallback in Background Image 8

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

Prepends a callback to an element.

Parameters

$element: A render array element, passed by reference.

$property: The property name of $element that should be used.

callable $handler: A callback handler that should be executed for $property.

mixed $default: The default value to use if no existing $property exists. This defaults to retrieving the element info default value first and falling back to this default value as the absolute last resort.

1 call to BackgroundImageFormTrait::prependCallback()
BackgroundImageFormTrait::addState in src/BackgroundImageFormTrait.php
Provides a way to add #states to an element, but in a deferred way.

File

src/BackgroundImageFormTrait.php, line 546

Class

BackgroundImageFormTrait
Trait BackgroundImageFormTrait.

Namespace

Drupal\background_image

Code

public static function prependCallback(&$element, $property, callable $handler, $default = []) {
  $existing = isset($element[$property]) ? $element[$property] : self::getElementInfo($element, $property, $default);
  $element[$property] = array_merge([
    $handler,
  ], $existing);
}