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.
Updated: Comment #87
Problem/Motivation
Views with no result sets were not being displayed. An option to "Display even if view has no result" was available but not being checked by the views handler.
Proposed resolution
The view handler now provides a filtered output string with results OR an empty string if "display no results" is selected.
Remaining tasks
Comment | File | Size | Author |
---|---|---|---|
#122 | views-1217394-122.patch | 5.16 KB | skylord |
| |||
#115 | views-1217394-115.patch | 5.84 KB | MustangGB |
| |||
#104 | views-1217394-104.patch | 5.82 KB | greggadsdon |
| |||
#77 | interdiff-1217394-77.txt | 1003 bytes | damiankloip |
#72 | display_empty-1217394-72.patch | 10.46 KB | dawehner |
Comments
Comment #1
dawehnerAre you really sure that there is no result?
Perhaps you have missed some filter configuration.
Comment #2
rogical CreditAttribution: rogical commentedI want it display even no results, so however any filter configuration, if no results it should also display, right?
but when I put the views block into panels, the header/footer doesn't display.
Comment #3
dawehnerThen this seems to be a bug of ctools
Comment #4
merlinofchaos CreditAttribution: merlinofchaos commentedNo this isn't actually CTools' fault, not precisely.
In blocks, you need an empty text. Putting in is probably enough. Unfortunately it's not smart enough to realize that the 'header' or 'footer' displaying is enough to trigger the block to appear. That's...a difficulty in Views right now.
Comment #5
arski CreditAttribution: arski commentedsub. have the same issue in the latest 6.x release.
Comment #6
dawehnerWhat about adding a $view->not_empty or $view->always_render so it can be forced and just need to be checked here.
Comment #7
m3n0R CreditAttribution: m3n0R commentedHere the same issue!
Subscribe +1
Comment #8
jsacksick CreditAttribution: jsacksick commentedWhat about loop over header and footer elements and check if the empty option is checked ?
Here is the proposed patch.
Edit : Must be in ctools issues and the patch should be resent.
See #1245202: Views content pane empty even if "Display even if view has no result" is checked for views header/footer
Comment #9
dawehnerMove to ctools issue queue as this patch is against ctools. Update status.
Comment #10
MichaelCole CreditAttribution: MichaelCole commentedThis is exactly what I needed when mixing Page Manager with Views.
The patch was edited to apply to ctools dir, instead of www.
Comment #11
MichaelCole CreditAttribution: MichaelCole commentedThis does not work when adding View:Master as a panel.
This does work when adding View:Content pane as a panel.
Comment #12
jsacksick CreditAttribution: jsacksick commentedThis new patch should work for the view master too. It's a simply copy/paste from views_pane.inc to views.inc
Comment #13
merlinofchaos CreditAttribution: merlinofchaos commentedI really think we need a better way in Views to find that information so that we don't have to hardcode digging into structures like that. Let's find an issue in Views and mark this dependent upon it. Or at least say so since our tracking system doesn't do dependencies.
Comment #14
develpr CreditAttribution: develpr commentedusing normal view.
I checked "Display even if view has no result" but text not showing if there is no record..
filter conditions:
published : yes
content: type (reviews)
not working. It shows empty page not that text which I write into the Header(global textarea).
Comment #15
merlinofchaos CreditAttribution: merlinofchaos commentedKicking this back to Views and assigning to dereine. Let's talk about an API in Views that we can use to put this annoying issue to bed.
Comment #16
dawehnerSo here is some code in views.
This currently doesn't handle the part in block.
What should be the default, or should it not change and has some configuration.
Comment #17
dawehnerJust tracking some work on the block part at 4am.
Comment #18
tim.plunkettTriggering the testbot.
Comment #20
sgb9809 CreditAttribution: sgb9809 commentedI am having opposite problem as OP - I leave the checkbox unchecked, so in theory if there are no results the header should NOT display, but even in my views where I am certain there are no results, the header is always shown. The only time the header does not display is when my contextual filter does not pass the filter criteria. If the contextual filter passes, even when the fields being queried are empty, the header is displayed. I'm guessing this is not a desired feature. Is there any way around this?
Comment #21
sgb9809 CreditAttribution: sgb9809 commentedNevermind, found a solution by adding filters to prevent null rows.
"There is no way for Views to tell if all fields in a row have no results (I know, this seems counter intuitive but it's true). You need to add filters to your view to prevent null rows for showing up."
Comment #22
areikiera CreditAttribution: areikiera commented@sgb9809,
I'm having trouble figuring out how to follow the suggested solution in comment #21. Could you (or someone) describe how you accomplished this?
I'm guessing you added a Contextual Filter 'Global: Null', but I can't figure out how to configure it.
Thanks!
EDIT: Nevermind. I was way off above, trying to add a contextual filter. I added a standard filter for the field I was using, and set it to "Is not empty (NOT NULL)". It was a little confusing since I was using a relationship for a nodereference field, and thought it had to be more complicated than that, but just had to select the relationship in the filter, and voila! Thanks for the info!
Comment #23
bryancasler CreditAttribution: bryancasler commentedLooks like I created a duplicate post.
#1554792: Empty view outputs <div></div>
...Here is my contribution...
I have a view that outputs the current node's body. The problem I'm running into is that even when the body is empty the "No results text" is ignored and instead an empty
is being included.
Views Export: http://pastebin.com/veCZAG0j
Screenshot of Views Settings: http://snpr.cm/vaZGM9.png
Screenshot of Display Suite Settings: http://www.diigo.com/item/image/1ks4o/r2b1?size=o
Screenshot of Panels Setting: http://snpr.cm/nLq12u.png
Screenshot of Node Body: http://snpr.cm/JM5Ogh.png
Screenshot of Views Output HTML: http://snpr.cm/pr89yR.png
Comment #24
dawehner#17: 1217394-view-empty.patch queued for re-testing.
Comment #26
dagmarI will try to fix this. I think I think dawhener won't be bothered :)
Comment #27
elly CreditAttribution: elly commentedSame problem here. Is there any workaround for the interim?
Comment #28
dagmarSorry I haven't time to work on this at this moment.
Comment #29
dasjojust encountered this bug when using a search api view
Comment #30
igget76 CreditAttribution: igget76 commentedI have the same problem. I'm using panels with a views pane. When checking "Show the empty text in the table", my panels page shows this error messagen:
Notice: Undefined variable: row_classes in include() (line 38 of /var/www/www.example.com/sites/all/modules/views/theme/views-view-table.tpl.php).
The view displays correctly in the preview.
Comment #31
rodp CreditAttribution: rodp commentedAnswer 21 above worked for me. If your filter is something like FieldFoo contains %some_string%, just AND another filter that says FieldFoo is not empty (not null). I'm using Drupal 6 block views inside of QuickTabs, and both the Display Header Even If No Results option and the Empty Text values started working after I added this. Whew! Thanks sgb9809.
Comment #32
sergeysynergy CreditAttribution: sergeysynergy commented++ to #21
Comment #33
rutcreate CreditAttribution: rutcreate commentedThis is a patch for block display even if no result for header and footer area.
Comment #34
Slacky08 CreditAttribution: Slacky08 commentedPatch in #33 worked for me! (Drupal 7.15 / Views 7.x-3.5)
Comment #35
dawehnerBut #33 is simply wrong compared to the previous approaches.
Comment #36
dawehnerLet's get something done for d8.
Comment #37
dawehnerThis should be core
Comment #38
ankit.goyal5 CreditAttribution: ankit.goyal5 commentedIn Views basic settings/empty text is there.
In that we can write the content that has to come when views give no result. even with content format option you can write PHP code also. I tried this in drupal 6, working perfect.
Thanks
Comment #39
dawehner@ankit.goyal5
Yeah this is about hiding the block, if there is no result.
Comment #40
dawehnerRerolled.
Comment #41
oresh CreditAttribution: oresh commented#40: drupal-1217394-40.patch queued for re-testing.
Comment #42
damiankloip CreditAttribution: damiankloip commented#40: drupal-1217394-40.patch queued for re-testing.
Comment #44
dawehnerLet's rerole it.
Comment #46
dawehnerJust another one.
Comment #48
dawehner#46: drupal-1217394-46.patch queued for re-testing.
Comment #50
dawehnerThat happens if you show a random amount of people some features of phpstorm.
Comment #51
bdone CreditAttribution: bdone commentedTagging for an issue summary.
http://drupal.org/node/1427826 has instructions for adding/updating an issue summary.
Comment #52
dawehnerLet's get this in, please.
Comment #53
dawehnerUploading a patch with just the test.
Comment #55
dawehner#52: drupal-1217394-52.patch queued for re-testing.
Comment #56
damiankloip CreditAttribution: damiankloip commentedWe should implement usage of this on the other area handlers, then we can change the
if (!$empty || !empty($this->options['empty'])) { ...
parts. I'm just thinking, maybe a isNotEmpty method would be nice to read for this too?'Returns whether the view has any rendered output' maybe? Also, maybe the second part could say 'This checks the view result, header, footer, and empty regions' or similar instead.
I like the 'FALSE otherwise' but sure, this is personal preference.
Why do we need the reference here?
label
Comment #57
dawehnerYeah I am not really sure how to improve the code, as the rendering of headers/footers have to be asked for, in order to determine whether the output of the area handler is really empty.
This is not a reference, but a logical AND.
Comment #59
olli CreditAttribution: olli commentedLooks like you uploaded #52 again?
Comment #60
dawehnerComment #62
olli CreditAttribution: olli commentedHmm, improvements from interdiff #57 are not in the patch #60.
So by default, show the block even if it's empty, correct?
I'm not sure about this.. Shouldn't it be !hide_empty || !outputIsEmpty? I have to test this manually.
I think that "!" is not needed here, or did I got it wrong again?
Missing #type.
This should be ...tests/modules/views_test_config... now.
Comment #63
dizi.joao CreditAttribution: dizi.joao commentedThe header and footer "no results" option will only work if you add a no result behavior to the view block. Go to the advanced fieldset and add a no result behavior. Its below "Relationships". You can add a empty "global text area" if you dont want to show anything. Its simple and dont need a patch.
Comment #64
dawehnerYes, we can for sure choose the other default value.
Rewrite the bit to make it way way easier to read.
@dizi.joao
The point of the issue is to make it configurable and work as expected.
Here is a version which has the fixes of #57 included.
Comment #65
dawehner#64: vdc-1217394-64.patch queued for re-testing.
Comment #67
dawehnerRerolled.
Comment #69
giorgio79 CreditAttribution: giorgio79 commented#63 works like magic. Much appreciated :)
Comment #70
dawehnerThere we go.
Comment #71
jibranNice it is green. Here is some minor issues.
This should be more descriptive imo.
We can move this to one
foreach
and remove$area_types
variable.We have a static method for this now
Views::getView
.Comment #72
dawehnerThank you for the review!!
There we go.
Comment #73
jibranIt is a major bug and now we have a nice test coverage so RTBC for me.
Comment #75
dawehner#72: display_empty-1217394-72.patch queued for re-testing.
Comment #76
jibranBack to RTBC.
Comment #77
damiankloip CreditAttribution: damiankloip commentedSpeaking with Tim and catch, we're removing the bitwise logic (to return early if a handler isn't empty) and changing the comment.
Comment #78
dawehnerThis makes it indeed easier to grok.
Comment #79
alexpottCommitted 2a43a1b and pushed to 8.x. Thanks!
Assigning to Views 8.x for a change notice
Comment #80
MXTThe original issue was for D7 an other related D7 issues in the queue points here: can this also be back-ported to D7 please?
Thank you very much for considering this
Comment #81
AaronBaumanHere's a patch for D7 -- it's a one-liner.
The only place I ran into this issue for 7.x was views_handler_area_result.inc
Not sure if I'm missing something else from this thread.
I'm leaving this at 8.x because I don't know whether the change notice has been completed yet.
edit: dunno why the VDC tag was removed when this comment was posted.
i didn't touch the tag field on the comment form, so I'll assume that was supposed to happen for some reason.
Comment #82
Woodyjon CreditAttribution: Woodyjon commentedPatch 81 did not solve the problem for me. v7.x-3.7
Comment #83
dawehner@aaronbauman
We want to have the same kind of concept in D7, so you or for example the ctools module can really figure out whether a view is empty or not.
Comment #84
YesCT CreditAttribution: YesCT commentedkeeping at this on 8.x till the change notice is done. (https://drupal.org/core-gates#documentation has a summary that says move to major task, etc. Disturbingly though, the actual doc about the policy is missing. see #2083415-7: [META] Write up all outstanding change notices before release)
to help with get the change notice done, updating the issue summary would help (contributor task doc on updating issue summary),
and also here are the instructions for drafting a change notice
Comment #85
daveramps CreditAttribution: daveramps commentedComment #86
daveramps CreditAttribution: daveramps commentedComment #87
daveramps CreditAttribution: daveramps commentedComment #88
milos.kroulik CreditAttribution: milos.kroulik commentedThe patch in #81 doesn't work for me neither (on D7, V 3.7). I'm trying to use it with Dynamic Fields feature of Display Suite.
Comment #89
TechNikh CreditAttribution: TechNikh commentedPatch in 81 shows the header but the @start token is wrong for me.
"Showing -14 - 0 of 0"
I am using contextual arguments.
Comment #90
schifazl CreditAttribution: schifazl commentedI did the same as dizi.joao in #63, works flawlessly
Comment #91
OnkelTem CreditAttribution: OnkelTem commentedAs far as I can see the backporting effort was silently abandoned as the patch was not provided for more then year. Or was is so hard/impossible to apply it on D7? Or basically D7 is not a subject of your interest anymore? :) FYI if D8 will be released tomorrow, we'll continue using D7 for year or so.
Comment #92
OnkelTem CreditAttribution: OnkelTem commentedOk, this is D7 backport patch for the #77 issue. The part that I missed is new tests.
Comment #93
OnkelTem CreditAttribution: OnkelTem commentedComment #94
OnkelTem CreditAttribution: OnkelTem commentedThis is follow-up for D7 to get Views Content Panes working with the new stuff: #1245202: Views content pane empty even if "Display even if view has no result" is checked for views header/footer see comment #4
Comment #95
BrightBoldThe patch in #93 works, but I don't think it's the way we want to solve the problem.
First, it adds a new field in the Advanced > Other section called "Hide block if the view output is empty" rather than honoring that setting in other places. Second, it sets the value of that setting to "Show," by default, which means all the views on your site that you didn't want appearing when empty (which is really a sensible default; otherwise your site is peppered with contentless headers) so you have to go and change it to Hide on all view displays except for the ones you want to show.
Comment #96
sachin.bansal CreditAttribution: sachin.bansal commentedI have modified the patch given in #93. Now, all empty block will be hidden by default.
Comment #97
nithinkolekar CreditAttribution: nithinkolekar commentedPatch doesn't seems to be working when view(display type: block) is placed inside Quicktab with parameter %2 for term pages. But working fine in view's preview by passing tid manually.
Is this related to quicktab (how it is passing) or related to this patch.
update:
working when tab type is set to block instead of view(select a view,display,argument).
also works when block is placed in theme region using block administration.
Comment #98
eric.chenchao CreditAttribution: eric.chenchao commentedLooking at those patches above, it seems those patches are making view / view block show up when ticking "Display even if view has no result". However the title of this node is too vague.
Could anyone provide a more detailed title or better description of the bug please?
Comment #99
osopolarWhat about attachment views, if the view it is attached to is empty? I have a panel pane view display with a glossary attachment and it does not show up in panels. I applied the patch from #96 and #1245202: Views content pane empty even if "Display even if view has no result" is checked for views header/footer.
This may also affect D8 as output_is_empty() only checks the handlers:
'empty', 'footer', 'header'
.Comment #100
milos.kroulik CreditAttribution: milos.kroulik commentedPatch in #96 seems to be working fine.
Comment #101
MustangGB CreditAttribution: MustangGB commentedWorks like a charm.
Comment #103
isimgt CreditAttribution: isimgt commentedPatch in #96 seems to be working fine.
Version: 7.x-3.11
Comment #104
greggadsdon CreditAttribution: greggadsdon at ComputerMinds commentedUpdated patch from #93 for latest views 7.x-3.14
Comment #105
osopolar@greggadsdon: Is there a reason for choosing patch #93 and not #96?
Comment #106
MustangGB CreditAttribution: MustangGB commentedThis is a blocker for #1245202: Views content pane empty even if "Display even if view has no result" is checked for views header/footer.
Comment #107
MustangGB CreditAttribution: MustangGB commentedTentatively marking as RTBC again because the patch is working fine and we're basically just waiting for a committer decision on whether to go with the #93 or #96 approach.
Personally I'd prefer #96.
Comment #108
MustangGB CreditAttribution: MustangGB commentedHere's a re-roll of #96 then.
Comment #109
DamienMcKennaBumping to the next release.
Comment #110
MustangGB CreditAttribution: MustangGB commentedManually edited #108 because the header comment indentation for output_is_empty() needed correcting.
Comment #111
DamienMcKennaNote: #110 literally only changed indenting of one of the comments, there were no other changes. Leaving this RTBC.
Comment #112
DamienMcKennaHaving reviewed the patches, #93 (therefore #104) is the way to go because it matches the wording of patch #77.
Comment #113
DamienMcKennaStill needs a change notice because of the subtle change.
Comment #114
DamienMcKennaTaking this off the plan for the next release, will consider it later.
Comment #115
MustangGB CreditAttribution: MustangGB commentedRe-rolled #110.
Comment #116
tobiasbPatch do not apply anymore.
Comment #117
chuck_theobald CreditAttribution: chuck_theobald commentedThis is still a problem with version 7.x-3.20.
Comment #118
randell CreditAttribution: randell as a volunteer and commentedStill an issue in Drupal 8.
Comment #119
AaronBaumanComment #120
AaronBaumanComment #121
MustangGB CreditAttribution: MustangGB commentedD8 has already had it's commit, if a follow-up is needed probably best to create a new issue.
Comment #122
skylord CreditAttribution: skylord commentedReroll for 3.20 attached - works OK for me.
Comment #123
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commented@skylord, what patch/comment # did you use for the rerolled patch in #122?
Comment #124
skylord CreditAttribution: skylord commentedSorry not to mention it. It was #115.
Comment #125
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedNo problem, based on the reading of this issue thread:
The patch in #122 is a reroll of the patch #115
The patch in #115 was a reroll of the patch in #110.
The patch in #110 was a manual edit to the patch in #108.
The patch in #108 was a reroll of the patch in #96.
The patch in #96 was a manual edit to the patch in #93
However, @DamienMcKenna mentioned in #122:
Please correct me if I'm wrong, but I think we've gotten off track on the most relevant patch to be working from.
Comment #126
skylord CreditAttribution: skylord commentedYou are right. There are two branches of patches: #93 - #104 and #96 - #108 - #110 - #115 - #122. The only difference is that second one considers block hiding as default behaviour and has reverse logic to #93: empty blocks are hidden and you have to manually set checkbox "Show block if no result/empty text" to show'em.
Comment #127
MustangGB CreditAttribution: MustangGB commentedAs aforely mentioned I think they empty ones should be hidden by default, à la #122.
But if we could just have a decision and get a commit that'd be ideal as this is still a blocker for #1245202: Views content pane empty even if "Display even if view has no result" is checked for views header/footer.
Comment #128
DamienMcKennaMight anyone have time to try writing some test coverage for this?