function user_form_field_ui_field_edit_form_alter

Implements hook_form_FORM_ID_alter().

Add a checkbox for the 'user_register_form' instance settings on the 'Edit field instance' form.

File

modules/user/user.module, line 3856

Code

function user_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
    $instance = $form['#instance'];
    if ($instance['entity_type'] == 'user' && !$form['#field']['locked']) {
        $form['instance']['settings']['user_register_form'] = array(
            '#type' => 'checkbox',
            '#title' => t('Display on user registration form.'),
            '#description' => t("This is compulsory for 'required' fields."),
            // Field instances created in D7 beta releases before the setting was
            // introduced might be set as 'required' and 'not shown on user_register
            // form'. We make sure the checkbox comes as 'checked' for those.
'#default_value' => $instance['settings']['user_register_form'] || $instance['required'],
            // Display just below the 'required' checkbox.
'#weight' => $form['instance']['required']['#weight'] + 0.1,
            // Disabled when the 'required' checkbox is checked.
'#states' => array(
                'enabled' => array(
                    'input[name="instance[required]"]' => array(
                        'checked' => FALSE,
                    ),
                ),
            ),
            // Checked when the 'required' checkbox is checked. This is done through
            // a custom behavior, since the #states system would also synchronize on
            // uncheck.
'#attached' => array(
                'js' => array(
                    drupal_get_path('module', 'user') . '/user.js',
                ),
            ),
        );
        array_unshift($form['#submit'], 'user_form_field_ui_field_edit_form_submit');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.