Closed (fixed)
Project:
Display Suite
Version:
7.x-1.5
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
24 Jan 2012 at 09:18 UTC
Updated:
5 Aug 2016 at 08:45 UTC
Jump to comment: Most recent
I'm using Display Suite fields on a view.
I'm configuring my display suite view on 2 cols. In left, i have an image field and on 2nd, body and title :
LEFT | RIGHT
image title
body
On my view, on image field definition, i check 'Hide if empty' and 'Hide rewriting if empty'. I haven't label and doesn't display label for this field. I also check on display suite 'Hide empty regions'.
But the result prints an empty markup :
<div class="group-left">
<div class="views-field-field_logo">
<div class="field-label"></div>
</div>
</div>
I fix this bug on views_plugin_ds_fields_view.inc l.97 :
// Create the region content.
$region_content = '';
if (isset($layout['settings']['regions'][$region_name])) {
foreach ($layout['settings']['regions'][$region_name] as $key => $field) {
if(!empty($view->style_plugin->rendered_fields[$row_index][$field]) || !$view->field[$field]->options['hide_alter_empty']) {
$region_content .= '<div class="views-field-' . $field . '">';
if (isset($view->field[$field]->options['label']) && $view->field[$field]->options['hide_alter_empty']) {
$region_content .= '<div class="field-label">';
$region_content .= check_plain($view->field[$field]->options['label']);
if ($view->field[$field]->options['element_label_colon']) {
$region_content .= ':';
}
$region_content .= '</div>';
}
$region_content .= $view->style_plugin->rendered_fields[$row_index][$field];
$region_content .= '</div>';
}
}
}
$vars[$region_name] = $region_content;
With this fix, i have no markup and so no region if my field is empty.
Patch on next comment
Comments
Comment #1
goz commentedShame on me, it's already in 7.x-1.x-dev
Sorry for that
Comment #3
kclarkson commentedI have a similar display at which I am using a custom 2 - column display tpl.php. I changed the % width's to 65% and 35% in the css.
In the settings I checked "hide region when empty". So in my view I have content where some have images and some do not but the regions always show leaving a blank space when a piece of content does not have images.
Comment #4
sonar_un commentedI am having the same problem as k-clarkson, using a custom ds display and specifically trying to display images..
The region continues to render even if I have the "hide region when empty" clicked and I am on the latest -dev version.
Comment #5
dufferin commentedI have no problem in 'full content' view mode, 'hide empty region' works fine,
though doesn't give any result in 'Teaser' view mode.
Comment #6
DanielFriis commentedHave you guys checked if you're using any other modules that rewrites the output? I had this issue when using the module DownloadFile in custom layout. Either changing to regular Full content or setting the file rendering to generic file fixed it for me.
Comment #7
swentel commentedAs DanielFriis points out, check if there is any data from that field. It's possible fields return empty wrappers. If so, in that case, there's nothing that I can do.
Comment #8
swentel commentedIn fact, closing this for now. If there's a region that's still there, it means there's output, even it that means there are empty wrappers. in that case, it's another module.
Comment #9
thoughtcat commentedHope you don't mind me reopening this, but I'm having the same problem. I've got an optional text field in which the user pastes YouTube embed code. After quite a lot of trial and error with filters and tokens I've got the videos to display in the node where there is one using this:
<p><iframe align="left" frameborder="0" height="335" scrolling="no" src="[node:field_youtube2]" width="450"></iframe></p>But where there is no value for the field I get a large white space in place of the video. I do have "hide empty regions" checked for the full display and I'm afraid I don't know what else could be outputting the space, or how to find this out.
I tried solving it with an attempt at conditional php:
But this doesn't display anything whether there is a value in the field or not. I'd be very grateful for any suggestions.
Comment #10
swentel commentedThe token won't be evaluated inside a php print statement. What you'll need todo is something like this:
There's a good article re: field_get_items and field_view_field at http://www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way
Comment #11
thoughtcat commentedThanks again Swentel, unfortunately it didn't work - I initially got the same as before (the field didn't display whether there was any content in it or not) - then after some fiddling I managed to get it to output the raw user input but not display the actual video. Guess I'll have to keep looking! Cheers :)
Comment #12
bloomt commentedIs there a way to hide the display suite regon on drupal 8 if the field is empty?
Comment #13
finex commentedHi, the bug is still valid on D8. Do you need a separate bug report?
Comment #14
aspilicious commentedWhat version of DS are you running? and which template? Yes please open a new report.
Comment #15
finex commented@spilicious: hi, I'm using DS 8.x-2.5 with ds-1col template and Drupal 8.1.7. I've opened a new bug report: https://www.drupal.org/node/2779437