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.
Comment | File | Size | Author |
---|---|---|---|
content_taxonomy_autocomplete.patch | 1.13 KB | brokentone |
Comments
Comment #1
bschilt CreditAttribution: bschilt commentedI 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...
Comment #2
rooby CreditAttribution: rooby commentedI'm in the same boat as bschilt in terms of code review and time but the patch fixes the errors for me too.
Comment #3
geek-merlin@brokentone : you did a very thorough and good description of the problem and your solution.
i'm seeing the ame warnings with a term field inside a profile2, so i'm guessing it's the same problem.
will try your patch on that.
@brokentone: a hint: use "needs review" as status next time.
Comment #4
geek-merlinthis seems to be solved in current dev.