Combine fields filter exposed ~ Error: Call to undefined method

Created on 14 June 2024, 5 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

Merge Requests

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
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia samit.310@gmail.com

    samit.310@gmail.com โ†’ made their first commit to this issueโ€™s fork.

  • Pipeline finished with Success
    about 2 months ago
    Total: 153s
    #291280
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia samit.310@gmail.com

    Hi @chrisfromredfin,

    Mean while i have added placeholder() and addWhereExpression() in the MR, now looking the way to add regex to search the multiple fields selected in the views filter.

    Meanwhile, if you can help with some ideas, it would be very helpful.

    Thanks
    Samit K.

Production build 0.71.5 2024