You are here

public static function ClaroPreRender::container in Drupal 10

Same name and namespace in other branches
  1. 8 core/themes/claro/src/ClaroPreRender.php \Drupal\claro\ClaroPreRender::container()
  2. 9 core/themes/claro/src/ClaroPreRender.php \Drupal\claro\ClaroPreRender::container()

Prerender callback for container elements.

Parameters

array $element: The container element.

Return value

array The processed container element.

File

core/themes/claro/src/ClaroPreRender.php, line 134

Class

ClaroPreRender
Implements trusted prerender callbacks for the Claro theme.

Namespace

Drupal\claro

Code

public static function container(array $element) {
  if (!empty($element['#accordion'])) {

    // The container must work as an accordion list wrapper.
    $element['#attributes']['class'][] = 'accordion';
    $children_keys = Element::children($element['#groups']['advanced'], TRUE);
    foreach ($children_keys as $key) {
      $element['#groups']['advanced'][$key]['#attributes']['class'][] = 'accordion__item';

      // Mark children with type Details as accordion item.
      if (!empty($element['#groups']['advanced'][$key]['#type']) && $element['#groups']['advanced'][$key]['#type'] === 'details') {
        $element['#groups']['advanced'][$key]['#accordion_item'] = TRUE;
      }
    }
  }
  return $element;
}