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

<?php
/*
* 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.

Files: 
CommentFileSizeAuthor
#8 drupal_locked_user_fields_1392852_8.patch503 bytesbulldozer2003
PASSED: [[SimpleTest]]: [MySQL] 39,072 pass(es).
[ View ]
#6 locked_user_fields_error-1392852-6.patch641 bytesShawn DeArmond
PASSED: [[SimpleTest]]: [MySQL] 38,439 pass(es).
[ View ]
#4 locked_user_fields_error-1392852-4.patch651 bytesShawn DeArmond
FAILED: [[SimpleTest]]: [MySQL] Invalid PHP syntax in modules/user/user.module.
[ View ]

Comments

Issue summary:View changes

Fixed typo, missed a single quote.

Priority:Normal» Major

Version:7.10» 7.x-dev
Priority:Major» Normal

I'm getting this same error for the same reason. My error is giving it on line 3648. Using 7.12.

Status:Active» Needs review
StatusFileSize
new651 bytes
FAILED: [[SimpleTest]]: [MySQL] Invalid PHP syntax in modules/user/user.module.
[ View ]

This seems to occur when, as you say, the field is locked.

Here's a patch that worked for me.

Status:Needs review» Needs work

The last submitted patch, locked_user_fields_error-1392852-4.patch, failed testing.

StatusFileSize
new641 bytes
PASSED: [[SimpleTest]]: [MySQL] 38,439 pass(es).
[ View ]

Doh! updated.

Status:Needs work» Needs review

Go, Bot, go!

Title:Notice: Undefined index: instance in user_form_field_ui_field_edit_form_alter() (line 3644 of /modules/user/user.module).User registration form field displays when user field is locked accompanied by error message.
Issue tags:+locked, +user fields, +field_create_instance
StatusFileSize
new503 bytes
PASSED: [[SimpleTest]]: [MySQL] 39,072 pass(es).
[ View ]

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

Status:Needs review» Reviewed & tested by the community

Patch in #6 looks good and works for me. The correct 'This field cannot be editted' text now appears and no more errors ;)

Status:Reviewed & tested by the community» Fixed

Committed #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.

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

Issue summary:View changes

Fixed a Typo.