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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

echoz’s picture

I’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.

juampynr’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
594 bytes

After 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.

echoz’s picture

Status: Active » Reviewed & tested by the community

The patch in #2 resolved the issue for me, that the field collection field can be saved with no error. RTBC?

wjaspers’s picture

Status: Needs review » Reviewed & tested by the community

I'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?

juampynr’s picture

I 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.

tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs work

Discussed 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.

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
691 bytes

$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 just isset($element['_weight']).

juampynr’s picture

The following condition evaluates to TRUE in multivalued fields, causing the warning to occur:

if ($field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED)

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.

tim.plunkett’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.