class Element (View source)

Provides helper methods for Drupal render elements.

Methods

static bool
property(string $key)

Checks if the key is a property.

static array
properties(array $element)

Gets properties of a structured array element (keys beginning with '#').

static bool
child(string $key)

Checks if the key is a child.

static array
children(array $elements, bool $sort = FALSE)

Identifies the children of an element array, optionally sorted by weight.

static array
getVisibleChildren(array $elements)

Returns the visible children of an element.

static bool
isVisibleElement(array $element)

Determines if an element is visible.

static 
setAttributes(array $element, array $map)

Sets HTML attributes based on element properties.

static bool
isEmpty(array $elements)

Indicates whether the given element is empty.

Details

static bool property(string $key)

Checks if the key is a property.

Parameters

string $key

The key to check.

Return Value

bool

TRUE of the key is a property, FALSE otherwise.

static array properties(array $element)

Gets properties of a structured array element (keys beginning with '#').

Parameters

array $element

An element array to return properties for.

Return Value

array

An array of property keys for the element.

static bool child(string $key)

Checks if the key is a child.

Parameters

string $key

The key to check.

Return Value

bool

TRUE if the element is a child, FALSE otherwise.

static array children(array $elements, bool $sort = FALSE)

Identifies the children of an element array, optionally sorted by weight.

The children of an element array are those key/value pairs whose key does not start with a '#'. See \Drupal\Core\Render\RendererInterface::render() for details.

Parameters

array $elements

The element array whose children are to be identified. Passed by reference.

bool $sort

Boolean to indicate whether the children should be sorted by weight.

Return Value

array

The array keys of the element's children.

static array getVisibleChildren(array $elements)

Returns the visible children of an element.

Parameters

array $elements

The parent element.

Return Value

array

The array keys of the element's visible children.

static bool isVisibleElement(array $element)

Determines if an element is visible.

Parameters

array $element

The element to check for visibility.

Return Value

bool

TRUE if the element is visible, otherwise FALSE.

static setAttributes(array $element, array $map)

Sets HTML attributes based on element properties.

Parameters

array $element

The renderable element to process. Passed by reference.

array $map

An associative array whose keys are element property names and whose values are the HTML attribute names to set on the corresponding property; e.g., array('#property_name' => 'attribute_name'). If both names are identical except for the leading '#', then an attribute name value is sufficient and no property name needs to be specified.

static bool isEmpty(array $elements)

Indicates whether the given element is empty.

An element that only has #cache set is considered empty, because it will render to the empty string.

Parameters

array $elements

The element.

Return Value

bool

Whether the given element is empty.