1 user.admin.inc | user_admin_settings($form, &$form_state) |
Form builder; Configure user settings for this site.
Related topics
File
- core/
modules/ user/ user.admin.inc, line 120 - Admin page callbacks for the User module.
Code
function user_admin_settings($form, &$form_state) {
$config = config('system.core');
$form['#config'] = 'system.core';
// User registration settings.
$form['registration_cancellation'] = array(
'#type' => 'fieldset',
'#title' => t('Registration and cancellation'),
'#weight' => -4,
);
$form['registration_cancellation']['user_register'] = array(
'#type' => 'radios',
'#title' => t('Who can register accounts?'),
'#default_value' => $config->get('user_register'),
'#options' => array(
USER_REGISTER_ADMINISTRATORS_ONLY => t('Administrators only'),
USER_REGISTER_VISITORS => t('Visitors'),
USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL => t('Visitors, but administrator approval is required'),
)
);
$form['registration_cancellation']['user_email_verification'] = array(
'#type' => 'checkbox',
'#title' => t('Require email verification when a visitor creates an account'),
'#default_value' => $config->get('user_email_verification'),
'#description' => t('New users will be required to validate their email address prior to logging into the site, and will be assigned a system-generated password. With this setting disabled, users will be logged in immediately upon registering, and may select their own passwords during registration.'),
'#states' => array(
// Hide this checkbox when "Administrators only" is selected.
'invisible' => array(
'input[name="user_register"]' => array('value' => USER_REGISTER_ADMINISTRATORS_ONLY),
),
),
'#indentation' => 1,
);
$form['registration_cancellation']['user_email_match'] = array(
'#type' => 'checkbox',
'#title' => t('When an email address is used as username, require a matching email address'),
'#default_value' => $config->get('user_email_match'),
);
module_load_include('inc', 'user', 'user.pages');
$form['registration_cancellation']['user_cancel_method'] = array(
'#type' => 'item',
'#title' => t('When cancelling a user account'),
'#description' => t('Users with the %select-cancel-method or %administer-users <a href="@permissions-url">permissions</a> can override this default method.', array('%select-cancel-method' => t('Select method for cancelling account'), '%administer-users' => t('Administer user accounts'), '@permissions-url' => url('admin/config/people/permissions'))),
);
$form['registration_cancellation']['user_cancel_method'] += user_cancel_methods();
foreach (element_children($form['registration_cancellation']['user_cancel_method']) as $element) {
// Remove all account cancellation methods that have #access defined, as
// those cannot be configured as default method.
if (isset($form['registration_cancellation']['user_cancel_method'][$element]['#access'])) {
$form['registration_cancellation']['user_cancel_method'][$element]['#access'] = FALSE;
}
// Remove the description (only displayed on the confirmation form).
else {
unset($form['registration_cancellation']['user_cancel_method'][$element]['#description']);
}
}
// Password settings.
$form['password_policy'] = array(
'#type' => 'fieldset',
'#title' => t('Password policy'),
'#weight' => -1,
);
module_load_include('password.inc', 'user', 'user');
$description = _user_password_policy_help();
$form['password_policy']['user_password_reject_weak'] = array(
'#type' => 'checkbox',
'#title' => t('Reject weak passwords'),
'#description' => $description,
'#default_value' => (bool) $config->get('user_password_reject_weak'),
);
// Account settings.
$form['personalization'] = array(
'#type' => 'fieldset',
'#title' => t('Personalization'),
'#weight' => 2,
);
$form['personalization']['user_signatures'] = array(
'#type' => 'checkbox',
'#title' => t('Enable signatures'),
'#default_value' => $config->get('user_signatures'),
);
// If picture support is enabled, check whether the picture directory exists.
$config = config('system.core');
if ($config->get('user_pictures')) {
$picture_path = file_default_scheme() . '://' . config_get('system.core', 'user_picture_path');
if (!file_prepare_directory($picture_path, FILE_CREATE_DIRECTORY)) {
form_set_error('user_picture_path', t('The directory %directory does not exist or is not writable.', array('%directory' => $picture_path)));
watchdog('file system', 'The directory %directory does not exist or is not writable.', array('%directory' => $picture_path), WATCHDOG_ERROR);
}
}
$picture_support = $config->get('user_pictures');
$form['personalization']['user_pictures'] = array(
'#type' => 'checkbox',
'#title' => t('Enable user pictures'),
'#default_value' => $picture_support,
);
backdrop_add_js(backdrop_get_path('module', 'user') . '/js/user.js');
$form['personalization']['pictures'] = array(
'#type' => 'container',
'#states' => array(
// Hide the additional picture settings when user pictures are disabled.
'invisible' => array(
'input[name="user_pictures"]' => array('checked' => FALSE),
),
),
);
$form['personalization']['pictures']['user_picture_path'] = array(
'#type' => 'textfield',
'#title' => t('Picture directory'),
'#default_value' => $config->get('user_picture_path'),
'#size' => 30,
'#maxlength' => 255,
'#description' => t('Subdirectory in the file upload directory where pictures will be stored.'),
);
$form['personalization']['pictures']['user_picture_default'] = array(
'#type' => 'textfield',
'#title' => t('Default picture'),
'#default_value' => $config->get('user_picture_default'),
'#size' => 30,
'#maxlength' => 255,
'#description' => t('URL of picture to display for users with no custom picture selected. Leave blank for none.'),
);
if (module_exists('image')) {
$form['personalization']['pictures']['settings']['user_picture_style'] = array(
'#type' => 'select',
'#title' => t('Picture display style'),
'#options' => image_style_options(TRUE, PASS_THROUGH),
'#default_value' => $config->get('user_picture_style'),
'#description' => t('The style selected will be used on display, while the original image is retained. Styles may be configured in the <a href="!url">Image styles</a> administration area.', array('!url' => url('admin/config/media/image-styles'))),
);
}
$form['personalization']['pictures']['user_picture_dimensions'] = array(
'#type' => 'textfield',
'#title' => t('Picture upload dimensions'),
'#default_value' => $config->get('user_picture_dimensions'),
'#size' => 10,
'#maxlength' => 10,
'#field_suffix' => ' ' . t('pixels'),
'#description' => t('Pictures larger than this will be scaled down to this size.'),
);
$form['personalization']['pictures']['user_picture_file_size'] = array(
'#type' => 'number',
'#title' => t('Picture upload file size'),
'#default_value' => $config->get('user_picture_file_size'),
'#min' => 0,
'#max' => 1000000000,
'#field_suffix' => ' ' . t('KB'),
'#description' => t('Maximum allowed file size for uploaded pictures. Upload size is normally limited only by the PHP maximum post and file upload settings, and images are automatically scaled down to the dimensions specified above.'),
);
$form['personalization']['pictures']['user_picture_guidelines'] = array(
'#type' => 'textarea',
'#title' => t('Picture guidelines'),
'#default_value' => $config->get('user_picture_guidelines'),
'#description' => t("This text is displayed at the picture upload form in addition to the default guidelines. It's useful for helping or instructing your users."),
);
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration')
);
return $form;
}