Is it at all possible to completely hide a tab with no results?

Sorry if this is a duplicate, but not finding any.

Sincerely,
Rene

Comments

rhache’s picture

Codexmas helped me solved this by changing the quicktabs_block function in quicktabs.module as follows.

The code below will hide the tab if the content is empty. Ideally, what we would like to see is the ability to choose the specific behavior on a per tab basis in the quicktabs settings. That way you could choose to output the tab or not if empty, and specify empty text if you want empty tabs to still be visible.

Feel free to use this code if you want to add it to the module.

function quicktabs_block($op = 'list', $delta = 0, $edit = array()) {

  switch ($op) {
    case 'list':
      $jqueryblocks = array();
      $result = db_query('SELECT * FROM {quicktabs}');
      while ($row = db_fetch_object($result)) {
        $jqueryblocks[$row->qtid] = $row->title;
      }
      foreach ($jqueryblocks as $key => $val) {
	$blocks[$key]['info'] = t($val);
      }
      return $blocks;
      break;
    case 'view':
      if ($jqueryblock = db_fetch_object(db_query('SELECT qtid, title, tabs FROM {quicktabs} WHERE qtid = %d', $delta))) {
        quicktabs_add_css();
        drupal_add_js(drupal_get_path('module', 'quicktabs') .'/js/quicktabs.js');
        $mainblock['subject'] = $jqueryblock->title;
        $tabs = unserialize($jqueryblock->tabs);
        if ($tabs[0]['weight']) {
          foreach ($tabs as $key => $tab) {
            $weight[$key]  = $tab['weight'];
          }
          array_multisort($weight, SORT_ASC, $tabs);
        }
        			
        $tab_header = '<div class="quicktabs_wrapper">';
        $tab_header .= '<ul class="quicktabs_tabs">';
        $output .= '<div class="quicktabs_main">';
        foreach ($tabs as $j => $tab) {
          $output .= '<div class="quicktabs">';
          if ($tab['type'] == 'view') {
            if (module_exists('views')) {
              if ($tab['args']!='') {
                $args = explode(',', $tab['args']);
              }
              else {
                $args = array();
              }	    	    	    
              $view = views_get_view($tab['bvid']);
              $viewbuild = $tab['build'] ? $tab['build'] : variable_get('quicktabs_viewbuild', 'embed');
              $output .= views_build_view($viewbuild, $view, $args, false, $tab['limit']);
              $tab_header .= '<li class="tab-'. $i .'"><a href="#">'. $tab['title'] .'</a></li>';
            }
            else {
              $output .= 'Views module not enabled, cannot display tab content';
            }
          }
          else {
            $pos = strpos($tab['bvid'], '_delta_');
            $blockmodule = substr($tab['bvid'], 0, $pos);
            $blockdelta = substr($tab['bvid'], $pos+7);
            $block = (object) module_invoke($blockmodule, 'block', 'view', $blockdelta);
            $block->module = $blockmodule;
            $block->delta = $blockdelta;
            if($this_tab_content = $block->content ? theme('quicktabs_block', $block, variable_get('quicktabs_blocktitles', 1)) : FALSE){
							$tab_header .= '<li class="tab-'. $i .'"><a href="#">'. $tab['title'] .'</a></li>';
							$output .= $this_tab_content;
							$tabs_with_content++;
						}
          }
          $output .= '</div>';  
        }
        $output .= '</div></div>';	
       
        $tab_header .= '</ul>';
        
        if($tabs_with_content > 0){
        	$mainblock['content'] = $tab_header.$output;
        }	
      }        
      return $mainblock;
    break;
  }
}
trevorleenc’s picture

this is GREAT...

just found quick tabs this morning, and have already replaced one of the "other" tab modules out there...this one is waaaay better, and this new function is just as good...

though...I noticed this odd behavior..

I have a block with three tabs now built..

subscribe rss (html block) -10
subscriptions interface (from subscriptions module) -9
subscribe newsletter (html block) -8

the subscriptions interface is not set to display on regular pages, front page, etc...so this function removes that tab from that, however, when viewing a regular page (where subs interface doesn't show), the subscribe newsletter block doesn't display it's html...this is remedied when I re-order the weights and put subs interface at the bottom (-8).

now that's well and good and all, and I can probably work with that...but sometimes, you might want to present the tab options in a certain order...

fishclic’s picture

It works nearly perfectly with this code, thanks ;)

