/** * {@inheritdoc} */ public function preRender(&$element, $rendering_object) { $element += array('#prefix' => '<div class=" ' . implode(' ', $this->getClasses()) . '">', '#suffix' => '</div>', '#tree' => TRUE, '#parents' => array($this->group->group_name), '#default_tab' => ''); if ($this->getSetting('id')) { $element['#id'] = Html::getId($this->getSetting('id')); } // By default tabs don't have titles but you can override it in the theme. if ($this->getLabel()) { $element['#title'] = SafeMarkup::checkPlain($this->getLabel()); } $form_state = new \Drupal\Core\Form\FormState(); if ($this->getSetting('direction') == 'vertical') { $element += array('#type' => 'vertical_tabs', '#theme_wrappers' => array('vertical_tabs')); $complete_form = array(); $element = \Drupal\Core\Render\Element\VerticalTabs::processVerticalTabs($element, $form_state, $complete_form); } else { $element += array('#type' => 'horizontal_tabs', '#theme_wrappers' => array('horizontal_tabs')); $on_form = $this->context == 'form'; $element = \Drupal\field_group\Element\HorizontalTabs::processHorizontalTabs($element, $form_state, $on_form); } // Make sure the group has 1 child. This is needed to succeed at form_pre_render_vertical_tabs(). // Skipping this would force us to move all child groups to this array, making it an un-nestable. $element['group']['#groups'][$this->group->group_name] = array(0 => array()); $element['group']['#groups'][$this->group->group_name]['#group_exists'] = TRUE; // Search for a tab that was marked as open. First one wins. foreach (\Drupal\Core\Render\Element::children($element) as $tab_name) { if (!empty($element[$tab_name]['#open'])) { $element[$this->group->group_name . '__active_tab']['#default_value'] = $tab_name; break; } } }
/** * {@inheritdoc} */ public function preRender(&$element) { $element += array('#prefix' => '<div class="field-group-' . $this->group->format_type . '-wrapper ' . $this->group->classes . '">', '#suffix' => '</div>', '#tree' => TRUE, '#parents' => array($this->group->group_name), '#default_tab' => ''); $form_state = new \Drupal\Core\Form\FormState(); if ($this->getSetting('direction') == 'vertical') { $element += array('#type' => 'vertical_tabs', '#theme_wrappers' => array('vertical_tabs')); $complete_form = array(); $element = \Drupal\Core\Render\Element\VerticalTabs::processVerticalTabs($element, $form_state, $complete_form); } else { $element += array('#type' => 'horizontal_tabs', '#theme_wrappers' => array('horizontal_tabs')); $on_form = $this->context == 'form'; $element = \Drupal\field_group\Element\HorizontalTabs::processHorizontalTabs($element, $form_state, $on_form); } // Make sure the group has 1 child. This is needed to succeed at form_pre_render_vertical_tabs(). // Skipping this would force us to move all child groups to this array, making it an un-nestable. $element['group']['#groups'][$this->group->group_name] = array(0 => array()); $element['group']['#groups'][$this->group->group_name]['#group_exists'] = TRUE; // By default tabs don't have titles but you can override it in the theme. if ($this->getLabel()) { $element['#title'] = SafeMarkup::checkPlain($this->getLabel()); } }
/** * Builds a renderable array for a field value. * * @param \Drupal\Core\Field\FieldItemListInterface $items * The field values to be rendered. * @param string $langcode * The language that should be used to render the field. * * @return array * A renderable array for $items, as an array of child elements keyed by * consecutive numeric indexes starting from 0. */ public function viewElements(FieldItemListInterface $items, $langcode) { $type = $this->getSetting('type') . '_tabs'; $element = ['#parents' => [$type], '#type' => $type, '#title' => '', '#theme_wrappers' => [$type], '#default_tab' => '']; foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) { $tab = ['#type' => 'details', '#title' => $entity->label(), '#description' => '']; $view_builder = \Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId()); $tab[] = $view_builder->view($entity, $this->getSetting('view_mode'), $langcode); $element[] = $tab; } $form_state = new FormState(); if ($this->getSetting('type') == 'vertical') { $complete_form = []; $element = VerticalTabs::processVerticalTabs($element, $form_state, $complete_form); // Make sure the group has 1 child. This is needed to succeed at // VerticalTabs::preRenderVerticalTabs(). Skipping this would force us to // move all child groups to this array, making it an un-nestable. $element['group']['#groups'][$type] = [0 => []]; $element['group']['#groups'][$type]['#group_exists'] = TRUE; } else { $element = HorizontalTabs::processHorizontalTabs($element, $form_state, FALSE); } return $element; }