Combine fields filter exposed ~ Error: Call to undefined method

Created on 14 June 2024, 3 months ago
Updated 12 July 2024, about 2 months ago

Problem/Motivation

I want to combine multiple fields together and search by them so I have added an exposed filter criteria "Combine fields filter" and added two fields to search by.

When I go to the page and input a value to search - the website throws this error:
"PHP message: Uncaught PHP Exception Error: "Call to undefined method Drupal\views_json_source\Plugin\views\query\ViewsJsonQuery::placeholder()" at /var/www/html/web/core/modules/views/src/Plugin/views/HandlerBase.php line 514"

Is there another way to search by the combined fields?

Steps to reproduce

  1. Create the base "Views JSON Source" by copying the file views.view.views_json_source.yml to your configuration directory and import it.
  2. Enable "Views JSON Source" view
  3. Add an exposed filter criteria "Combine fields filter".
  4. Expose this filter to visitors
  5. Single Filter
  6. Operator: Contains
  7. Choose both "JSON: JSON Field" fields to combine for filtering
  8. Save View
  9. Go to /vjs-example-1
  10. Search by "Sample"
  11. "PHP message: Uncaught PHP Exception Error: "Call to undefined method Drupal\views_json_source\Plugin\views\query\ViewsJsonQuery::placeholder()" at /var/www/html/web/core/modules/views/src/Plugin/views/HandlerBase.php line 514"
πŸ› Bug report
Status

Active

Version

2.0

Component

Module

Created by

πŸ‡ΊπŸ‡ΈUnited States wfairhead

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

Comments & Activities

  • Issue created by @wfairhead
  • πŸ‡ΊπŸ‡ΈUnited States chrisfromredfin Portland, Maine

    Yes, it would seem that in order for Views Json Source to support combined fields filtering, it the ViewsJsonQuery class needs to implement the ::placeholder() method.

    This method is invoked by Drupal core's views HandlerBase for combined fields filters.

  • πŸ‡ΊπŸ‡ΈUnited States chrisfromredfin Portland, Maine

    It's certainly non-trivial to implement the Combine filter for APath/JSONPath, but I don't think impossible. It seems like we could use regex to search the multiple fields selected in the views filter:

    $..[?(@.field1 =~ /.*someword.*/ || @.field2 =~ /.*someword.*/)]
    

    After a little more digging, it seems that at a minimum, placeholder() and addWhereExpression() would need to be implemented. The placeholders would define where to substitute what in the addWhereExpression, which could ultimately hopefully get to specifying the correct APath.

  • πŸ‡ΊπŸ‡ΈUnited States chrisfromredfin Portland, Maine
Production build 0.71.5 2024