Hide empty panes

Rob Loach - January 30, 2008 - 22:45
Project:Panels
Version:5.x-2.x-dev
Component:User interface
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

Hide a tab if its pane is empty.

#1

Rob Loach - January 30, 2008 - 22:51
Status:active» needs review

Although it's not a patch, a simple if statement will hide the tab.....

<?php
 
foreach ($panes as $pane_id => $content) {
   
// Only show the tab if there is existing content
   
if ($content->content) {
     
// Remove the title from the content. We don't want titles in both the tab
      // and the content associated with the tab.
     
$content_without_title = drupal_clone($content);
      unset(
$content_without_title->title);
 
     
$tabs[$id][$pane_id] = array(
       
'#type' => 'tabpage',
       
'#title' => $content->title,
       
'#content' => theme('panels_pane', $content_without_title, $display->content[$pane_id], $display),
       
'#weight' => $index,
      );
     
$index++;
    }
  }
?>

This will effectively show the tab only if content exists within it. I would love to make a patch, but I'm quite busy at the moment.

#2

Wim Leers - January 30, 2008 - 22:56

When/how are panes empty?

#3

Rob Loach - January 31, 2008 - 00:40

You can have an empty pane if you're displaying a view that queries some nodes that don't exist and the view doesn't have its "Empty Text" set. In Panels (with a normal panel), when this happens, the pane just doesn't display. With Panels Tabs, it displays an empty tab. This could be considered a bug in Panels Tabs and is fixed with this patch.

We could move this into a style setting it you want....

<?php
  $form
['hide_empty_tabs'] = array(
   
'#type' => 'checkbox',
   
'#title' => t('Hide empty tabs'),
   
'#description' => t('This option will hide tabs that do not contain content.'),
   
'#default_value' => (isset($style_settings['hide_empty_tabs'])) ? $style_settings['hide_empty_tabs'] : FALSE,
  );
?>

AttachmentSize
panels_tabs.patch 1.56 KB

#4

Wim Leers - January 31, 2008 - 06:35
Project:Tabs panel style» Panels
Version:5.x-1.x-dev» 5.x-2.x-dev

Well, just about every style would have to implement this feature. So perhaps it's better if we can do this in Panels itself. Moving to the Panels issue queue, to get some feedback about this from merlin.

#5

nath - February 5, 2008 - 11:30

It would be nice to have this option.

#6

cgjohnson - May 20, 2008 - 21:53

This would be nice. Does it exist? Does it work for views without panels? Anyone have a suggestion about that?
thanks!

#7

sdboyer - May 24, 2008 - 06:19

I'll have a look at this tomorrow, see if there's anything to be moved on here.

#8

merlinofchaos - July 9, 2008 - 21:02
Status:needs review» active

This is not currently a patch against Panels.

#9

Wim Leers - July 9, 2008 - 22:03
Status:active» postponed (maintainer needs more info)

Earl, the issue at hand is whether each panel style should check for itself if a pane is empty and then not render it, or if Panels itself should handle this. If you decide it's the former, then I'll move it back to the panels_tabs issue queue and fix it.

#10

merlinofchaos - July 9, 2008 - 22:08

If the patch makes sense I agree that it could possibly be Panels responsibility to remove it before it gets to the style.

#11

sdboyer - July 11, 2008 - 05:29

Yeah, I think this is legit, although it's also a bit complicated, as I've had some reasonably-argued requests for allowing content-less panes to be rendered in particular ways, too.

Ultimately, though, I'd be most interested to see a patch that actually pertains to Panels :)

#12

Wim Leers - July 12, 2008 - 17:19

Well, if you want to support content-less panes, this won't work. In what cases do you you want/need that?

#13

rgraves - August 15, 2008 - 14:00

I've been using the patch suggestioned in comment #1 to solve my problem with empty tabs appearing. It worked, however I have about 40 views that are used with my panel to create tabs. No page uses all 40 views - some use 2 of the views, some use 4, etc.

The problem is with this fix it runs the sql queries for all 40 views and then uses the IF statement to decide whether to display it or not. This makes the page loading very slow.

Is there a way that I can have it only run the sql queries if it knows there is content for that view? That way it would only run the necessary queries for the tabs it will be displaying.

Rob

#14

sun - December 28, 2008 - 20:24
Title:Hide Empty Tabs» Hide empty panes
Status:postponed (maintainer needs more info)» active

Better title. And, +1, we should support this.

#15

tobiass - January 1, 2009 - 14:31

This would be great. Subscribing

#16

CorpX - February 4, 2009 - 13:12

Subscribing

#17

thelocaltourist - February 9, 2009 - 20:11

subscribing

#18

tsi - March 30, 2009 - 16:03

subscribing

#19

JStarcher - April 3, 2009 - 16:02

I was going to use this patch but with the problem Rob is talking about I don't think I will even try it. I have 40+ views as well.

#20

rgraves - May 27, 2009 - 13:27

What I ended up having to do was create separate panels for each of my pages, then only add the views (tabs) that were necessary for those panel pages. It was an administrative headache to set them all up because there are so many panel pages, but it drastically improved the speed for the end user. If you don't have many views, the patch above worked great. If you have dozens of views, consider using separate panels for each page.

#21

bensemmel - May 30, 2009 - 15:29

Same issue for 6.x at http://drupal.org/node/208832

 
 

Drupal is a registered trademark of Dries Buytaert.