You are here

public function Tab::preRender in Field Group 8

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

Class

Tab
Plugin implementation of the 'tab' formatter.

Namespace

Drupal\field_group\Plugin\field_group\FieldGroupFormatter

Code

public function preRender(&$element, $rendering_object) {
  parent::preRender($element, $rendering_object);
  $add = array(
    '#type' => 'details',
    '#title' => Html::escape($this
      ->t($this
      ->getLabel())),
    '#description' => $this
      ->getSetting('description'),
  );
  if ($this
    ->getSetting('id')) {
    $add['#id'] = Html::getId($this
      ->getSetting('id'));
  }
  else {
    $add['#id'] = Html::getId('edit-' . $this->group->group_name);
  }
  $classes = $this
    ->getClasses();
  if (!empty($classes)) {
    $element += array(
      '#attributes' => array(
        'class' => $classes,
      ),
    );
  }
  if ($this
    ->getSetting('formatter') == 'open') {
    $element['#open'] = TRUE;
  }

  // Front-end and back-end on configuration will lead
  // to vertical tabs nested in a separate vertical group.
  if (!empty($this->group->parent_name)) {
    $add['#group'] = $this->group->parent_name;
    $add['#parents'] = array(
      $add['#group'],
    );
  }
  if ($this
    ->getSetting('required_fields')) {
    $element['#attached']['library'][] = 'field_group/formatter.tabs';
    $element['#attached']['library'][] = 'field_group/core';
  }
  $element += $add;
}