diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 843ed78..7fdb5b7 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -966,6 +966,17 @@ function system_menu() { 'file' => 'system.admin.inc', 'weight' => -20, ); + // TODO: move mail to system completely. + $items['admin/config/system/mail'] = array( + 'title' => 'E-mail templates', + 'description' => 'Configure Drupal system e-mail templates.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('user_admin_mail_settings'), + 'access arguments' => array('administer site configuration'), + 'file' => '../user/user.admin.inc', + 'weight' => -19, + ); + $items['admin/config/system/cron'] = array( 'title' => 'Cron', 'description' => 'Manage automatic site maintenance tasks.', @@ -973,7 +984,7 @@ function system_menu() { 'page arguments' => array('system_cron_settings'), 'access arguments' => array('administer site configuration'), 'file' => 'system.admin.inc', - 'weight' => 20, + 'weight' => 18, ); // Additional categories $items['admin/config/user-interface'] = array( diff --git a/core/modules/user/config/user.settings.yml b/core/modules/user/config/user.settings.yml index b4c8a58..d4e3989 100644 --- a/core/modules/user/config/user.settings.yml +++ b/core/modules/user/config/user.settings.yml @@ -14,3 +14,6 @@ register: visitors signatures: '0' cancel_method: user_cancel_block password_reset_timeout: '86400' +advanced_config: '0' +site_access_profile: 'moderated' +site_access_profile_config: '1' diff --git a/core/modules/user/user.admin.inc b/core/modules/user/user.admin.inc index f4363cf..73581ed 100644 --- a/core/modules/user/user.admin.inc +++ b/core/modules/user/user.admin.inc @@ -235,7 +235,7 @@ function user_admin_account() { } /** - * Submit the user administration update form. + * Form submission handler for user_admin_account_settings(). */ function user_admin_account_submit($form, &$form_state) { $operations = module_invoke_all('user_operations', $form, $form_state); @@ -264,66 +264,226 @@ function user_admin_account_validate($form, &$form_state) { } /** - * Form builder; Configure user settings for this site. + * Form builder; Configure account workflow settings for this site. * * @ingroup forms - * @see user_admin_settings_submit() + * @see user_admin_workflow_settings_submit() */ -function user_admin_settings($form, &$form_state) { +function user_admin_workflow_settings($form, &$form_state) { $config = config('user.settings'); - $mail_config = config('user.mail'); - // Settings for anonymous users. - $form['anonymous_settings'] = array( - '#type' => 'fieldset', - '#title' => t('Anonymous users'), - ); - $form['anonymous_settings']['anonymous'] = array( - '#type' => 'textfield', - '#title' => t('Name'), - '#default_value' => $config->get('anonymous'), - '#description' => t('The name used to indicate anonymous users.'), - '#required' => TRUE, - ); + switch ($config->get('advanced_config')) { + case FALSE: + $form['access_profile'] = array( + '#type' => 'fieldset', + '#title' => t('Site access profile'), + ); + $profiles = array(); + foreach (module_invoke_all('user_site_access_profiles') as $profile => $array) { + $profiles[$profile] = $array['label']; + } + // Render the site access profile selector. + $form['access_profile']['user_site_access_profile'] = array( + '#type' => 'select', + '#default_value' => $config->get('site_access_profile'), + '#options' => $profiles, + '#description' => t('Select the access profile your site will be operating in. If you are a solo blogger, you might want to select Single person blog, if you run a forum, Public site (moderated) might be the one for you. See the manual for a detailed explanation on all available profiles.'), + ); - // Administrative role option. - $form['admin_role'] = array( - '#type' => 'fieldset', - '#title' => t('Administrator role'), - ); + $form['advanced_config'] = array( + '#type' => 'fieldset', + '#title' => t('Advanced configuration'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#group' => 'settings', + '#attributes' => array( + 'class' => array('advanced-config-form-information'), + ), + ); + // Render the advanced config checkbox. + $form['advanced_config']['user_advanced_config'] = array( + '#type' => 'checkbox', + '#title' => t('Enable advanced configuration.'), + '#default_value' => $config->get('advanced_config'), + '#description' => t('This enables the advanced workflow configuration mode.'), + ); + break; - // Do not allow users to set the anonymous or authenticated user roles as the - // administrator role. - $roles = user_roles(); - unset($roles[DRUPAL_ANONYMOUS_RID]); - unset($roles[DRUPAL_AUTHENTICATED_RID]); - $roles[0] = t('disabled'); + case TRUE: + $form['settings'] = array( + '#type' => 'vertical_tabs', + '#title' => t('Registration workflow settings'), + ); + $form['config_settings'] = array( + '#type' => 'fieldset', + '#title' => t('Advanced settings'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#group' => 'settings', + '#attributes' => array( + 'class' => array('configuration-settings-global-config-form-information'), + ), + ); + // Settings for anonymous users. + $form['config_settings']['anonymous'] = array( + '#type' => 'textfield', + '#title' => t('Name'), + '#default_value' => $config->get('anonymous'), + '#description' => t('The name used to indicate anonymous users.'), + '#required' => TRUE, + ); + // Do not allow users to set the anonymous or authenticated + // user roles as the administrator role. + $roles = user_roles(); + unset($roles[DRUPAL_ANONYMOUS_RID]); + unset($roles[DRUPAL_AUTHENTICATED_RID]); + $roles[0] = t('disabled'); + + $form['config_settings']['user_admin_role'] = array( + '#type' => 'select', + '#title' => t('Administrator role'), + '#default_value' => $config->get('admin_role'), + '#options' => $roles, + '#description' => t('This role will be automatically assigned new permissions whenever a module is enabled. Changing this setting will not affect existing permissions.'), + ); + // Render the advanced config checkbox. + $form['config_settings']['user_advanced_config'] = array( + '#type' => 'checkbox', + '#title' => t('Enable advanced configuration.'), + '#default_value' => $config->get('advanced_config'), + '#description' => t('This enables the advanced workflow configuration mode.'), + ); - $form['admin_role']['user_admin_role'] = array( - '#type' => 'select', - '#title' => t('Administrator role'), - '#default_value' => $config->get('admin_role'), - '#options' => $roles, - '#description' => t('This role will be automatically assigned new permissions whenever a module is enabled. Changing this setting will not affect existing permissions.'), - ); + $limits = array( + 'global' => array( + 'key' => 'user_admin_account_settings_form', + 'description' => '', + ), + ); + $form['global_limits'] = array( + '#type' => 'fieldset', + '#title' => 'Global limits', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#group' => 'settings', + ); + break; - // @todo Remove this check once language settings are generalized. - if (module_exists('translation_entity')) { - $form['language'] = array( - '#type' => 'fieldset', - '#title' => t('Language settings'), - '#tree' => TRUE, - ); - $form_state['translation_entity']['key'] = 'language'; - $form['language'] += translation_entity_enable_widget('user', 'user', $form, $form_state); } - // User registration settings. - $form['registration_cancellation'] = array( + return system_config_form($form, $form_state); +} + +/** + * Form submission handler for user_admin_workflow_settings(). + */ +function user_admin_workflow_settings_submit($form, &$form_state) { + $config = config('user.settings'); + + switch ($config->get('advanced_config')) { + case FALSE: + $site_access_profile = $config->get('site_access_profile'); + + // Get available access profiles. + $site_access_profiles = module_invoke_all('user_site_access_profiles'); + + // If the profile is updated. + if (($site_access_profile != $form_state['values']['user_site_access_profile']) && (array_key_exists($form_state['values']['user_site_access_profile'], $site_access_profiles))) { + + // Set simple site config according to site access profile setting. + switch ($form_state['values']['user_site_access_profile']) { + // Single person blog site. + case 'single': + $register = 'admin_only'; + $verify_mail = 1; + break; + + // Public site (moderated). + case 'moderated': + $register = 'visitors_admin_approval'; + $verify_mail = 1; + break; + + // Public site (let loose). + case 'public': + $register = 'visitors'; + $verify_mail = 1; + break; + + // Closed site (to the public). + case 'closed': + $register = 'admin_only'; + $verify_mail = 0; + break; + + } + + if ($form_state['values']['user_site_access_profile'] == 'closed') { + // Remove access permission to content for anonymous user. + user_role_revoke_permissions('anonymous', array('access content')); + } + // Grant or ungrant access to content depending on the selected profile. + elseif ($form_state['values']['user_site_access_profile'] == ('single' || 'moderated' || 'public')) { + // Grant access permission to content for anonymous user. + user_role_grant_permissions('anonymous', array('access content')); + } + + // Save the settings. + config('user.settings') + ->set('register', $register) + ->set('verify_mail', $verify_mail) + ->set('site_access_profile', $form_state['values']['user_site_access_profile']) + ->save(); + } + break; + + case TRUE: + config('user.settings') + ->set('anonymous', $form_state['values']['anonymous']) + ->set('admin_role', $form_state['values']['user_admin_role']) + ->save(); + break; + + } + + // If the advanced config has been (un)checked. + if ($config->get('advanced_config') != $form_state['values']['user_advanced_config']) { + + // Save advanced config variable. + config('user.settings') + ->set('advanced_config', $form_state['values']['user_advanced_config']) + ->save(); + + // Clear all menu cache. + menu_cache_clear_all(); + } +} + +/** + * Form builder; Configure registration settings for this site. + * + * @ingroup forms + * @see user_admin_registration_settings_submit() + */ +function user_admin_registration_settings($form, &$form_state) { + $config = config('user.settings'); + + $form['registration'] = array( + '#type' => 'vertical_tabs', + '#title' => t('Registration workflow settings'), + ); + + $form['registration_settings'] = array( '#type' => 'fieldset', - '#title' => t('Registration and cancellation'), + '#title' => 'Registration settings', + '#collapsible' => TRUE, + '#collapsed' => FALSE, + '#group' => 'registration', + '#attributes' => array( + 'class' => array('registration-config-form-information'), + ), ); - $form['registration_cancellation']['user_register'] = array( + $form['registration_settings']['user_register'] = array( '#type' => 'radios', '#title' => t('Who can register accounts?'), '#default_value' => $config->get('register'), @@ -331,121 +491,279 @@ function user_admin_settings($form, &$form_state) { 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( + $form['registration_settings']['user_email_verification'] = array( '#type' => 'checkbox', '#title' => t('Require e-mail verification when a visitor creates an account.'), '#default_value' => $config->get('verify_mail'), - '#description' => t('New users will be required to validate their e-mail 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.') + '#description' => t('New users will be required to validate their e-mail 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.'), + ); + + $form['registration_limits'] = array( + '#type' => 'fieldset', + '#title' => 'Registration limits', + '#collapsible' => TRUE, + '#collapsed' => FALSE, + '#group' => 'registration', + '#attributes' => array( + 'class' => array('registration-limits-form-information'), + ), + ); + + $form['registration_contrib_settings'] = array( + '#type' => 'fieldset', + '#title' => 'Registration extentions', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#group' => 'registration', + '#attributes' => array( + 'class' => array('registration-config-form-information'), + ), + ); + + return system_config_form($form, $form_state); +} + +/** + * Form validation handler for user_admin_registration_settings(). + */ +function user_admin_registration_settings_validate($form, &$form_state) { +} + +/** + * Form submission handler for user_admin_registration_settings(). + */ +function user_admin_registration_settings_submit($form, &$form_state) { + config('user.settings') + ->set('register', $form_state['values']['user_register']) + ->set('verify_mail', $form_state['values']['user_email_verification']) + ->save(); +} + +/** + * Form builder; Configure registration settings for this site. + * + * @ingroup forms + * @see user_admin_authentication_settings_submit() + */ +function user_admin_authentication_settings($form, &$form_state) { + $config = config('user.settings'); + + $form['authentication'] = array( + '#type' => 'vertical_tabs', + '#title' => t('Authentication workflow settings'), + ); + + $form['authentication_settings'] = array( + '#type' => 'fieldset', + '#title' => 'Authentication settings', + '#collapsible' => TRUE, + '#collapsed' => FALSE, + '#group' => 'authentication', + '#attributes' => array( + 'class' => array('authentication-config-form-information'), + ), + ); + + $form['authentication_limits'] = array( + '#type' => 'fieldset', + '#title' => 'Authentication limits', + '#collapsible' => TRUE, + '#collapsed' => FALSE, + '#group' => 'authentication', + '#attributes' => array( + 'class' => array('authentication-config-form-information'), + ), + ); + + $form['authentication_contrib_settings'] = array( + '#type' => 'fieldset', + '#title' => 'Authentication extentions', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#group' => 'authentication', + '#attributes' => array( + 'class' => array('authentication-config-form-contrib-information'), + ), + ); + + return system_config_form($form, $form_state); +} + +/** + * Form validation handler for user_admin_authentication_settings(). + */ +function user_admin_authentication_settings_validate($form, &$form_state) { +} + +/** + * Form submission handler for user_admin_authentication_settings(). + */ +function user_admin_authentication_settings_submit($form, &$form_state) { +} + +/** + * Form builder; Configure registration settings for this site. + * + * @ingroup forms + * @see user_admin_cancellation_settings_submit() + */ +function user_admin_cancellation_settings($form, &$form_state) { + $config = config('user.settings'); + + $form['cancellation'] = array( + '#type' => 'vertical_tabs', + '#title' => t('Cancellation settings'), + ); + $form['cancellation_settings'] = array( + '#type' => 'fieldset', + '#title' => 'Cancellation settings', + '#collapsible' => TRUE, + '#collapsed' => FALSE, + '#group' => 'cancellation', + '#attributes' => array( + 'class' => array('cancellation-config-form-information'), + ), ); module_load_include('inc', 'user', 'user.pages'); - $form['registration_cancellation']['user_cancel_method'] = array( + $form['cancellation_settings']['user_cancel_method'] = array( '#type' => 'item', '#title' => t('When cancelling a user account'), '#default_value' => $config->get('cancel_method'), - '#description' => t('Users with the %select-cancel-method or %administer-users permissions can override this default method.', array('%select-cancel-method' => t('Select method for cancelling account'), '%administer-users' => t('Administer users'), '@permissions-url' => url('admin/people/permissions'))), + '#description' => t('Users with the %select-cancel-method or %administer-users permissions can override this default method.', + array( + '%select-cancel-method' => t('Select method for cancelling account'), + '%administer-users' => t('Administer users'), + '@permissions-url' => url('admin/people/permissions'), + ) + ), ); - $form['registration_cancellation']['user_cancel_method'] += user_cancel_methods(); - foreach (element_children($form['registration_cancellation']['user_cancel_method']) as $element) { + $form['cancellation_settings']['user_cancel_method'] += user_cancel_methods(); + foreach (element_children($form['cancellation_settings']['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; + if (isset($form['cancellation_settings']['user_cancel_method'][$element]['#access'])) { + $form['cancellation_settings']['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']); + unset($form['cancellation_settings']['user_cancel_method'][$element]['#description']); } } - // Account settings. - $form['personalization'] = array( + $form['cancellation_limits'] = array( '#type' => 'fieldset', - '#title' => t('Personalization'), - ); - $form['personalization']['user_signatures'] = array( - '#type' => 'checkbox', - '#title' => t('Enable signatures.'), - '#default_value' => $config->get('signatures'), - ); - // If picture support is enabled, check whether the picture directory exists. - if (variable_get('user_pictures', 0)) { - $picture_path = file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures'); - 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 = variable_get('user_pictures', 0); - $form['personalization']['user_pictures'] = array( - '#type' => 'checkbox', - '#title' => t('Enable user pictures.'), - '#default_value' => $picture_support, - ); - $form['#attached']['library'][] = array('user', 'drupal.user'); - $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), - ), + '#title' => 'Cancellation limits', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#group' => 'cancellation', + '#attributes' => array( + 'class' => array('cancellation-config-form-information'), ), ); - $form['personalization']['pictures']['user_picture_path'] = array( - '#type' => 'textfield', - '#title' => t('Picture directory'), - '#default_value' => variable_get('user_picture_path', 'pictures'), - '#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' => variable_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.'), + + $form['cancellation_contrib_settings'] = array( + '#type' => 'fieldset', + '#title' => 'Cancellation extentions', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#group' => 'cancellation', + '#attributes' => array( + 'class' => array('cancellation-config-form-contrib-information'), + ), ); - if (module_exists('image')) { - $form['personalization']['pictures']['settings']['user_picture_style'] = array( - '#type' => 'select', - '#title' => t('Picture display style'), - '#options' => image_style_options(TRUE), - '#default_value' => variable_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 Image styles 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' => variable_get('user_picture_dimensions', '85x85'), - '#size' => 10, - '#maxlength' => 10, - '#field_suffix' => ' ' . t('pixels'), - '#description' => t('Pictures larger than this will be scaled down to this size.'), + + return system_config_form($form, $form_state); +} + +/** + * Form validation handler for user_admin_cancellation_settings(). + */ +function user_admin_cancellation_settings_validate($form, &$form_state) { +} + +/** + * Form submission handler for user_admin_cancellation_settings(). + */ +function user_admin_cancellation_settings_submit($form, &$form_state) { + config('user.settings') + ->set('cancel_method', $form_state['values']['user_cancel_method']) + ->save(); +} + +/** + * Form builder; Configure pass_reset settings for this site. + * + * @ingroup forms + * @see user_admin_pass_reset_settings_submit() + */ +function user_admin_pass_reset_settings($form, &$form_state) { + $config = config('user.settings'); + + $form['pass_reset'] = array( + '#type' => 'vertical_tabs', + '#title' => t('Password reset settings'), ); - $form['personalization']['pictures']['user_picture_file_size'] = array( - '#type' => 'number', - '#title' => t('Picture upload file size'), - '#default_value' => variable_get('user_picture_file_size', '30'), - '#min' => 0, - '#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['pass_reset_settings'] = array( + '#type' => 'fieldset', + '#title' => 'Password reset settings', + '#collapsible' => TRUE, + '#collapsed' => FALSE, + '#group' => 'pass_reset', + '#attributes' => array( + 'class' => array('pass-reset-config-form-information'), + ), ); - $form['personalization']['pictures']['user_picture_guidelines'] = array( - '#type' => 'textarea', - '#title' => t('Picture guidelines'), - '#default_value' => variable_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['pass_reset_limits'] = array( + '#type' => 'fieldset', + '#title' => 'Password reset limits', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#group' => 'pass_reset', + '#attributes' => array( + 'class' => array('pass-reset-config-form-information'), + ), ); - $form['email_title'] = array( - '#type' => 'item', - '#title' => t('E-mails'), + $form['pass_reset_contrib_settings'] = array( + '#type' => 'fieldset', + '#title' => 'Password reset extentions', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#group' => 'pass_reset', + '#attributes' => array( + 'class' => array('pass-reset-config-form-contrib-information'), + ), ); + + return system_config_form($form, $form_state); +} + +/** + * Form validation handler for user_admin_pass_reset_settings(). + */ +function user_admin_pass_reset_settings_validate($form, &$form_state) { +} + +/** + * Form submission handler for user_admin_pass_reset_settings(). + */ +function user_admin_pass_reset_settings_submit($form, &$form_state) { +} + +/** + * Form builder; Configure e-mail templates for this site. + * + * @ingroup forms + * @see user_admin_mail_settings_submit() + */ +function user_admin_mail_settings($form, &$form_state) { + $config = config('user.settings'); + $mail_config = config('user.mail'); + $form['email'] = array( '#type' => 'vertical_tabs', ); @@ -668,16 +986,10 @@ function user_admin_settings($form, &$form_state) { } /** - * Form submission handler for user_admin_settings(). + * Form submission handler for user_admin_mail_settings(). */ -function user_admin_settings_submit($form, &$form_state) { +function user_admin_mail_settings_submit($form, &$form_state) { config('user.settings') - ->set('anonymous', $form_state['values']['anonymous']) - ->set('admin_role', $form_state['values']['user_admin_role']) - ->set('register', $form_state['values']['user_register']) - ->set('verify_mail', $form_state['values']['user_email_verification']) - ->set('signatures', $form_state['values']['user_signatures']) - ->set('cancel_method', $form_state['values']['user_cancel_method']) ->set('notify.status_activated', $form_state['values']['user_mail_status_activated_notify']) ->set('notify.status_blocked', $form_state['values']['user_mail_status_blocked_notify']) ->set('notify.status_canceled', $form_state['values']['user_mail_status_canceled_notify']) @@ -703,6 +1015,122 @@ function user_admin_settings_submit($form, &$form_state) { } /** + * Form builder; Configure user settings for this site. + * + * @ingroup forms + * @see user_admin_settings_submit() + */ +function user_admin_settings($form, &$form_state) { + $config = config('user.settings'); + + // @todo Remove this check once language settings are generalized. + if (module_exists('translation_entity')) { + $form['language'] = array( + '#type' => 'fieldset', + '#title' => t('Language settings'), + '#tree' => TRUE, + ); + $form_state['translation_entity']['key'] = 'language'; + $form['language'] += translation_entity_enable_widget('user', 'user', $form, $form_state); + } + + // Account settings. + $form['personalization'] = array( + '#type' => 'fieldset', + '#title' => t('Personalization'), + ); + $form['personalization']['user_signatures'] = array( + '#type' => 'checkbox', + '#title' => t('Enable signatures.'), + '#default_value' => $config->get('signatures'), + ); + // If picture support is enabled, check whether the picture directory exists. + if (variable_get('user_pictures', 0)) { + $picture_path = file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures'); + 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 = variable_get('user_pictures', 0); + $form['personalization']['user_pictures'] = array( + '#type' => 'checkbox', + '#title' => t('Enable user pictures.'), + '#default_value' => $picture_support, + ); + $form['#attached']['library'][] = array('user', 'drupal.user'); + $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' => variable_get('user_picture_path', 'pictures'), + '#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' => variable_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), + '#default_value' => variable_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 Image styles 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' => variable_get('user_picture_dimensions', '85x85'), + '#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' => variable_get('user_picture_file_size', '30'), + '#min' => 0, + '#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' => variable_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."), + ); + + return system_config_form($form, $form_state); +} + +/** + * Form submission handler for user_admin_settings(). + */ +function user_admin_settings_submit($form, &$form_state) { + config('user.settings') + ->set('signatures', $form_state['values']['user_signatures']) + ->set('pictures', $form_state['values']['user_pictures']) + ->save(); +} + +/** * Menu callback: administer permissions. * * @ingroup forms diff --git a/core/modules/user/user.api.php b/core/modules/user/user.api.php index 648cc0f..8ef5653 100644 --- a/core/modules/user/user.api.php +++ b/core/modules/user/user.api.php @@ -476,5 +476,50 @@ function hook_user_role_delete($role) { } /** + * Create basic site access profiles. + * + * This hook creates an array of site user profile modes. A profile is used to + * quickly set variables and such after people save the account workflow + * form in simple configuration mode. + * + * @return + * An array of site user profiles. + * contain the following key-value pairs: + * - "label": Required. The label for the profile, displayed in the select. + * - "callback": Required. The function to call for the mode. + * + * @see user_admin_account_settings() + * @see user_admin_account_settings_mode_submit() + */ +function hook_user_site_access_profiles() { + $access_profiles = array( + 'single' => array( + 'label' => t('Single person blog site'), + 'callback' => '', + ), + 'moderated' => array( + 'label' => t('Public site (moderated)'), + 'callback' => '', + ), + 'public' => array( + 'label' => t('Public site (unmoderated)'), + 'callback' => '', + ), + 'closed' => array( + 'label' => t('Closed site (to the public)'), + 'callback' => '', + ), + + // TODO: Think about callbacks. (if any) + // We could, for example, hook them up with the submit. + // (else we'll just ax them). + + // TODO: think about if we would need more access profiles. + + ); + return $access_profiles; +} + +/** * @} End of "addtogroup hooks". */ diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 68b45ea..062b032 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1123,6 +1123,13 @@ function user_cancel_access($account) { } /** + * Menu access callback for account workflow contextual items. + */ +function user_admin_advanced_access() { + return config('user.settings')->get('advanced_config'); +} + +/** * Implements hook_menu(). */ function user_menu() { @@ -1264,7 +1271,7 @@ function user_menu() { ); $items['admin/config/people/accounts'] = array( 'title' => 'Account settings', - 'description' => 'Configure default behavior of users, including registration requirements, e-mails, fields, and user pictures.', + 'description' => 'Configure default behavior of users, including fields and user pictures.', 'page callback' => 'drupal_get_form', 'page arguments' => array('user_admin_settings'), 'access arguments' => array('administer users'), @@ -1277,6 +1284,66 @@ function user_menu() { 'weight' => -10, ); + // Account config. + $items['admin/config/people/workflow'] = array( + 'title' => 'Account workflow', + 'description' => 'Configure default behavior for the registration, authentication, cancellation and password reset process.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('user_admin_workflow_settings'), + 'access arguments' => array('administer users'), + 'file' => 'user.admin.inc', + 'weight' => -9, + ); + $items['admin/config/people/workflow/settings'] = array( + 'title' => 'Global settings', + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => -16, + ); + $items['admin/config/people/workflow/registration'] = array( + 'title' => 'Registration', + 'description' => 'Configure default behavior for the authentication system.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('user_admin_registration_settings'), + 'access callback' => 'user_admin_advanced_access', + 'access arguments' => array('administer users'), + 'file' => 'user.admin.inc', + 'weight' => -15, + 'type' => MENU_LOCAL_TASK, + ); + $items['admin/config/people/workflow/authentication'] = array( + 'title' => 'Authentication', + 'description' => 'Configure default behavior for the authentication system.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('user_admin_authentication_settings'), + 'access callback' => 'user_admin_advanced_access', + 'access arguments' => array('administer users'), + 'file' => 'user.admin.inc', + 'weight' => -14, + 'type' => MENU_LOCAL_TASK, + ); + $items['admin/config/people/workflow/cancellation'] = array( + 'title' => 'Cancellation', + 'description' => 'Configure default behavior for the cancellation system.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('user_admin_cancellation_settings'), + 'access callback' => 'user_admin_advanced_access', + 'access arguments' => array('administer users'), + 'file' => 'user.admin.inc', + 'weight' => -13, + 'type' => MENU_LOCAL_TASK, + ); + $items['admin/config/people/workflow/pass_reset'] = array( + 'title' => 'Password reset', + 'description' => 'Configure default behavior for the password reset system.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('user_admin_pass_reset_settings'), + 'access callback' => 'user_admin_advanced_access', + 'access arguments' => array('administer users'), + 'file' => 'user.admin.inc', + 'weight' => -13, + 'type' => MENU_LOCAL_TASK, + ); + $items['user/%user'] = array( 'title' => 'My account', 'title callback' => 'user_page_title', @@ -2492,6 +2559,31 @@ function user_user_operations_block($accounts) { } /** + * Implements hook_user_site_access_profiles(). + */ +function user_user_site_access_profiles() { + $access_profiles = array( + 'single' => array( + 'label' => t('Single person blog site'), + 'callback' => '', + ), + 'moderated' => array( + 'label' => t('Public site (moderated)'), + 'callback' => '', + ), + 'public' => array( + 'label' => t('Public site (unmoderated)'), + 'callback' => '', + ), + 'closed' => array( + 'label' => t('Closed site (to the public)'), + 'callback' => '', + ), + ); + return $access_profiles; +} + +/** * Callback function for admin mass adding/deleting a user role. */ function user_multiple_role_edit($accounts, $operation, $rid) {