Hide block/view if No results behavior

Created on 22 August 2024, 12 months ago

Problem/Motivation

Reopening this issue as 3334147 🐛 Empty content view Fixed was closed but the problem has not been resolved as missing patch #4.

Proposed resolution

Attached patch works as expected and should be released.

3334147_3.patch

🐛 Bug report
Status

Active

Version

2.1

Component

Code

Created by

🇸🇰Slovakia coaston

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @coaston
  • Status changed to Postponed: needs info 11 months ago
  • 🇩🇪Germany Anybody Porta Westfalica

    @coaston how do you come to this conclusion?

    Comparing the commit from the linked issue
    https://git.drupalcode.org/project/entity_extra_field/-/commit/94a2ab3dc...
    to the latest branch:
    https://git.drupalcode.org/project/entity_extra_field/-/blob/2.1.x/src/P...

    it's present!

  • it's present!

    Coaston means to say that the original commit is incomplete, not that the commit is missing.

    The MR created by jnettik implemented the fix in a different way from the patch file submitted by artyom. Namely:

    • The MR implementation simply calls Element::isEmpty()
    • The patch file implementation additionally executes the view to check if the rendered output is empty

    This is significant in the special case of views because as explained 🐛 Empty content view Fixed :

    ViewExecutable will build a render array regardless of whether it has anything to display, because the view is not executed until render time, and hence just checking the render array it not reliable, which is all Element::isEmpty() does.

    The Drupal Core views block display plugin (\Drupal\views\Plugin\views\display\Block::execute()) suggests that the correct way to check is to actually execute the view with arguments, then check $view->getDisplay()->outputIsEmpty(), which is how the plugin implements its "Hide block if the view output is empty" option.

  • 🇺🇸United States joelsteidl

    I can confirm that this patch solved the issue of a View block with empty output. I will take a look at the approach and see if it can be improved.

  • 🇺🇸United States droath

    Upon further reflection on this issue, there are two potential solutions for using Entity Extra Fields to render Views. A developer can implement this using either the Views or the Block plugin within the Entity Extra Field module. I currently do not recommend supporting views being rendered in the block plugin when we have a Views plugin available. I've added some additional code to the Views Plugin within the Entity Extra Field module to address this issue. Please let me know if this addresses the issue you're personally experiencing.

  • 🇺🇸United States droath
  • Status changed to RTBC 3 months ago
  • 🇸🇰Slovakia coaston

    Thank you, your patch works as expected. No issue found. I think it is ready to be merged.

  • Status changed to Needs work 13 days ago
  • 🇩🇪Germany Anybody Porta Westfalica

    @coaston thanks for the RTBC. Could you please create a MR from the patch? Thanks!

  • 🇮🇳India divyansh.gupta Jaipur

    Working on it!!

  • 🇮🇳India divyansh.gupta Jaipur

    Converted the patch to MR,
    please review!!

  • Pipeline finished with Success
    11 days ago
    Total: 140s
    #555561
  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks for the MR. Back to NR, would be nice if someone here could test it (or even better add a test)!

    Code-wise this LGTM, still there might be an impact on performance, as each view is now executed twice? Do we have a way to improve that or are there better ways?
    Otherwise I'd be fine to merge this after review. Thank you! :)

Production build 0.71.5 2024