You are here

public static function UIkitAccordion::preRenderUIkitAccordion in UIkit Components 8.3

Pre-render callback: Sets the accordion options and attributes.

Doing so during pre_render gives modules a chance to alter the accordion.

Parameters

array $element: A renderable array.

Return value

array A renderable array.

File

src/Element/UIkitAccordion.php, line 79

Class

UIkitAccordion
Provides a render element for the Accordion component.

Namespace

Drupal\uikit_components\Element

Code

public static function preRenderUIkitAccordion($element) {

  // Prepare the component options for the accordion.
  $component_options = '';
  if (!empty($element['#component_options'])) {
    $component_options = implode('; ', $element['#component_options']);
  }

  // Set the attributes for the accordion outer element.
  $element['#attributes']
    ->addClass('uk-accordion');
  $element['#attributes']
    ->setAttribute('data-uk-accordion', $component_options);
  return $element;
}