Problem/Motivation

jsonapi_views_views_preview_info_alter() is checking for exposed filters by field name instead of by identifier.

When previewing a JSON:API Views -enabled view with an exposed filter, the log shows warnings like the following for each exposed filter:

Warning: Undefined array key "created" in jsonapi_views_views_preview_info_alter() (line 43 of web/modules/contrib/jsonapi_views/jsonapi_views.module)

Steps to reproduce

  1. Create a view on nodes and ensure that "Exposed via JSON:API" is set to "Yes".
  2. Add a filter on a node field, make it exposed, and set its [required] "Filter identifier".
  3. Preview the view below.

The filter won't show up in the URL in the "JSON:API Views", and there will be a warning like the above in the site log.

Proposed resolution

Check for filter identifier instead of just field name.

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

jeffschuler created an issue. See original summary.

jeffschuler’s picture

Assigned: jeffschuler » Unassigned
Status: Active » Needs review
StatusFileSize
new915 bytes
jeffschuler’s picture

Missed an isset().

< +        if ($input[$param]) {
---
> +        if (isset($input[$param])) {
nuuou’s picture

+1 on this. Ran into this exact same issue on a handful of projects, and this fixed it for me!

anybody’s picture

Issue tags: +Needs tests, +Novice

@jeffschuler thanks, this is an important fix! Could someone maybe turn the patch from #3 into a MR and add tests?

anybody’s picture

Turned #3 into a MR to speed things up.

anybody’s picture

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

  • deciphered committed eabd6bbf on 8.x-1.x
    test(#3376193): cover exposed filter identifier in preview URL
    

deciphered’s picture

Status: Needs review » Fixed

Thanks all, this is fixed and committed for the upcoming 8.x-1.2 release.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.