You are here

public static function Element::processLegend in Lightning Core 8

Same name and namespace in other branches
  1. 8.5 src/Element.php \Drupal\lightning_core\Element::processLegend()
  2. 8.2 src/Element.php \Drupal\lightning_core\Element::processLegend()
  3. 8.3 src/Element.php \Drupal\lightning_core\Element::processLegend()
  4. 8.4 src/Element.php \Drupal\lightning_core\Element::processLegend()

Sets descriptions on child elements according to the #legend property.

Parameters

array $element: The unprocessed element.

Return value

array The processed element.

2 calls to Element::processLegend()
ElementTest::testProcessLegendArray in tests/src/Kernel/ElementTest.php
@covers ::processLegend
ElementTest::testProcessLegendCallable in tests/src/Kernel/ElementTest.php
@covers ::processLegend

File

src/Element.php, line 134

Class

Element
Helpful functions for dealing with renderable arrays and elements.

Namespace

Drupal\lightning_core

Code

public static function processLegend(array $element) {
  if ($element['#legend']) {
    foreach (RenderElement::children($element) as $key) {
      if (is_callable($element['#legend'])) {
        $element[$key]['#description'] = $element['#legend']($element[$key]);
      }
      elseif (isset($element['#legend'][$key])) {
        $element[$key]['#description'] = $element['#legend'][$key];
      }
    }
  }
  return $element;
}