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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andywhale created an issue. See original summary.

dawehner’s picture

Issue tags: +Needs tests

Thank you for your patch. Did you tried writing a test for it?

andy_w’s picture

I didn't as I ran out of time, but I will when I get a chance.

dawehner’s picture

Cool, @andywhale! Its certainly worth to post already the fix. Maybe someone else will pick it up.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

LoMo’s picture

Status: Needs review » Needs work
Issue tags: +user experience

@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.

Lendude’s picture

Category: Bug report » Task

@LoMo thanks for all the testing!

I agree that this is not a bug so much as unclear UX, so setting to task.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.