If you add visibility rules to panes in your panels there are cases when whole region or even row/column become empty. In some cases we are interested not to show such region's/row's/column's wrappers.

Here is patch for flexible layout managing this situation.

Changes:
- added checkbox "Hide element if empty" on row/column/region configuration form (flexible layout designer);
- added logic to remove element wrappers if they have empty content.

flexible-layout-hide-empty.png

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

AndreyMaximov’s picture

andypost’s picture

Nice improvement! BC implemented so should be RTBC

+++ b/plugins/layouts/flexible/flexible.incundefined
@@ -471,15 +471,26 @@ function panels_flexible_render_items($renderer, $list, $owner_id) {
+        if (empty($renderer->settings['items'][$id]['hide_empty']) || trim($content)) {
...
+        if (empty($renderer->settings['items'][$id]['hide_empty']) || trim($content)) {
...
+        if (empty($renderer->settings['items'][$id]['hide_empty']) || $content) {

The only check for emptiness questionable here

maximpodorov’s picture

Status: Needs review » Reviewed & tested by the community

The patch is useful and working.

Sinan Erdem’s picture

What if we don't use flexible layouts? For example I generally use custom layouts for reusability.

Sinan Erdem’s picture

I applied the patch and it even works for custom layouts since they are also of "Flexible" type.

Thanks!

Chris Burge’s picture

I have successfully applied this patch, and it works as advertised.

There is a minor bug, however. The 'Hide element if empty' checkbox doesn't appear when initially creating a region (or column); rather, the user must create a region and then edit it in order to check the 'Hide element if empty' checkbox.

japerry’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work

Marking needs work per #6

AndreyMaximov’s picture

Status: Needs work » Needs review
FileSize
831 bytes
3.26 KB

Chris Burge, thanks.

Added 'Hide element if empty' checkbox to region (or column) adding form.

Chris Burge’s picture

The #8 patch resolves the issue described by #6.

maximpodorov’s picture

Status: Needs review » Reviewed & tested by the community

The obvious addition. But maybe it's better to use the more descriptive label for the checkbox or add a description text which explains what will happen.

Anonymous’s picture

Patch is working. Would be awesome if this gets included in Panels.

khuongkd’s picture

mxr576’s picture

It is just what I need right now. Thanks for this. I hope it will be the part of the panels soon.

malbone’s picture

Would this work against the latest stable release 7.x-3.4 ?

liquidcms’s picture

not sure if i am having the same issue; but sounds like it.

- i have a mini panel def inside a quicktab.
- i have Panels 7.x-3.4
- i applied the patch here and it seems to have applied cleanly - i now get hide if empty checkboxes at all levels of panels layout (canvas, column, row, region).
- i have set qtabs to hide if empty
- i have checked all the new hide if empty checkboxes for layout of my mini panel
- i have NO content in my mini-panel (i removed all the content panes to test).

the qtab still shows.

looking at the html for this qtab i see:

<div id="quicktabs-tabpage-user-1" class="quicktabs-tabpage">
<div id="block-panels-mini-user-teaching" class="block block-panels-mini contextual-links-region even collapsiblock-processed">
<div class="contextual-links-wrapper contextual-links-processed">
<div class="content">
<div id="mini-panel-user_teaching" class="panel-flexible panels-flexible-34 clearfix">
<div class="panel-flexible-inside panels-flexible-34-inside"> </div>
</div>
</div>
</div>
</div>

and i see the issue why qtabs does not think it is empty, the most inner div still has a space.

as far as i can tell there is nothing that should be creating that space; there are no content panes.

not sure if this is related to this issue or not.

japerry’s picture

Status: Reviewed & tested by the community » Fixed

Per #9 and #8 I believe we're fixed. It appears #15 is referring to visibility issues with quicktabs, which is another issue. Marking this one fixed and committed. feel free to comment and mark needs work if I'm wrong.

  • japerry committed 77057be on 7.x-3.x authored by AndreyMaximov
    Issue #2025043 by AndreyMaximov: Flexible layout: hide an empty region/...

Status: Fixed » Closed (fixed)

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

jvieille’s picture

For this to work, I had to change trim($content) by trim(strip_tags($content)).
As trim did not remove all the html code which is generated regardless the actual content, the panes always showed up.

I am using D6, but the code is identical.

arruk’s picture

Can the code in this patch be applied to other layouts?