Skip to content

Drupal\helper\RenderElement

Utility helpers for working with render elements.

Methods

Name Description
applyToChildren Apply a callback to the render element children.
attachDrupalSetting Attach a single drupalSettings key/value.
attachDrupalSettings Attach multiple drupalSettings.
attachFeed Attach a feed.
attachHeadLink Attach a head link.
attachHeader Attach a HTML header.
attachLibrary Attach a library to the render element.
attachStyle Attach an inline CSS style.
mergeAccess Change the access of a render element.
wrap Add a wrapper around a render element.

RenderElement::applyToChildren

Description

public static applyToChildren (array $element, callable $callback, mixed $args)

Apply a callback to the render element children.

Parameters

  • (array) $element : The render element.
  • (callable) $callback : The callback to apply.
  • (mixed) $args : The additional parameters to provide to the callback.

Return Values

void


RenderElement::attachDrupalSetting

Description

public static attachDrupalSetting (array $element, string $key, mixed $value)

Attach a single drupalSettings key/value.

Parameters

  • (array) $element : The render element.
  • (string) $key : The drupalSettings key.
  • (mixed) $value : The drupalSettings value.

Return Values

void


RenderElement::attachDrupalSettings

Description

public static attachDrupalSettings (array $element, array $settings)

Attach multiple drupalSettings.

Parameters

  • (array) $element : The render element.
  • (array) $settings : The drupalSettings key/value array.

Return Values

void


RenderElement::attachFeed

Description

public static attachFeed (array $element, string $href, string|null $title)

Attach a feed.

Parameters

  • (array) $element : The render element.
  • (string) $href : The feed href.
  • (string|null) $title : The feed title.

Return Values

void


Description

public static attachHeadLink (array $element, string $href, string $rel, array $attributes, bool $shouldAddHeader)

Attach a head link.

Parameters

  • (array) $element : The render element.
  • (string) $href : The link href.
  • (string) $rel : The link rel.
  • (array) $attributes : Optionally more link attributes.
  • (bool) $shouldAddHeader : A boolean specifying whether the link should also be a Link: HTTP header.

Return Values

void


RenderElement::attachHeader

Description

public static attachHeader (array $element, string $name, string $value, bool $replace)

Attach a HTML header.

Parameters

  • (array) $element : The render element.
  • (string) $name : The header name, 'status' is treated specially and used as http status
    code.
  • (string) $value : The header value.
  • (bool) $replace : (optional) Whether to replace a current value with the new one, or add
    it to the others. If the value is not replaced, it will be appended,
    resulting in a header like this: 'Header: value1,value2'.

Return Values

void


RenderElement::attachLibrary

Description

public static attachLibrary (array $element, string $library)

Attach a library to the render element.

Parameters

  • (array) $element : The render element.
  • (string) $library : The library, like 'your_module/library_name'.

Return Values

void


RenderElement::attachStyle

Description

public static attachStyle (array $element, string $style)

Attach an inline CSS style.

Parameters

  • (array) $element : The render element.
  • (string) $style : The inline CSS style value.

Return Values

void


RenderElement::mergeAccess

Description

public static mergeAccess (array $element, bool|\Drupal\Core\Access\AccessResultInterface $access, bool $and)

Change the access of a render element.

Parameters

  • (array) $element : The render element.
  • (bool|\Drupal\Core\Access\AccessResultInterface) $access : The access to merge.
  • (bool) $and : If the access should be an andIf if TRUE or orIf if FALSE.

Return Values

void


RenderElement::wrap

Description

public static wrap (array $element, string|\Drupal\Component\Render\MarkupInterface $prefix, string|\Drupal\Component\Render\MarkupInterface $suffix, bool $inside)

Add a wrapper around a render element.

Parameters

  • (array) $element : The render element.
  • (string|\Drupal\Component\Render\MarkupInterface) $prefix : The prefix to add to the element.
  • (string|\Drupal\Component\Render\MarkupInterface) $suffix : The suffix to add to the element.
  • (bool) $inside : If the wrapper should be inside the existing prefix and suffix.

Return Values

void