diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 1a3580f..ec96c0c 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1747,13 +1747,15 @@ function comment_form($form, &$form_state, $comment) { // Add the author name field depending on the current user. if ($is_admin) { + $account_settings_config = config('user.account_settings'); + $anonymous_name = $account_settings_config->get('anonymous'); $form['author']['name'] = array( '#type' => 'textfield', '#title' => t('Authored by'), '#default_value' => $author, '#maxlength' => 60, '#size' => 30, - '#description' => t('Leave blank for %anonymous.', array('%anonymous' => variable_get('anonymous', t('Anonymous')))), + '#description' => t('Leave blank for %anonymous.', array('%anonymous' => $anonymous_name)), '#autocomplete_path' => 'user/autocomplete', ); } @@ -1914,7 +1916,8 @@ function comment_preview($comment) { $comment->picture = $account->picture; } elseif (empty($comment->name)) { - $comment->name = variable_get('anonymous', t('Anonymous')); + $account_settings_config = config('user.account_settings'); + $comment->name = $account_settings_config->get('anonymous'); } $comment->created = !empty($comment->created) ? $comment->created : REQUEST_TIME; @@ -2002,7 +2005,8 @@ function comment_submit($comment) { // If the comment was posted by an anonymous user and no author name was // required, use "Anonymous" by default. if ($comment->is_anonymous && (!isset($comment->name) || $comment->name === '')) { - $comment->name = variable_get('anonymous', t('Anonymous')); + $account_settings_config = config('user.account_settings'); + $comment->name = $account_settings_config->get('anonymous'); } // Validate the comment's subject. If not specified, extract from comment body. diff --git a/core/modules/comment/comment.tokens.inc b/core/modules/comment/comment.tokens.inc index 1c6a7ee..70b4fe2 100644 --- a/core/modules/comment/comment.tokens.inc +++ b/core/modules/comment/comment.tokens.inc @@ -131,7 +131,9 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = break; case 'name': - $name = ($comment->uid == 0) ? variable_get('anonymous', t('Anonymous')) : $comment->name; + $account_settings_config = config('user.account_settings'); + $anonymous_name = $account_settings_config->get('anonymous'); + $name = ($comment->uid == 0) ? $anonymous_name : $comment->name; $replacements[$original] = $sanitize ? filter_xss($name) : $name; break; diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc index 4e94b26..f17108b 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -246,6 +246,8 @@ function node_form($form, &$form_state, $node) { ); // Node author information for administrators + $account_settings_config = config('user.account_settings'); + $anonymous_name = $account_settings_config->get('anonymous'); $form['author'] = array( '#type' => 'fieldset', '#access' => user_access('administer nodes'), @@ -258,10 +260,10 @@ function node_form($form, &$form_state, $node) { ), '#attached' => array( 'js' => array( - drupal_get_path('module', 'node') . '/node.js', + drupal_get_path('module', 'node') . '/node.js', array( 'type' => 'setting', - 'data' => array('anonymous' => variable_get('anonymous', t('Anonymous'))), + 'data' => array('anonymous' => $anonymous_name), ), ), ), @@ -274,7 +276,7 @@ function node_form($form, &$form_state, $node) { '#autocomplete_path' => 'user/autocomplete', '#default_value' => !empty($node->name) ? $node->name : '', '#weight' => -1, - '#description' => t('Leave blank for %anonymous.', array('%anonymous' => variable_get('anonymous', t('Anonymous')))), + '#description' => t('Leave blank for %anonymous.', array('%anonymous' => $anonymous_name)), ); $form['author']['date'] = array( '#type' => 'textfield', diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 00c75c7..a9ef88c 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -3842,7 +3842,9 @@ function hook_tokens($type, $tokens, array $data = array(), array $options = arr // Default values for the chained tokens handled below. case 'author': - $name = ($node->uid == 0) ? variable_get('anonymous', t('Anonymous')) : $node->name; + $account_settings_config = config('user.account_settings'); + $anonymous_name = $account_settings_config->get('anonymous'); + $name = ($node->uid == 0) ? $anonymous_name : $node->name; $replacements[$original] = $sanitize ? filter_xss($name) : $name; break; diff --git a/core/modules/user/config/user.account_settings.xml b/core/modules/user/config/user.account_settings.xml new file mode 100644 index 0000000..e7998e4 --- /dev/null +++ b/core/modules/user/config/user.account_settings.xml @@ -0,0 +1,4 @@ + + + Anonymous + diff --git a/core/modules/user/user.admin.inc b/core/modules/user/user.admin.inc index f7d4552..a0bc8da 100644 --- a/core/modules/user/user.admin.inc +++ b/core/modules/user/user.admin.inc @@ -259,6 +259,7 @@ function user_admin_account_validate($form, &$form_state) { */ function user_admin_settings() { // Settings for anonymous users. + $config = config('user.account_settings'); $form['anonymous_settings'] = array( '#type' => 'fieldset', '#title' => t('Anonymous users'), @@ -266,7 +267,7 @@ function user_admin_settings() { $form['anonymous_settings']['anonymous'] = array( '#type' => 'textfield', '#title' => t('Name'), - '#default_value' => variable_get('anonymous', t('Anonymous')), + '#default_value' => $config->get('anonymous'), '#description' => t('The name used to indicate anonymous users.'), '#required' => TRUE, ); @@ -638,10 +639,20 @@ function user_admin_settings() { '#rows' => 3, ); + $form['#submit'][] = 'user_admin_settings_submit'; return system_settings_form($form); } /** + * Save account settings settings. + */ +function user_admin_settings_submit($form, $form_state) { + $config = config('user.account_settings'); + $config->set('anonymous', $form_state['values']['anonymous']); + $config->save(); +} + +/** * Menu callback: administer permissions. * * @ingroup forms diff --git a/core/modules/user/user.install b/core/modules/user/user.install index 38d78e1..1de52bc 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -398,5 +398,18 @@ function user_update_8001() { } /** + * Converts account settings variables to configuration system + * + * @see http://drupal.org/node/1496534 + */ +function user_update_8002() { + $config = config('user.account_settings'); + $anonymous_name = variable_get('anonymous'); + $config->set('anonymous', $anonymous_name); + db_delete('variable')->condition('name', 'anonymous')->execute(); + $config->save(); +} + +/** * @} End of "addtogroup updates-7.x-to-8.x" */ diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 865f17b..1c8b186 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -774,6 +774,8 @@ function user_is_blocked($name) { * Implements hook_permission(). */ function user_permission() { + $account_settings_config = config('user.account_settings'); + $anonymous_name = $account_settings_config->get('anonymous'); return array( 'administer permissions' => array( 'title' => t('Administer permissions'), @@ -791,7 +793,7 @@ function user_permission() { ), 'cancel account' => array( 'title' => t('Cancel own user account'), - 'description' => t('Note: content may be kept, unpublished, deleted or transferred to the %anonymous-name user depending on the configured user settings.', array('%anonymous-name' => variable_get('anonymous', t('Anonymous')), '@user-settings-url' => url('admin/config/people/accounts'))), + 'description' => t('Note: content may be kept, unpublished, deleted or transferred to the %anonymous-name user depending on the configured user settings.', array('%anonymous-name' => $anonymous_name, '@user-settings-url' => url('admin/config/people/accounts'))), ), 'select account cancellation method' => array( 'title' => t('Select method for cancelling own account'), @@ -1367,7 +1369,9 @@ function user_preprocess_block(&$variables) { * printed to the page. */ function user_format_name($account) { - $name = !empty($account->name) ? $account->name : variable_get('anonymous', t('Anonymous')); + $account_settings_config = config('user.account_settings'); + $anonymous_name = $account_settings_config->get('anonymous'); + $name = !empty($account->name) ? $account->name : $anonymous_name; drupal_alter('user_format_name', $name, $account); return $name; } diff --git a/core/modules/user/user.pages.inc b/core/modules/user/user.pages.inc index c54bd4c..654e942 100644 --- a/core/modules/user/user.pages.inc +++ b/core/modules/user/user.pages.inc @@ -426,6 +426,8 @@ function user_cancel_confirm_form_submit($form, &$form_state) { * @see user_multiple_cancel_confirm() */ function user_cancel_methods() { + $account_settings_config = config('user.account_settings'); + $anonymous_name = $account_settings_config->get('anonymous'); $methods = array( 'user_cancel_block' => array( 'title' => t('Disable the account and keep its content.'), @@ -436,8 +438,8 @@ function user_cancel_methods() { 'description' => t('Your account will be blocked and you will no longer be able to log in. All of your content will be hidden from everyone but administrators.'), ), 'user_cancel_reassign' => array( - 'title' => t('Delete the account and make its content belong to the %anonymous-name user.', array('%anonymous-name' => variable_get('anonymous', t('Anonymous')))), - 'description' => t('Your account will be removed and all account information deleted. All of your content will be assigned to the %anonymous-name user.', array('%anonymous-name' => variable_get('anonymous', t('Anonymous')))), + 'title' => t('Delete the account and make its content belong to the %anonymous-name user.', array('%anonymous-name' => $anonymous_name)), + 'description' => t('Your account will be removed and all account information deleted. All of your content will be assigned to the %anonymous-name user.', array('%anonymous-name' => $anonymous_name)), ), 'user_cancel_delete' => array( 'title' => t('Delete the account and its content.'), diff --git a/core/modules/user/user.test b/core/modules/user/user.test index 3a07e1c..0ceafb3 100644 --- a/core/modules/user/user.test +++ b/core/modules/user/user.test @@ -674,7 +674,9 @@ class UserCancelTestCase extends DrupalWebTestCase { $this->drupalGet('user/' . $account->uid . '/edit'); $this->drupalPost(NULL, NULL, t('Cancel account')); $this->assertText(t('Are you sure you want to cancel your account?'), t('Confirmation form to cancel account displayed.')); - $this->assertRaw(t('Your account will be removed and all account information deleted. All of your content will be assigned to the %anonymous-name user.', array('%anonymous-name' => variable_get('anonymous', t('Anonymous')))), t('Informs that all content will be attributed to anonymous account.')); + $account_settings_config = config('user.account_settings'); + $anonymous_name = $account_settings_config->get('anonymous'); + $this->assertRaw(t('Your account will be removed and all account information deleted. All of your content will be assigned to the %anonymous-name user.', array('%anonymous-name' => $anonymous_name)), t('Informs that all content will be attributed to anonymous account.')); // Confirm account cancellation. $timestamp = time();