Problem/Motivation

The current implementation only checks if results are empty and if they are, the view is hidden.

This is sadly incorrect and prevents this module from working with (required) exposed filters! The check has to be extended to check if there are exposed filters. In that case the view may not be hidden but instead shown with the form.

A typical use case would be if the required exposed filter option / better exposed filters is used in views or if the view returns empty results for a prefilled search.

Currently the module is unusable in that case.

Steps to reproduce

  1. Create a view with exposed filters
  2. Reference it via viewsreference
  3. Set "Advanced: Exposed Form" to "Input required" (admin/structure/views/nojs/display/EXAMPLEVIEW/default/exposed_form)
  4. Result: View is always hidden in viewsreference

Workaround

As a dirty workaround you can add a placeholder text in "Empty results behaviour" area. Then the view is shown, but of course that's no valid solution and until you find this workaround you've lost hours. :)

Proposed resolution

  • Add check to hide the view if results are empty and there are no exposed filters
  • Optionally add an option "Hide empty view" which is enabled by default for maximum flexibility.

Remaining tasks

Discuss
Implement
Test
Release

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Anybody created an issue. See original summary.

anybody’s picture

Issue summary: View changes

anybody’s picture

Status: Active » Needs review

The given MR should fix the issue. Anyway it would make sense if someone could check why the existing check

!empty($view->empty)

is not enough. PERHAPS that might be an upstream issue. But even if, the given patch should not make things worse.

Please review. For us this patch fixes the described issue.

If someone needs the patch until this is fixed, this is the URL:
https://git.drupalcode.org/project/viewsreference/-/merge_requests/3.patch

anybody’s picture

seanB made their first commit to this issue’s fork.

seanb’s picture

Status: Needs review » Fixed

Makes sense. Thanks.

anybody’s picture

Thank you very much @seanB :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.