I've found that the dev release of field_collection fixes one issue I had with the beta4. But it also has one more bug but it was easy to fix. The setup has nothing spectacular, only i18n activated with some of the submodules, no special configuration.

Here is the message I have if I edit a node with a field collection:
Notice: Undefined index: en in field_collection_field_attach_form() (line 1142 of .../sites/all/modules/field_collection/field_collection.module).

Eventually the field in question does not have a specific language and is simply "und" instead of "en". Using the field_language function to get the proper langcode to use fixes the issue.

patch following

Comments

idflood’s picture

Status: Active » Needs review
StatusFileSize
new933 bytes
idflood’s picture

StatusFileSize
new1.02 KB

Found one more issue at the same spot if the field processed is a "container". Here is the notice displayed:
Notice : Undefined offset: 0 dans field_collection_field_attach_form() (ligne 1143 dans .../sites/all/modules/field_collection/field_collection.module).

In this situation the $lang variable is set to FALSE so I added it to the condition.

gmclelland’s picture

#2: undefined_langcode-1716526-2.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, undefined_langcode-1716526-2.patch, failed testing.

The last submitted patch, undefined_langcode-1716526-2.patch, failed testing.

gmclelland’s picture

I'm seeing this as well. In my case, I think it is when I'm using http://drupal.org/project/fape to edit a field that is attached to a node.

Can you re-roll your patch?

jelle_s’s picture

Issue summary: View changes

Also, there should be a check if the field exists in the form, developers can call field_attach_form with a value for 'field_name' in the options argument, if so it is possible that a field is not present:

field_attach_form('my_entity_type', $entity, $form, $form_state, NULL, array('field_name' => 'field_myfield'));
super_romeo’s picture

#7 - same thing

kle’s picture

#7 - same issue

Solution is simple: Change this in field_collection_field_attach_form():

    if ($field['type'] == 'field_collection' && $field['settings']['hide_blank_items']
        && field_access('edit', $field, $entity_type) && $instance['widget']['type'] == 'field_collection_embed') {

to

    if ($field['type'] == 'field_collection' && $field['settings']['hide_blank_items']
        && field_access('edit', $field, $entity_type) && $instance['widget']['type'] == 'field_collection_embed'
        && isset($form[$field_name])) {
barry_fisher’s picture

Status: Needs work » Needs review
StatusFileSize
new996 bytes

Thanks kle

Following on from #9 I've rolled a patch adding the && isset($form[$field_name] against 7.x-1.0-beta8 which works for me.

chris burge’s picture

#10 resolved the issue for me. In my case, the field didn't exist, which caused the error.

japerry’s picture

StatusFileSize
new2.14 KB

The patch in #10 doesn't fully get all the if statements. This following patch adds checks at the top of the loop, which skips looking in the field if none of the conditions are met.

shi99’s picture

The patch in #12 solved the issue for me.

Thanks

ybabel’s picture

Patch #12 works fine but do not apply any more (the lines have changed position 1009 -> 1226)

japerry’s picture

StatusFileSize
new2.24 KB

Here is a re-roll against HEAD as of 2/2/2017. It also works against beta12.

tobiberlin’s picture

I applied that patch against 7.x-1.0-beta12 version and it works like a charme

tobiberlin’s picture

Unfortunately I found out that it does not solve the issue. I create a form in the following way:

$form = array();

  $fields = array(
    'field_name1',
    'field_name2',
    'field_name3',
    'field_name4'
  );

  foreach ($fields as $fieldname) {
    field_attach_form('node', $node, $form, $form_state, NULL, array('field_name' => $fieldname));
  }

It seems that field_collection_field_attach_form() still acts on fields and field collections which should never be added to the form. After applying the patch following error messages appear:

Notice: Undefined index: #language in field_collection_field_attach_form() (line 1242 of \sites\all\modules\contrib\field_collection\field_collection.module).
Notice: Undefined index: in field_collection_field_attach_form() (line 1243 of \sites\all\modules\contrib\field_collection\field_collection.module).
Notice: Undefined index: #language in field_collection_field_attach_form() (line 1261 of \sites\all\modules\contrib\field_collection\field_collection.module).
Notice: Undefined index: in field_collection_field_attach_form() (line 1262 of \sites\all\modules\contrib\field_collection\field_collection.module).
Notice: Undefined index: in field_collection_field_attach_form() (line 1263 of \sites\all\modules\contrib\field_collection\field_collection.module).

They repeat in different order. The node type I want to get the fields from, has some field groups/ collections and fields in it.

tobiberlin’s picture

I found out the problem was in another hook_field_attach_form: https://www.drupal.org/node/2890683

chris burge’s picture

Status: Needs review » Needs work

Patch no longer applies to HEAD.

ericpoir’s picture

StatusFileSize
new1.82 KB

I created undefined_langcode-1716526-20.patch to make it work with the current version of the module.