Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
$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?
Comments
Comment #2
brooke_heaton CreditAttribution: brooke_heaton as a volunteer commentedI'm having the same issue. I am displaying a view with a contextual filter and the tab is still rendering.
Comment #3
brooke_heaton CreditAttribution: brooke_heaton as a volunteer commentedPatch updates all TabRenderer plugins to detect if tab content is a view and checks of view is empty - hides if empty view.
Comment #4
brooke_heaton CreditAttribution: brooke_heaton as a volunteer commentedComment #5
brooke_heaton CreditAttribution: brooke_heaton as a volunteer commentedAdded array_key_exists check for '#type' on Quicktab since this is not always set.
Comment #6
brooke_heaton CreditAttribution: brooke_heaton as a volunteer commentedRerolled against origin/8.x-3.x-dev.
Comment #7
brooke_heaton CreditAttribution: brooke_heaton as a volunteer commentedFixed array_key_exists argument order.
Comment #8
Train CreditAttribution: Train commentedI 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:
Comment #9
brooke_heaton CreditAttribution: brooke_heaton as a volunteer commentedGood catch. I've revised the patch to include the continue logic.
Comment #10
johnnydarkko CreditAttribution: johnnydarkko at Sage Tree Solutions commentedWhen 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
Comment #11
brooke_heaton CreditAttribution: brooke_heaton as a volunteer commentedRerolled below. This one did not add the proper namespacing for
Drupal\views;\Views
.Comment #12
brooke_heaton CreditAttribution: brooke_heaton as a volunteer commentedIn some cases, a view may have a non-empty attachment which should be rendered. Updated patch to check for non-empty view display attachments.
Comment #13
markdc#12 tested and working.
Comment #14
brooke_heaton CreditAttribution: brooke_heaton as a volunteer commentedComment #15
shelaneThe 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.
Comment #16
shelaneTaking 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.
Comment #17
shelaneComment #18
shelaneComment #19
shelaneComment #20
TechnoTim2010 CreditAttribution: TechnoTim2010 commentedHi
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
Comment #21
brooke_heaton CreditAttribution: brooke_heaton as a volunteer commented@shelane I'm happy to take another stab at this.
Comment #22
brooke_heaton CreditAttribution: brooke_heaton as a volunteer commentedI'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.
Comment #23
brooke_heaton CreditAttribution: brooke_heaton as a volunteer commentedComment #24
brooke_heaton CreditAttribution: brooke_heaton as a volunteer commentedUpdated patch to correct wrong array key in views_get_view_result.
Comment #25
shelaneI applied the patch, but it is still rendering for an empty view. The code output looks like:
What am I missing?
Comment #27
shelaneFound it. I missed the checkbox option.
Comment #29
heinvdb CreditAttribution: heinvdb commentedThis 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.
Comment #30
georgejhoffman CreditAttribution: georgejhoffman as a volunteer commentedheinvdb.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.