$render = $object->render($tab);

in quicktabs\Plugin\TabRender expects the render array to be empty. With contextual arguments there is no view but there is an object returned that has cache data in it.

$render['#cache']['contexts'] .....

wouldn't it be better to check for a type in the array or something else? Or is this a configuration issue on my part?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

reptilex created an issue. See original summary.

brooke_heaton’s picture

I'm having the same issue. I am displaying a view with a contextual filter and the tab is still rendering.

brooke_heaton’s picture

Patch updates all TabRenderer plugins to detect if tab content is a view and checks of view is empty - hides if empty view.

// If user wants to hide empty tabs and there is no content
      // then skip to next tab]
      if ($instance->getHideEmptyTabs() && $render['#type'] === 'view') {
        $view_results = views_get_view_result($render['#name'], $render['#display_id']);
        $render = empty($view_results) ? NULL : $render;
      }
      if ($instance->getHideEmptyTabs() && empty($render)) {
        continue;
      }
brooke_heaton’s picture

Assigned: Unassigned » brooke_heaton
Status: Active » Needs review
brooke_heaton’s picture

Added array_key_exists check for '#type' on Quicktab since this is not always set.

brooke_heaton’s picture

Rerolled against origin/8.x-3.x-dev.

brooke_heaton’s picture

Fixed array_key_exists argument order.

Train’s picture

I noticed that the continue statement was omitted from this patch thereby allowing the loop to render all the other elements of the tab. Meaning empty Views still rendered.

I made the following change and it works for me:

      if (array_key_exists('#type', $render) && $render['#type'] === 'view') {
        $view_results = views_get_view_result($render['#name'], $render['#display_id']);
        $render = empty($view_results) ? NULL : $render;
      }

      if ($instance->getHideEmptyTabs() && empty($render)) {
        continue;
      }
brooke_heaton’s picture

Good catch. I've revised the patch to include the continue logic.

johnnydarkko’s picture

When you the empty tabs are no longer rendered, the tab indexing gets thrown off and tries to display the wrong tab content.
The patch in this issue correctly maps the tabs to the tab content: https://www.drupal.org/project/quicktabs/issues/3008441

brooke_heaton’s picture

Rerolled below. This one did not add the proper namespacing for Drupal\views;\Views.

brooke_heaton’s picture

In some cases, a view may have a non-empty attachment which should be rendered. Updated patch to check for non-empty view display attachments.

markdc’s picture

#12 tested and working.

brooke_heaton’s picture

Status: Needs review » Reviewed & tested by the community
shelane’s picture

The only thing I don't like in this approach is that it is putting the repeated code directly in the renderer. This would also mean that any sub-modules that have additional renderers would need to include this code. I'd like to see if there is a better place to put this code where it can be reused.

shelane’s picture

Taking a look, I'm thinking this may be a good place: src/Plugin/TabType/ViewContent.php

I'll look into this idea more in the coming weeks.

shelane’s picture

Status: Reviewed & tested by the community » Needs work
shelane’s picture

Issue tags: +Global2020
shelane’s picture

Assigned: brooke_heaton » Unassigned
TechnoTim2010’s picture

Hi

I am trying to work out how to do empty tabs for a custom coded block.

I have the block rendering nothing and working properly as an empty block, but in a tab it still shows the tab header even though the tab contains precisely nothing.

By the way the reason this block is necessary is it was to replace a view of three file fields which even though empty still showed up.

Somewhat confused as to why and how to proceed.

Regards

Tim

brooke_heaton’s picture

@shelane I'm happy to take another stab at this.

brooke_heaton’s picture

I've addressed this now on src/Plugin/TabType/ViewContent.php where there is already a check on view permissions, which returns empty if the user does not have permission to view the view diaplay. If we return empty on an empty view or empty view with empty attachments, that should be sufficient. I will note that it may be possible for a user to add a Block View Display, which may be empty and this patch does not address that issue, but it should cover any View Tab.

brooke_heaton’s picture

Status: Needs work » Needs review
brooke_heaton’s picture

Updated patch to correct wrong array key in views_get_view_result.

shelane’s picture

I applied the patch, but it is still rendering for an empty view. The code output looks like:

<div id="quicktabs-tabpage-empty_view_test-1" class="quicktabs-tabpage">
<div class="quicktabs-block-title"></div>
<div></div>
</div>

What am I missing?

  • shelane committed fb696fe on 8.x-3.x authored by brooke_heaton
    Issue #2909326 by brooke_heaton: Empty Views Tabs still being rendered
    
shelane’s picture

Status: Needs review » Fixed
Issue tags: -Global2020

Found it. I missed the checkbox option.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

heinvdb’s picture

This commit has caused some issues.

- If a View's Empty Behavior is set, the output is never displayed even if "Hide empty tabs" isn't selected.
- It causes some caching issues and shows 0 results for anonymous users after using the page for a while. The patch from https://www.drupal.org/project/quicktabs/issues/2979578 had to be applied to fix the issue.

georgejhoffman’s picture

heinvdb.ntt Thanks for your post, as I was having an issue where quicktabs would disappear for anonymous users after a while. The above patch looks to have fixed the issue.