You are here

public function Fieldset::preRender in Field Group 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/field_group/FieldGroupFormatter/Fieldset.php \Drupal\field_group\Plugin\field_group\FieldGroupFormatter\Fieldset::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/Fieldset.php, line 26

Class

Fieldset
Plugin implementation of the 'fieldset' formatter.

Namespace

Drupal\field_group\Plugin\field_group\FieldGroupFormatter

Code

public function preRender(&$element, $rendering_object) {
  $element += array(
    '#type' => 'fieldset',
    '#title' => Html::escape($this
      ->t($this
      ->getLabel())),
    '#pre_render' => array(),
    '#attributes' => array(),
  );
  if ($this
    ->getSetting('description')) {
    $element += array(
      '#description' => $this
        ->getSetting('description'),
    );

    // When a fieldset has a description, an id is required.
    if (!$this
      ->getSetting('id')) {
      $element['#id'] = Html::getId($this->group->group_name);
    }
  }
  if ($this
    ->getSetting('id')) {
    $element['#id'] = Html::getId($this
      ->getSetting('id'));
  }
  $classes = $this
    ->getClasses();
  if (!empty($classes)) {
    $element['#attributes'] += array(
      'class' => $classes,
    );
  }
  if ($this
    ->getSetting('required_fields')) {
    $element['#attached']['library'][] = 'field_group/formatter.fieldset';
    $element['#attached']['library'][] = 'field_group/core';
  }
}