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.
When saving changes to a field collection at admin/structure/types/manage/article/fields (for the article content type), I'm getting the following notice:
Notice: Undefined index: _weight in field_collection_field_widget_embed_validate() (line 998 of /Users/benkaplan/git/drupal/sites/all/modules/contrib/field_collection/field_collection.module).
The field collection includes a text field, a long text field, and a link field.
Thoughts?
--Ben
Comment | File | Size | Author |
---|---|---|---|
#8 | field_collection-1282566-8.patch | 849 bytes | juampynr |
#7 | field_collection-1282566-7.patch | 691 bytes | tim.plunkett |
#2 | set_weight_to_multiple_field_1282566_2.patch | 594 bytes | juampynr |
Comments
Comment #1
echoz CreditAttribution: echoz commentedI’m getting the same (except with the current dev of 12/15, it’s line 1251). The error goes away on reload, and the settings are seemingly saved without issue. It happens set to unlimited or not.
Comment #2
juampynr CreditAttribution: juampynr commentedAfter checking the code logic, it seems that when the field is edited and then saved, a wrong property ($element['_weight']['#value']) is being used for the weight instead of $element['#weight']. I see that this logic was added at http://drupal.org/node/1142114#comment-4968338.
Attached is a patch to fix the issue. I would appreciate a review.
Comment #3
echoz CreditAttribution: echoz commentedThe patch in #2 resolved the issue for me, that the field collection field can be saved with no error. RTBC?
Comment #4
wjaspers CreditAttribution: wjaspers commentedI'm confused.
Why is the #weight handled by the item's 'delta' in the database?
When the field collection's items are saved, does that mean the entire set gets deleted and re-inserted? Is it revision safe?
Comment #5
juampynr CreditAttribution: juampynr commentedI agree, it looks odd because the actual '_weight' index is set when a Field Collection is removed, but not when it is being saved, hence the warning alerting about the undefined index.
Hope that @tim.plunkett can throw in some light.
Comment #6
tim.plunkettDiscussed with juampy in IRC, this is not the right fix. Also, I could not reproduce.
Specific steps to reproduce should be added to the issue summary.
Comment #7
tim.plunkett$element['_weight']
is added by field_multiple_value_form(), which is called for multivalue fields when editing content. But, the multiple value form is not used by the default values form when editing the content type, so the easiest way to check this is justisset($element['_weight'])
.Comment #8
juampynr CreditAttribution: juampynr commentedThe following condition evaluates to TRUE in multivalued fields, causing the warning to occur:
Here is an updated patch where the isset() statement is evaluated first. I splitted it out to a higher level as the line was getting far too long.
Comment #9
tim.plunkettCommitted, thanks!
http://drupalcode.org/project/field_collection.git/commit/fc02cae