You are here

public static function BackgroundImageFormTrait::getElementInfo in Background Image 8

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

Retrieves default element info or a property from it.

Note: this is necessary because of the way Drupal's form and rendering process works. If you provide an element with a callback property, it does not merge with the default values. This allows us to merge custom property callbacks with the defaults.

Parameters

array $element: The render array element to retrieve info for. It must have a valid element with a #type property.

string $property: A specific property to retrieve from the element info.

mixed $default: The default value to use if the provided $property does not exist.

Return value

mixed If $property was provided, it will return the value of said property or the $default value if it does not exist. Otherwise, the entire element type's info array will be returned. If the type is not valid, an empty array will be returned.

2 calls to BackgroundImageFormTrait::getElementInfo()
BackgroundImageFormTrait::appendCallback in src/BackgroundImageFormTrait.php
Appends a callback to an element.
BackgroundImageFormTrait::prependCallback in src/BackgroundImageFormTrait.php
Prepends a callback to an element.

File

src/BackgroundImageFormTrait.php, line 361

Class

BackgroundImageFormTrait
Trait BackgroundImageFormTrait.

Namespace

Drupal\background_image

Code

public static function getElementInfo(array $element, $property = NULL, $default = []) {
  if (isset($element['#type'])) {
    return $property ? self::getElementInfoManager()
      ->getInfoProperty($element['#type'], $property, $default) : self::getElementInfoManager()
      ->getInfo($element['#type']);
  }
  return [];
}