You are here

public static function BackgroundImageFormTrait::appendCallback in Background Image 8

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

Appends 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.

File

src/BackgroundImageFormTrait.php, line 153

Class

BackgroundImageFormTrait
Trait BackgroundImageFormTrait.

Namespace

Drupal\background_image

Code

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