I received the following error when I went to http://example.com/admin/config/people/accounts/fields/example_field
Notice: Undefined index: instance in user_form_field_ui_field_edit_form_alter() (line 3644 of /modules/user/user.module).
The reason I received this error was because I pragmatically created a field for a user where locked is TRUE
/*
* Returns the fields
*/
function example_fields() {
return array(
array(
'field_name' => 'example_field',
'type' => 'text',
'locked' => TRUE,
'settings' => array(
'no_ui' => TRUE,
'max_length' => 100,
),
),
);
}
/*
* Returns the field instances
*/
function example_instances() {
return array(
array(
'field_name' => 'example_field',
'entity_type' => 'user',
'bundle' => 'user',
'label' => 'Example Field',
'widget' => array(
'settings' => array(
'size' => 100,
),
),
),
);
}
/**
* Implements hook_install().
*/
function example_install() {
// Create the subscriber fields
foreach (example_fields() as $field) {
field_create_field($field);
}
foreach (example_instances() as $instance) {
field_create_instance($instance);
}
}
/**
* Implements hook_uninstall().
*/
function example_uninstall() {
foreach (example_instances() as $instance) {
field_delete_instance($instance);
}
}
If I change locked to FALSE then I stop receiving the error.
Comments
Comment #0.0
davidwbarratt commentedFixed typo, missed a single quote.
Comment #1
davidwbarratt commentedComment #2
davidwbarratt commentedComment #3
jazzdrive3 commentedI'm getting this same error for the same reason. My error is giving it on line 3648. Using 7.12.
Comment #4
shawn dearmond commentedThis seems to occur when, as you say, the field is locked.
Here's a patch that worked for me.
Comment #6
shawn dearmond commentedDoh! updated.
Comment #7
shawn dearmond commentedGo, Bot, go!
Comment #8
bulldozer2003My patch looks for the locked setting and returns before the function does anything else. Displaying the registration form field checkbox is fruitless since you cannot submit the setting.
When adding required locked fields to user entities programattically, you need to be sure to set $instance['settings']['user_register_form'] to TRUE as well! Otherwise the field will not be displayed on the registration form nor will you be able to set the option through the UI.
Comment #9
FreekVR commentedPatch in #6 looks good and works for me. The correct 'This field cannot be editted' text now appears and no more errors ;)
Comment #10
David_Rothstein commentedCommitted #6 to 7.x - thanks! http://drupalcode.org/project/drupal.git/commit/922166f
(#8 looks like it would have been good too, but I went with #6 since that's the one that got some manual testing by @FreekVR.)
Note: This doesn't seem to be an issue in Drupal 8.
Comment #11.0
(not verified) commentedFixed a Typo.