Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Scenario:
* two vocabularies: functionality and product type. Product type has a term reference field to functionality (field_functionality).
* a content type named products sharing field_functionality and also with a term reference field to product type (field_product_type).
Create a view called "x" and:
1. Added Filter criteria: Taxonomy term: Functionality (field_functionality)
2. Added Filter criteria: Content: Product type (option limit) (field_product_type)
3. Check: Filter criterion: Field: Functionality (field_functionality)
4. Click Apply & continue
5. crash with
An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /admin/structure/views/ajax/config-item-extra/x/page/filter/field_product_type_tid_option_limit
StatusText: Service unavailable (with message)
ResponseText: PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) AND (field_data_field_functionality0.deleted = '0') AND (taxonomy_term_data.v' at line 2: SELECT field_data_field_functionality0.entity_type AS entity_type, field_data_field_functionality0.entity_id AS entity_id, field_data_field_functionality0.revision_id AS revision_id, field_data_field_functionality0.bundle AS bundle
FROM
{field_data_field_functionality} field_data_field_functionality0
INNER JOIN {taxonomy_term_data} taxonomy_term_data ON taxonomy_term_data.tid = field_data_field_functionality0.entity_id
WHERE (field_data_field_functionality0.field_functionality_tid IN ()) AND (field_data_field_functionality0.deleted = :db_condition_placeholder_0) AND (taxonomy_term_data.vid = :db_condition_placeholder_1) AND (field_data_field_functionality0.entity_type = :db_condition_placeholder_2) ; Array
(
[:db_condition_placeholder_0] => 0
[:db_condition_placeholder_1] => 2
[:db_condition_placeholder_2] => taxonomy_term
)
in field_sql_storage_field_storage_query() (line 577 of /var/www/venexma.xsto.info/htdocs-dev2/modules/field/modules/field_sql_storage/field_sql_storage.module).
Comments
Comment #1
jonhattanOn inspecting the SQL I see the error is at
WHERE (field_data_field_functionality0.field_functionality_tid IN ())
I figure out that's caused because of the live preview.
Comment #2
jonhattanFurther testing reveals the error is gone if I
Select terms from vocabulary Functionality
in the first exposed field. Also, It is not related to exposing the filters or not.Now that is not failing, it doesn't work :p
The option-limited exposed field doesn't react to changes in the matching field.
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedyep, same problem here. also if I'm not selecting any terms from dependee filter - I get this (attached png) on the created view page. I'm using 7.x-1.0-beta1
Comment #4
Anonymous (not verified) CreditAttribution: Anonymous commented@jonhattan have you figured out how to fix that issue?
Comment #5
ykyuen CreditAttribution: ykyuen commentedi have the same problem.
Comment #6
Anonymous (not verified) CreditAttribution: Anonymous commentedI guess everyone have it, here the quote from the code)
Comment #7
joachim CreditAttribution: joachim commentedIt's always a good idea to have a browse through the source code when you find a bug ;)
So, is there anyone able to work on a patch for this?
Comment #8
Anonymous (not verified) CreditAttribution: Anonymous commentedUnfortunately I haven't got needed programming skills, all I can is to test a patch on several sites!
Comment #9
Anonymous (not verified) CreditAttribution: Anonymous commentedHey Joachim, could you please make a patch for this? As I understand there's something about 10-30 lines of code need to be added, I can pay for your work time =) Really need this to be done as soon as possible...
Comment #10
joachim CreditAttribution: joachim commentedCould someone try this patch please?
You'll need the latest version from git to apply it on, as I've made other fixes there today too.
Comment #11
Anonymous (not verified) CreditAttribution: Anonymous commentedJust tested it. Exposed filter (with option limit) is limiting only when I'm selecting value from matching field and applying it with a button, otherwise it doesn't react to changes in matching field and stays empty.
Comment #12
jonhattanI confirm #11. It lacks ajax, that's the big challenge here.
Also, when using it as a exposed filters, there're two warnings because the filter values are not set on first page load. I fixed it with isset() in attached patch.
Comment #13
joachim CreditAttribution: joachim commentedAjax inside Views form is going to be a nightmare.
I briefly tried with D7 core #ajax and it doesn't do anything at all.
Comment #14
jonhattanAjax and views are not my forte.
I did try to accomodate the exposed form to leverage the code in the hook_form_alter and it simple does nothing. Attached the patch for reference, although it's mostly garbage.
In the following comment I'll comment out about the patch.
Comment #15
jonhattanSorry wrong patch. Here it goes.
Comment #16
jonhattanFor this patch to "work" (not raise any warning) the filter identifiers must be changed to meet the field name, so for example an auto assigned value of
field_functionality_tid
must be changed tofield_functionality
andfield_product_type_tid_option_limit
renamed tofield_product_type
.This is so because the hook_form_alter implementation wants the form items to be named the same as the fields. It was just a proof. The idea I had in mind is to refactor the hook_form_alter once I got it working with this scam.
This is the quick way I found to get the other field. Perhaps there's an api for that?
The comment says it all. It would be no longer a problem if I don't try to leverage hook_form_alter.
I found no way to get the bundle.
Comment #17
jonhattanThis issue explains a way to do ajax within exposed filters form #1183418: Ajax attached to exposed filters in form_alter doesn't trigger callback
Comment #18
joachim CreditAttribution: joachim commentedThanks for the fix to my patch in #12!
I want to go for a slightly different approach of $match_values always being populated.
Committing this patch.
Issue #1532124 by jonhattan, joachim: Fixed error in views with exposed filters as controllers.
Let's move the AJAX stuff to another issue (that is, if anyone's got the stomach for it!). Marking this as closed.