Skip to content

undefined array key error in locale_field_node_form_submit() when moving fields in a hook_form_alter() #6918

@robertgarrigos

Description

@robertgarrigos

Description of the bug

I am using hook_form_alter() to move some fields around the form array, as I need some ajax functionality. My code moves a field from $form['field_name'] to $form['ajax_wrapper']['field_name']. Then just unsets the original $form['field_name'].

locale_field_node_form_submit() function, in locale.module, has this code on line 238:

$previous_langcode = $form[$field_name]['#language'];

which triggers the error because there is not field_name as key of the $form array, as I just unset it.

Besides this error, everything else works as expected. No other backdrop's code complains about a missing key. My ajax is also working.

Using $form['field_name'] = array('#language' => NULL); instead of unsetting the field_name array, in my code, fixes the problem, or even using $form['field_proveidor']['#access'] = FALSE; solves the problem, and the ajax is still working fine.

However, I wonder if it wouldn't be better that locale module just checked the existence of the field_name key before using it. Something like this worked for me:

$previous_langcode = isset($form[$field_name]) ? $form[$field_name]['#language']: '';

Would that be a right approach to address this issue? I am aware that my need is very specific, but, still, the locale module is using a value without any prior checking. Shouldn't this be addressed?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions