You are here

public function Details::preRender in Field Group 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/field_group/FieldGroupFormatter/Details.php \Drupal\field_group\Plugin\field_group\FieldGroupFormatter\Details::preRender()

Allows the field group formatter to manipulate the field group array and attach the formatters rendering element.

Parameters

array $element: The field group render array.

object $rendering_object: The object / entity beïng rendered.

Overrides FieldGroupFormatterBase::preRender

File

src/Plugin/field_group/FieldGroupFormatter/Details.php, line 26

Class

Details
Details element.

Namespace

Drupal\field_group\Plugin\field_group\FieldGroupFormatter

Code

public function preRender(&$element, $rendering_object) {
  parent::preRender($element, $rendering_object);
  $element += array(
    '#type' => 'details',
    '#title' => Html::escape($this
      ->t($this
      ->getLabel())),
    '#open' => $this
      ->getSetting('open'),
  );
  if ($this
    ->getSetting('id')) {
    $element['#id'] = Html::getId($this
      ->getSetting('id'));
  }
  $classes = $this
    ->getClasses();
  if (!empty($classes)) {
    $element += array(
      '#attributes' => array(
        'class' => $classes,
      ),
    );
  }
  if ($this
    ->getSetting('description')) {
    $element += array(
      '#description' => $this
        ->getSetting('description'),
    );
  }
  if ($this
    ->getSetting('required_fields')) {
    $element['#attached']['library'][] = 'field_group/formatter.details';
    $element['#attached']['library'][] = 'field_group/core';
  }
}