You are here

class Tab in Field Group: Easy Responsive Tabs to Accordion 8

Same name in this branch
  1. 8 src/Element/Tab.php \Drupal\field_group_easy_responsive_tabs\Element\Tab
  2. 8 src/Plugin/field_group/FieldGroupFormatter/Tab.php \Drupal\field_group_easy_responsive_tabs\Plugin\field_group\FieldGroupFormatter\Tab

Plugin implementation of the 'ertta_tab' formatter.

Plugin annotation


@FieldGroupFormatter(
  id = "ertta_tab",
  label = @Translation("Easy Responsive Tabs to Accordion - Tab"),
  description = @Translation("This fieldgroup renders the content as a tab."),
  supported_contexts = {
    "form",
    "view",
  },
)

Hierarchy

  • class \Drupal\field_group_easy_responsive_tabs\Plugin\field_group\FieldGroupFormatter\Tab extends \Drupal\field_group\FieldGroupFormatterBase

Expanded class hierarchy of Tab

File

src/Plugin/field_group/FieldGroupFormatter/Tab.php, line 21

Namespace

Drupal\field_group_easy_responsive_tabs\Plugin\field_group\FieldGroupFormatter
View source
class Tab extends FieldGroupFormatterBase {

  /**
   * {@inheritdoc}
   */
  public function preRender(&$element, $rendering_object) {
    parent::preRender($element, $rendering_object);
    $label = $this
      ->t($this
      ->getLabel());
    $add = [
      '#type' => 'field_group_easy_responsive_tab',
      '#title' => !empty($label) ? Html::escape($label) : '',
      '#description' => $this
        ->getSetting('description'),
      '#theme_wrappers' => [
        'field_group_easy_responsive_tab',
      ],
      '#attributes' => [
        'class' => $this
          ->getClasses(),
      ],
    ];

    // 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['#parents'] = [
        $this->group->parent_name,
      ];
    }
    if ($this
      ->getSetting('id')) {
      $add['#id'] = Html::getId($this
        ->getSetting('id'));
    }
    else {
      $add['#id'] = Html::getId('edit-' . $this->group->group_name);
    }
    $element += $add;
  }

  /**
   * {@inheritdoc}
   */
  public function settingsForm() {
    $form = parent::settingsForm();
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public static function defaultContextSettings($context) {
    $defaults = [] + parent::defaultContextSettings($context);
    return $defaults;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Tab::defaultContextSettings public static function
Tab::preRender public function
Tab::settingsForm public function