Currently selecting No Results Behaviour of Global: View area (Global: View area) the Hide block if the view output is empty:Yes fails to be honoured.
This appears to be caused by the isEmpty method in Drupal\views\Plugin\views\area\View, as while checking isEmpty in the handler the render has not already run, and therefore the variable is still NULL.
One approach would be to run the render if the isEmpty variable has not yet been set - caching should reduce the impact of this - which would then populate the isEmpty variable.
Comment | File | Size | Author |
---|---|---|---|
views-view-area-hide-block.patch | 701 bytes | andy_w | |
Comments
Comment #2
dawehnerThank you for your patch. Did you tried writing a test for it?
Comment #3
andy_w CreditAttribution: andy_w at Numiko commentedI didn't as I ran out of time, but I will when I get a chance.
Comment #4
dawehnerCool, @andywhale! Its certainly worth to post already the fix. Maybe someone else will pick it up.
Comment #6
LoMo CreditAttribution: LoMo as a volunteer commented@andywhale: This is an interesting issue. I was planning to help with a test... but as far as I can tell, the two settings are simply in logical conflict. One is an override to provide some kind of content if there is nothing to display in the view and the other is to hide an empty view. That said, even with your patch applied, the block still shows up* until I remove the "No Results Behaviour". Then if "Hide block if the view output is empty:Yes" is enabled, the Views block is not displayed.
IMHO, this is less a bug than a quirk of Views. Or perhaps the bug is that we still allow the "Hide if empty" to be enabled if we have "No results behavior". The "No results behavior" means that the block is NOT empty, though, so "Hide if empty" no longer really applies, perhaps.
Anyway, I agree that the UX could be improved here, but I think it's a matter of having two settings that can be set in somewhat opposing manners and which setting takes precedence should be more clear to users. Or it should not be possible to have both settings enabled in this opposing manner. I think the "bug" is more to do with VIew UI and what the user experience should be here could bear further discussion. I would personally suggest disabling the "Hide block if the view output is empty:Yes" option if "No results behavior" provides some other kind of output. Users should then see that "Hide block" option will be available if they remove the "No results behavior". Note that there are a lot of options for the "No results behavior", so it's possible that there is a use case where these two options might NOT be in conflict (I am not sure, and I can't think of one... but just saying... ;-) )
* The block I used to test this was the standard "Recent content" block, which already has default text displayed if the view is empty. Enabling the "Hide block if the view output is empty" setting, with this patch applied, still meant the block was displayed. (Yes, the View was saved and the caches cleared). Then if I removed the "No results behavior", the block title was still displayed if "Hide if empty" was not enabled, but was correctly hidden if "hide if empty" was enabled. The attached patch did not appear to make any difference for any scenario I tried.
Comment #7
Lendude@LoMo thanks for all the testing!
I agree that this is not a bug so much as unclear UX, so setting to task.