I set out to reproduce the problem of a mini panel being included when it's empty. I am using the most recent dev's of panels and ctools.

In my panels display I have a mini panel that has no content in it and no title.
screenshot: http://www.diigo.com/item/image/1ks4o/gqb8?size=o
export: http://pastebin.com/7ArS97wt

I add that mini panel to the panel layout and choose to override the title.
screenshot: http://www.diigo.com/item/image/1ks4o/68pq?size=o

This is the mini panel's output on the page.

<div class=?"panel-pane pane-panels-mini pane-blank-mini-panel">?<div class="panel-pane pane-panels-mini pane-blank-mini-panel">
<div class="pane-content">
<div class="panel-display panel-1col clearfix" id="mini-panel-blank_mini_panel">
<div class="panel-panel panel-col">
<div></div>
</div>
</div>
</div>
</div>

*There appears to be a missing closing div

If I choose not to override the title, this is the mini panel's output on the page.

<div class="panel-pane pane-panels-mini pane-blank-mini-panel">
<div class="pane-content">
<div class="panel-display panel-1col clearfix" id="mini-panel-blank_mini_panel">
<div class="panel-panel panel-col">
<div></div>
</div>
</div>
</div>
</div>

REF: #400332: Hide mini panels when empty
REF: #1367154: Empty mini-panels does not hide when title being overridden.

Files: 
CommentFileSizeAuthor
#21 1391450-21-hide-empty-mini-panel.patch2.66 KBMichelle
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]
#19 interdiff.txt1.29 KBAngry Dan
#19 1391450-19-hide-empty-mini-panel.patch2.66 KBAngry Dan
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]
#16 1391450-16-hide-empty-mini-panel.patch2.33 KBjwilson3
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]
#14 1391450-14-hide-empty-mini-panel.patch2.96 KBzhangtaihao
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1391450-14-hide-empty-mini-panel.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#13 panels-hide-empty-mini-panel-1391450-13.patch1.98 KBjantoine
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]
#8 1391450-08-hide-empty-mini-panel.patch1.95 KBzhangtaihao
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1391450-08-hide-empty-mini-panel.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Comments

bryancasler’s picture

Issue summary:View changes

Adding info

bryancasler’s picture

Issue summary:View changes

fix

bryancasler’s picture

Issue summary:View changes

fix

merlinofchaos’s picture

Status:Active» Closed (duplicate)

Really you just duplicated an issue that you referenced, and my response is here: http://drupal.org/node/400332#comment-2219542

I could type it again, but that doesn't serve anybody's interests.

merlinofchaos’s picture

I take it back, it does serve:

Panel layouts are not smart enough to hide if there are no visible panes. It's not part of the layout system to do that. Unless a specific layout were to be smart enough to do that (it's possible with a preprocess), that is.

bryancasler’s picture

Thanks for responding Merlin. I opened up a new issue because of Letharion's comment in #26 "@R.hendel Thanks for clearly describing the problem. Again, this issue contains to many loose ends. New issue based on #23 here: #1367154: Empty mini-panels does not hide when title being overridden.. Closing this one, hoping I can get rid of it."

I was a bit confused about why it was closed if there were still "many loose ends" but I figured Letharion wanted to split the issue off into more targeted discussions.

I remembered the comment your referencing, but you later re-opened the issue and followed it up with "Re-opening. With the new render pipeline, I think this is much more possible now. We could slide a check into panels_renderer_standard::render_layout() and set a flag on the display (or renderer) to abort the rendering if there is no rendered content at all." So I figured that this was indeed possible and I was hoping to help in any way I could.

merlinofchaos’s picture

Category:bug» feature
Status:Closed (duplicate)» Active

Hm. I had forgotten saying that.

In that case, not a bug, but a feature request.

Letharion’s picture

In response to #3, yeah, I just wanted to close an issue that had no clear instructions for how to reproduce the error, and probably contained several different errors in itself. More targeted was indeed the goal, like this one :)

@merlinofchaos, that missing </div> does look like a bug, though, right?

rich.yumul’s picture

To get around this issue in the 6.x space, I created a template override in my site's custom theme, that overrode the onecol layout (my mini-panel was using the one column layout). Basically, I just put 'panels-onecol.tpl.php' in my theme folder and it looked like this:

/**
* @file
* Template for a 3 column panel layout.
*
* This template provides a very simple "one column" panel display layout.
*
* Variables:
* - $id: An optional CSS id to use for the layout.
* - $content: An array of content, each item in the array is keyed to one
*   panel of the layout. This layout supports the following sections:
*   $content['middle']: The only panel in the layout.
*/
if ($content['middle']):
?>
<div class="panel-display panel-1col clear-block" <?php if (!empty($css_id)) { print "id="$css_id""; } ?>>
  <div class="panel-panel panel-col">
    <div><?php print $content['middle']; ?></div>
  </div>
</div>
<?php endif; ?>

Of course, you have to make sure the views are returning nothing first though. HTH, YMMV. :)

osopolar’s picture

I am using the woraround too, but would prefer to have an option "hide when empty" ... like views has.

