Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Steps to reproduce
1. Create new article and enter a tag in the 'Tags' autocomplete textfield, say 'Drupal' and save
2. Create another one and begin typing 'Drupal' again. Nothing will be returned.
Instead you'll see this error message in the database
Notice: Undefined index: vid in taxonomy_autocomplete() (line 95 of /Users/swentel/drupalcvs/drupal-head/modules/taxonomy/taxonomy.pages.inc).
When inspecting the $field variable, there is no 'vid' key in the 'allowed settings'.
Array ( [translatable] => 1 [entity_types] => Array ( ) [settings] => Array ( [allowed_values] => Array ( [0] => Array ( [vocabulary] => tags [parent] => 0 ) ) ) [storage] => Array ( [type] => field_sql_storage [settings] => Array ( ) [module] => field_sql_storage [active] => 1 [details] => Array ( [sql] => Array ( [FIELD_LOAD_CURRENT] => Array ( [field_data_field_tags] => Array ( [tid] => field_tags_tid ) ) [FIELD_LOAD_REVISION] => Array ( [field_revision_field_tags] => Array ( [tid] => field_tags_tid ) ) ) ) ) [foreign keys] => Array ( ) [indexes] => Array ( [tid] => Array ( [0] => tid ) ) [id] => 5 [field_name] => field_tags [type] => taxonomy_term_reference [module] => taxonomy [active] => 1 [locked] => 0 [cardinality] => 1 [deleted] => 0 [columns] => Array ( [tid] => Array ( [type] => int [unsigned] => 1 [not null] => ) ) [bundles] => Array ( [node] => Array ( [0] => article ) ) )
Array ( [vocabulary] => tags [parent] => 0 )
Even when deleting the term and create a new one, the same error occurs.
The patch attach fixes the issue, but I'm not sure if this needs to fixed here or in field API in taxonomy_field_settings_form where the 'machine_name' is used.
Comment | File | Size | Author |
---|---|---|---|
#23 | 936836_autocomplete_term_7_0.patch | 3.42 KB | catch |
#21 | test_only.patch | 1.55 KB | catch |
#21 | 936836_autocomplete_term_7.patch | 2.62 KB | catch |
#16 | test_only.patch | 2.62 KB | catch |
#16 | 936836_autocomplete_term_7.patch | 3.42 KB | catch |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedYou're targeting the right area. Allowed values should be using machine names after #881530: Exportability of vocabularies is ruined by taxonomy field's 'allowed values' setting.
Comment #2
webchickNo tests for autocomplete? tsk, tsk.
Comment #3
swentel CreditAttribution: swentel commentedAdded a simple test in TaxonomyTermTestCase at the bottom since that one is working with freetagging - didn't really see the need to create a new testcase because it's a small single test, unless you really want that.
Comment #4
flndr CreditAttribution: flndr commentedI've tested the attached patch (not the simpletest one), now the ajax callback works as expected.
The autocomplete widget now displays the correct results. Although, when a term is selected, it replaces the name in the field with the tid. I suppose thats a different issue.
Comment #5
catchPlease use http://api.drupal.org/api/function/taxonomy_vocabulary_get_names/7 or http://api.drupal.org/api/function/taxonomy_vocabulary_machine_name_load/7 instead of the direct database query.
Comment #6
flndr CreditAttribution: flndr commentedI take back what I said about the selection not working. The above patch works as expected.
I'll make a patch with the above advice from catch in a minute.
Comment #7
Sivaji_Ganesh_Jojodae CreditAttribution: Sivaji_Ganesh_Jojodae commented+1 for #5.
Re-rolled patch #3 with
taxonomy_vocabulary_get_names()
.Comment #8
Sivaji_Ganesh_Jojodae CreditAttribution: Sivaji_Ganesh_Jojodae commentedComment #9
flndr CreditAttribution: flndr commentedThis works for me...
Just started looking at D7 today, so... is there any reason that field_info_field can't return the vid along with the machine name for the vocabulary in the ['allowed values'] key? It looks like thats cached, and would avoid a bunch of queries on the database.
Comment #10
flndr CreditAttribution: flndr commentedComment #11
catch@justinzero: there's no place to put the vid information - this setting was originally changed in #881530: Exportability of vocabularies is ruined by taxonomy field's 'allowed values' setting for the exact reason of keeping the site-specific serial out of field configuration.
I don't think the extra query on the autocomplete path is going to make a huge amount of difference, if it did, we'd need to add caching for taxonomy_vocabulary_get_names().
Comment #12
flndr CreditAttribution: flndr commentedThanks for the info.
My patch should be disregarded over #7.
Comment #13
moshe weitzman CreditAttribution: moshe weitzman commentedRTBC for #7
Comment #14
netov CreditAttribution: netov commentedWhen I try to use filter "Taxonomy: Term ID (with depth)" in Views with option "Autocomplete", I recieve an error.
Log:
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 'taxonomy_vocabulary JOIN tv td.vidtv.vid WHERE (td.name IN ('Дон')) AND (tv' at line 2: SELECT td.* FROM {taxonomy_term_data} td taxonomy_vocabulary JOIN {tv} td.vidtv.vid WHERE (td.name IN (:db_condition_placeholder_0)) AND (tv.machine_name = :db_condition_placeholder_1) ; Array ( [:db_condition_placeholder_0] => Дон [:db_condition_placeholder_1] => _ ) in views_handler_filter_term_node_tid->validate_term_strings() (line 290 of /var/www/bashnabash/sites/all/modules/views/modules/taxonomy/views_handler_filter_term_node_tid.inc).
Comment #15
Damien Tournoud CreditAttribution: Damien Tournoud commentedSo, basically, #881530: Exportability of vocabularies is ruined by taxonomy field's 'allowed values' setting broke the autocomplete.
Sweet, that means we need tests.
Comment #16
catch#7 has tests...
To avoid any more confusion, let's re-upload the patch, also attaching one with just the tests to confirm they actually catch the bug.
@netov: I haven't looked at the views code, but there's two possibilities:
1. the patch here fixes it - please try with it applied.
2. #881530 broke views - in which case this is going to need a companion issue in the views queue, and I'll be further annoyed that it got in without the API change being discussed.
Comment #17
swentel CreditAttribution: swentel commentedThere are tests in 5 and 7
The views autocomplete is probably related in views itself ...
Comment #18
swentel CreditAttribution: swentel commentedAargh, sorry cross post :(
Comment #19
Damien Tournoud CreditAttribution: Damien Tournoud commentedI was actually looking at #9. Sorry for the confusion.
Comment #20
catchTagging being broken is critical.
Comment #21
catchgrr, my vim config is trimming whitespace for some reason, need to fix that.
Comment #23
catchsorry, wtf.
Comment #24
chx CreditAttribution: chx commentedLooks good. taxonomy_vocabulary_get_names is not horribly expensive at all.
Comment #25
webchickCommitted to HEAD. Thanks folks!
Comment #26
netov CreditAttribution: netov commentedPatch of course was done:))
Comment #27
Dave ReidViews taxonomy autocompletion was always broken in D7: #925302: taxonomy_autocomplete() has changed in D7 - expects a field name and not a vid