Fieldgroup vertical tabs

Created on 8 November 2019, over 4 years ago
Updated 16 May 2023, about 1 year ago

Hi,

When using the field_group module 8.x-1.* and configuring a tabs container with multiple tabs in it the layout is broken.
The tab's are printed double, once as a tab and once as a fieldset.
When i'm switching back to seven or adminimal i don't have this problem.

I also saw issue 3023291 and tried the dev module but the problem stays the same.

Kind regards,
Kristof

🐛 Bug report
Status

Active

Version

9.3

Component
Claro 

Last updated about 3 hours ago

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇱Netherlands nielsva

    I'm seeing this issue as well, using 8.x-3.4 and Gin 8.x-3.0-rc1. Therefor I think this may be reopened.

  • 🇺🇸United States danflanagan8 St. Louis, US

    @nielsva, it might be better to open an issue against Gin. IF this can't be reproduced without Gin, then this is a bug with Gin (even though Gin extends Claro).

  • 🇳🇱Netherlands nielsva

    Hi @danflanagan8, thanks for the reply. I narrowed it down to the following conditions:

    1. This only occurs on Claro (based) themes
    2. This only occurs on non Form API based usages of field_group's vertical tabs, eg. view mode of a node.

    I noticed that core/themes/claro/src/ClaroPreRender.php:88 seems to be dependent on a `$element['group']['#groups'][$group_key][$child_key]['#type']` variable which is not set at this point. This seems to make sense when I look into `field_group` which seems to not set these when rendered outside a Form API context, see: field_group/src/Element/VerticalTabs.php:26.

    The `\Drupal\claro\ClaroPreRender::verticalTabs` should be setting a `vertical-tabs__item` class on the `` element. If that is done, it would hide the `` and I think that everything should be fine.

    Though, the `$element['group']['#groups']` element does not seem to be the right place to add the attributes to. I'm guessing the Claro prerender should be revisited, but I'm not entirely sure. What's your assessment on this?

  • 🇳🇱Netherlands nielsva

    Since we need to fix this issue yesterday, I've cooked up the following preprocess method which now lives in a custom module. Placing it here for anyone in need.

    ```
    /**
    * Sets the correct Claro / Gin classes.
    *
    * This is a workaround until the following issue is solved.
    * https://www.drupal.org/project/drupal/issues/3093189#comment-15053368 🐛 Fieldgroup vertical tabs Active
    *
    * @param array $element
    * The element containing vertical tabs.
    *
    * @return array
    * The resulting pre-rendered element.
    */
    public static function verticalTabs(array $element): array {
    $groupTypeIsDetails = isset($element['group']['#type']) && $element['group']['#type'] === 'details';
    $groupsArePresent = isset($element['group']['#groups']) && is_array($element['group']['#groups']);

    if ($groupTypeIsDetails && $groupsArePresent) {
    $groupName = $element['#group_name'];
    $childrenKeys = Element::children($element, TRUE);
    foreach ($childrenKeys as $childKey) {
    if (!isset($element[$childKey]['#group']) || $element[$childKey]['#group'] !== $groupName) {
    continue;
    }

    $type = $element[$childKey]['#type'] ?? NULL;
    if ($type === 'details') {
    // Add BEM class to specify the details element is in a vertical
    // tabs group.
    $element[$childKey]['#attributes']['class'][] = 'vertical-tabs__item';
    $element[$childKey]['#vertical_tab_item'] = TRUE;
    }
    }
    }

    return $element;
    }

    ```

Production build 0.69.0 2024