zhangtaihao’s picture

StatusFileSize
new1.95 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1391450-08-hide-empty-mini-panel.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Here's my attempt at hiding empty mini panels.

The point, I believe, is to not return any content for a mini panel CTools block if its content is empty after rendering. Then, in the renderer, the layout is only rendered if any region is not empty. Otherwise, the render does not trigger the layout (e.g. one column) and therefore does not return any markup, and the mini panel does not show up.

Core blocks seem to also hide a mini panel if block content invoked from hook_block_view() is empty.

Is this the right approach?

P.S. I didn't use $this->rendered['panes'] in the renderer to check for content because an editor renders regions with no panes (to output a UI for adding panes).

zhangtaihao’s picture

Status:Active» Needs review

Oops.

anniegreens’s picture

I have applied the patch in #8 and it appears to be working for my scenario: panel page with mini panel containing a title and three views panes displays. When all three views return no results based on contextual filters the mini panel no longer appears.

bbinkovitz’s picture

I applied the patch and it effectively hid the empty minipanel I tested it with. It didn't affect populated minipanels.

merlinofchaos’s picture

Status:Needs review» Needs work

This needs to be optional. Let's say I have a panel page, and for some reason, the panel has no content. It returns blank, which will ultimately cause a whitescreen rather than an empty page. Plus, we'll spend extra cycles testing for empty panels when we don't need to.

I think mini panels could set a flag on the renderer or something and that flag could be checked prior to running this test.

jantoine’s picture

StatusFileSize
new1.98 KB
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]

Updated patch in #8 against the latest dev.

zhangtaihao’s picture

Status:Needs work» Needs review
StatusFileSize
new2.96 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1391450-14-hide-empty-mini-panel.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Sorry this took me a while to get back to.

Updated patch per #12. This works based on the (possibly tricky) assumption that a mini panel is rendered by loading the exportable object via the Export API and contains the table attribute. I found implementing hook_panels_pre_render() the only practical way (without adding the flag to display) to set the flag on the renderer only after a display has initialized the renderer object.

jwilson3’s picture

Status:Needs review» Needs work

Re: #14, Good start, but being able to set the show_empty_layout flag through the Mini-panels Admin UI would be a basic requirement for this feature to be of any general use.

Also, I wasnt able to get this to apply to 7.x-3.x-dev had to apply by hand.

jwilson3’s picture

StatusFileSize
new2.33 KB
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]

Re-rolled #14 to apply against latest 7.x-3.x-dev, I still havent implemented an admin settings form for this (per #15), so am leaving in needs work.

jwilson3’s picture

Issue summary:View changes

fix

freeform.steph’s picture

Thank you for this, I successfully applied it to the latest dev release without issue.

ShaunDychko’s picture

#16 is great. Thank you very much!

Angry Dan’s picture

Version:7.x-3.x-dev» 7.x-3.4
Issue summary:View changes
Status:Needs work» Needs review
StatusFileSize
new2.66 KB
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]
new1.29 KB

This patch wasn't working for me for blocks rendered via mini_panels_block_view because the owner reference wasn't being set. I'm not sure if this is correct, but I've modified mini_panels_block_view to include the owner value on the display. Patch rolled against latest stable release.

Michelle’s picture

Version:7.x-3.4» 7.x-3.x-dev
StatusFileSize
new2.66 KB
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]

There was an offset when I applied the patch in #19 to the latest dev so I uploaded a new patch just to fix that; I made no other changes to it.

I tested it and it does hide the mini-panel when it's empty. I don't know what "rendered via mini_panels_block_view " means so I wasn't able to test the issue in #19.

My one concern is that in #12 merlinofchaos said it should be optional. #14 says it addresses #12 but I don't see any setting that makes it optional.

Angry Dan’s picture

@michelle, I was probably referrring to the point in my debugging that I had the problem, but given it's a hook implementation of hook_block_view(), mini_panels_block_view() must be my poor code for "mini panels added via the blocks administration page"

Michelle’s picture

Ah, I see. Ok, I just tested a mini panel added as a block and patch #21 worked to hide it there as well. I think this is RTBC but someone else needs to set it since technically I had the last patch even though it was just a minor re-roll.

tlangston’s picture

#21 solved the issue for me here as well.

potassiumchloride’s picture

#21 appears to have solved the issue for me as well. This has saved a major headache. Thank you!

hey_germano’s picture

Status:Needs review» Reviewed & tested by the community

#21 solved the issue for me, too. Thanks!

The last submitted patch, 8: 1391450-08-hide-empty-mini-panel.patch, failed testing.

The last submitted patch, 14: 1391450-14-hide-empty-mini-panel.patch, failed testing.

annya’s picture

#21 works like a charm

japerry’s picture

Status:Reviewed & tested by the community» Fixed

I think this is good to go, if we missed something we can file another bug report.

  • japerry committed 87dd920 on 7.x-3.x authored by Angry Dan
    Issue #1391450 by zhangtaihao, Angry Dan, jwilson3, Michelle, jantoine:...

Status:Fixed» Closed (fixed)

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