But a small issue :

Let's say we have 3 tabs : A, B, C.

A and C are supposed to be visible on every pages and by every users.
If B is invisible to unregistered users, then C will be empty as well for unregistered users... The C title will be here, but not the content of the block.

techutopia’s picture

Subscribing.
This would be a great addition to the module main code when sorted.
Additionally, it would be good to say whether a tab is shown or not when a user is logged in or not (or of a certain role).

trevorleenc’s picture

not showing a tabbed block inside quicktabs can be controlled by the block settings, or if you are using a view, from that particular view options.

daniorama’s picture

Any news about how to implement this feature for D6? I have a problem with OG Blocks tabs showing on public content, this would be an excellent solution. Thanks

bubsy119’s picture

? any news on this ?

pauln600’s picture

+1 for this feature in Drupal 6. I'd like to display tabs showing relevant
content in categories where relevant content exists, and in this case
it's pretty well essential for tabs not to show up when blocks are
empty.

Thanks,
Paul N.

Flying Drupalist’s picture

+1 for D6 as well.

dmitrii’s picture

Title: Not showing empty tabs » Not showing empty tabs - my solution for 6.x-2.x-dev 2009/02/01
Version: 5.x-1.3 » 6.x-2.x-dev
Category: support » feature
StatusFileSize
new17.56 KB

Here is my modification of quicktabs.module,v 1.10.2.49 2009/01/31 22:05:12 pasqualle

Automatically hide quicktabs with empty views and blocks (from anonymous visitors only)

Changed functions:
function quicktabs_render($quicktabs)
function quicktabs_render_tabpage($tab)

pasqualle’s picture

Title: Not showing empty tabs - my solution for 6.x-2.x-dev 2009/02/01 » Hide empty tabs

for easier review, here is the base of solution in #10

function quicktabs_render($quicktabs) {
+	// Render all tabpgages. Unset empty
+	foreach ($quicktabs['tabs'] as $key => $tab) {
+		$quicktabs['tabs'][$key]['value'] = quicktabs_render_tabpage($tab);
+		if(empty($quicktabs['tabs'][$key]['value'])){
+			// $quicktabs['tabs'][$key]['value']='<h1>Empty Tab</h1>';
+			unset($quicktabs['tabs'][$key]);
+		}
+	}

@dmitrii your solution have the problem which I outlined here: #262886-4: Show tab according to visibility settings of contained block

To know that the tab content (like the login block) is empty then it is required to load that content first and check. This could work with non-ajax quicktabs but it is in contrast with ajax quicktabs, where you do not want to load anything unless you clicked on the tab.

and you even load every non empty tabpage twice, which I think is absolutely unwanted..

drupalok’s picture

subscribing... could this please be taken into a release? i don't like this patching stuff... one can hardly update anymore
thanks!!!

pasqualle’s picture

@drupalok: The solution is not good enough to be released with QT..

pasqualle’s picture

Version: 6.x-2.x-dev » 6.x-3.x-dev

Moving new features to 3.x version

gregarios’s picture

Subscribing... Sorry 'bout the duplicate post. :)

happydrupal’s picture

Cool......Can't wait to see the new Quick Tab 3.X

Subscribing...........

math_1048’s picture

subscribing

xarbot’s picture

subscribing

EvanDonovan’s picture

Subscribing. I need this to properly use Quicktabs inside Panels 3 pages when I have Views when no empty text set. (Nice specific use case :) )

Thanks so much for this module, and the patch.

EvanDonovan’s picture

StatusFileSize
new2.04 KB

For people still on QuickTabs 2.x, here is an improved patch for this functionality. Now it will hide views when they don't have results, which was what I needed.

If anyone cares to re-roll for 3.x, that would be great, so that we could set this to "needs review".

pasqualle’s picture

Status: Active » Needs work

don't worry, there is no 3.x version yet. So you can post patches against 2.x
the problem described in comment #11 still exists in this patch.

