1 user.module | user_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) |
Implements hook_form_FORM_ID_alter().
Add a checkbox for the 'user_register_form' instance settings on the 'Edit field instance' form.
File
- core/
modules/ user/ user.module, line 3155 - Enables the user registration and login system.
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'] + .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(backdrop_get_path('module', 'user') . '/js/user.js'),
),
);
array_unshift($form['#submit'], 'user_form_field_ui_field_edit_form_submit');
}
}