Download & Extend

Errors when deny new autocomplete terms used with field collections

Project:Content Taxonomy
Version:7.x-1.x-dev
Component:Autocomplete - Freetagging
Category:bug report
Priority:minor
Assigned:Unassigned
Status:reviewed & tested by the community

Issue Summary

First off, forgive me if I'm doing things wrong here, this is my first post as well as my first patch.

Steps to reproduce:
Download and enable latest of each content taxonomy (7.x-1.x-dev | Jun, 22) and field collection (7.x-1.0-beta2 | Aug, 18)
Create a content type with a field collection
Create a sample vocabulary and add a few sample terms
Add a term reference field with a tagging widget
Click "Deny any new terms" in the field settings
Create new content with a term other than one previously created

Expected results:
Content creation to be halted and returned to form with an error message denying the addition.

Actual results:
Content is added with new term and PHP errors displayed (okay, notice and warning, but you knew what I meant!)

Notice: Undefined index: field_ing_unit in content_taxonomy_autocomplete_validate_deny_new_terms() (line 125 of /Users/admin/Documents/workspace/drupal7.modules-contrib/trunk/content_taxonomy/content_taxonomy_autocomplete.module).
Warning: Invalid argument supplied for foreach() in content_taxonomy_autocomplete_validate_deny_new_terms() (line 125 of /Users/admin/Documents/workspace/drupal7.modules-contrib/trunk/content_taxonomy/content_taxonomy_autocomplete.module).

Explanation:
This is a result of the way field collections (and possibly other special special fields?) are structured within $form_state. The actual fields are not immediate children of the '#values' but are within their respective field collection (possibly even a few levels deep if you're like me. However, content_taxonomy_autocomplete_validate_deny_new_terms is assuming that all the fields are immediate children.

Solution:
If the element var has parents, then we drill into the $form_state for the actual element before checking whether the tid is to be created or not. Perhaps there is a better way to do this than iteratively drilling down into the array, if so I would love to see it.

AttachmentSize
content_taxonomy_autocomplete.patch1.13 KB

Comments

#1

Status:patch (to be ported)» reviewed & tested by the community

I was experiencing the exact same problem. I have a series of taxonomy vocabularies in a fieldset, each of them has "deny any new terms" selected. I applied the patch and the warnings went away. I spent zero time looking into the code for the problem or the solution b/c I'm on a tight deadline. So I don't know if there is a better way of handling this. My problem is now gone, so I'm moving on...

#2

I'm in the same boat as bschilt in terms of code review and time but the patch fixes the errors for me too.

nobody click here