requirements:
1. 'hide empty tab' setting can be used in non-ajax quicktabs only (or non-ajax tabpages only #351953: Tabpage specific AJAX Settings)
2. the tab content should be loaded only once

to achieve requirement 2 the quicktab rendering process needs to be fully redesigned..

EvanDonovan’s picture

Good point, Pasqualle. I didn't think about the situation with AJAX tabs since my site isn't using the AJAX feature. But yes, this patch won't work with AJAX.

The main advantage of my patch was simply that it fixes the issue with "empty" views. Offhand, I can't think of a way to find out whether a tab would be empty without actually loading the content.

pasqualle’s picture

yes, we need to load the content if we want to find out whether the tab is empty, but we do not have to load it again to render it.

garywiz’s picture

StatusFileSize
new1.67 KB

Patch #20 had a number of problems for us:

  • Rendering views twice, once to check for emptiness, once to render the tab.
  • Broke tabs which used Ajax.
  • Included $quicktabs['tabs'][n]['value'] data in the Drupal.settings strings which sometimes caused javascript selection to stop working properly and do full page reloads.

At the risk of adding to the noise, here is a patch rolled which solves these problems. Empty tabs are eliminated only for non-ajax quicktabs and the tab order is renumbered so the rest of the code is none-the-wiser. Also, a general caching mechanism is added to quicktabs_render_tabpage() so that nothing is ever rendered twice during a single page build... the empty check and the tab render do not cause duplicate renders. Also, the empty check is omitted for ajax quicktabs, so those still work properly.

I am not pretending this should be part of the committed QT module... I think it is a bit of a hack, but it solved the problem for us.

pasqualle’s picture

Version: 6.x-3.x-dev » 6.x-2.x-dev
Status: Needs work » Needs review

@garywiz: thanks for the patch, this looks much more better now. And I do not have any objections, this could be added to the module, I just have to do some testing..

garywiz’s picture

I think if it were added to the module, it would be good to have a checkbox on the admin page for a quicktab such as "Hide empty tabs (only if Ajax set to 'no')" and set something like $quicktabs['hide_if_empty'] = 1 so that it could be used conditionally.

It is also notable that it can be difficult to hide empty tabs if people aren't careful with their themes. For example, if a block is put into a tab, often block theming includes boilerplate divs, etc which may render even if the block is empty. So, I would expect some people will submit bugs against this when "visibly empty" does not mean the same as "really empty". I debated about this thinking about whether it was worth worrying about but instead decided just to modify our theme templates to check the $content variable and not render useless divs if the content were empty. This makes the pages leaner anyway and was a good change for us.

pasqualle’s picture

yes, I agree. An explanation on the admin page should describe this problem.
If you have the time to do the "Hide empty tabs" checkbox, then please do it. Thanks..

EvanDonovan’s picture

@garywiz: Thanks for the new patch. You say that it renumbers the tab order - does that mean that there might be side effects if I switch from my patch to yours?

garywiz’s picture

@EvanDonavan: You say that it renumbers the tab order - does that mean that there might be side effects if I switch from my patch to yours?

Well, it may work differently, but I believe the renumbering is necessary in order to make things work right. With the patch in #20, I was seeing problem cases where if the middle tab of three were empty (and deleted), the javascript code in quicktabs.js was not working properly because the tab indices were [0,2] instead of [0,1]. The wrong tabs were being chosen as the default tab. So, I think the proper operation is that, after empty tabs are removed, tab indices should be sequential because other parts of the code depend on having no gaps in the tab order.

garywiz’s picture

StatusFileSize
new5.41 KB

@Pasqualle: yes, I agree. An explanation on the admin page should describe this problem. If you have the time to do the "Hide empty tabs" checkbox, then please do it. Thanks..

Here is an updated patch that includes the admin settings to allow you to choose empty-tab behavior on a per tabset basis.

Note, this patch updates the database and requires a module upgrade. I suggest using #24 for now until Pasqualle let's us know what he thinks of this and whether it will be put into the dev version. This patch is upward compatible from the one in #24 and just adds some of the glue to make it more suitable for inclusion.

Requires testing.

garywiz’s picture

StatusFileSize
new5.39 KB

There was a line of debugging code (a dsm) in the patch in #30. Apologies. This one fixes it.

pasqualle’s picture

Status: Needs review » Fixed

committed with a slight modification to correctly hide the tab when the user does not have the permission to see the tab content.
http://drupal.org/cvs?commit=292078

the idea in comment #20, to hide an empty view (view with no results) is nice, but I guess there is a problem with views with exposed filters, where the resultset can be changed. Please create a new issue if you need that functionality.

Status: Fixed » Closed (fixed)

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

rc2020’s picture

subscribe

404’s picture

subscribe