Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If the view inside the view field is empty the field does not get excluded (hidden).
Comment | File | Size | Author |
---|---|---|---|
#20 | 1091780-20-hide-if-empty.patch | 2.03 KB | fizk |
#18 | 1091780-hide-if-empty.patch | 1.99 KB | fizk |
Comments
Comment #1
pontus_nilssonThis can be solved by adding a template file for the view that is added as a field to your view that strips out the surrounding div for the view.
Comment #2
Damien Tournoud CreditAttribution: Damien Tournoud commentedRetitling, bumping.
This module uses views_embed_view() directly. It should be easy to render the view ourselves and add the option to not return anything if the child view has an empty result set.
Comment #3
Damien Tournoud CreditAttribution: Damien Tournoud commentedThis is technically more a feature request.
Comment #4
the_paulus CreditAttribution: the_paulus commentedHere is how I got around the problem. I created a module and added this function:
function MODULE_views_post_render(&$view, &$output, &$cache) {
if($view->name == 'VIEWNAME') {
if(count($view->result) == 1) {
$output = '';
$cache = '';
}
}
}
For my view field I created a view and am only using the default display. If you have a view with multiple display, you're going to have to add additional logic to make sure you are not removing anything you want to keep.
Comment #5
davidarthur CreditAttribution: davidarthur commentedIt should just use the "Hide if empty" option.
Anyone got a better solution yet? I'm looking into it...
(This bug is for v6 release also)
Comment #6
pbeakley CreditAttribution: pbeakley commented+1
Comment #7
damiankloip CreditAttribution: damiankloip commentedCommitted to dev branch, as per #2, views_embed_view is not being used anymore.
Comment #9
moniuch CreditAttribution: moniuch commentedEven though the issue has been closed, let me chime in.
I got here because I too have been suffering from lack of this 'hide if empty' feature, implemented on the UI side, just like modules are supposed to, without any workarounds. And I was surprised to see the status 'closed (fixed)' - I can't see the feature, so how should I understand that?
Comment #10
damiankloip CreditAttribution: damiankloip commentedThis is referring to the Hide if empty checkbox under 'No results behaviour' settings for the field. Where are you looking for this feature? I'm pretty sure it's there.
Comment #11
moniuch CreditAttribution: moniuch commentedI was looking in the Manage Display and Manage Fields form for the content type where I'm inserting the view.
Utilizing the view I'm displaying other categories that a node is tagged with. If there is no other association than the current one, I meant to hide not only the result, but also the label of the view field. I thought the visibility should be controlled on the node level.
The "Hide if empty" checkbox is there in the View but does not cause the label to go off when checked.
Please enlighten me as per the logic you implemented.
Comment #12
damiankloip CreditAttribution: damiankloip commentedHang on, you are embedding the view in a node? So you aren't using this module to do it?
Comment #13
moniuch CreditAttribution: moniuch commentedGrrrh.... Looks like I have confused Viewfield with VFV... Will you ever forget? How can I redeem my sin?
Comment #14
damiankloip CreditAttribution: damiankloip commentedHa, :) Thought something strange was going on. I will heal over time.....
Comment #15
ice5nake CreditAttribution: ice5nake commentedI'd like to see something happen surrounding this request. My take on this was Views Field View is not working correctly with the "Hide if Empty" and "Hide empty fields" View options.
FWIW, I'm using 6.x
Comment #16
damiankloip CreditAttribution: damiankloip commentedChanging the issue to the correct version is a good place to start. I would like to see something happen around this too, but unfortunately time is an issue. Most of my concentration is going into the 7.x branch at the moment. Patches are welcome.
Comment #17
jvieille CreditAttribution: jvieille commentedViews field still shows up even if it is empty.
Any solution yet?
Comment #18
fizk CreditAttribution: fizk commentedThis patch seems to work for me.
Comment #19
fizk CreditAttribution: fizk commentedNote that I removed the
unset($options[$this->view->name]);
in that patch because I needed to access the current view, but a different display.Comment #20
fizk CreditAttribution: fizk commentedChanged a comment to "// If there are no results and either hide_empty is set or the empty text is set."
Comment #21
jibranDrupal 6 compatible versions of the module are not supported anymore.