diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-06-29 18:24:10 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-06-29 18:24:10 +0000 |
commit | ef1fd4887aedfd7c33477300977fadd053478b1e (patch) | |
tree | 5e9ccc183e2f8918af410ce186cfbbe0e59137a9 /modules/user | |
parent | 7640e03624f2242653143267f66fbfcca42656d8 (diff) | |
download | brdo-ef1fd4887aedfd7c33477300977fadd053478b1e.tar.gz brdo-ef1fd4887aedfd7c33477300977fadd053478b1e.tar.bz2 |
- Patch #721086 by rfay, aspilicious, andypost: create tests for system actions, clean up token replacement, clean up triggers.
Diffstat (limited to 'modules/user')
-rw-r--r-- | modules/user/user.module | 11 | ||||
-rw-r--r-- | modules/user/user.tokens.inc | 12 |
2 files changed, 14 insertions, 9 deletions
diff --git a/modules/user/user.module b/modules/user/user.module index bac1b767c..0fa22cb09 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -3373,7 +3373,7 @@ function user_action_info() { 'label' => t('Block current user'), 'type' => 'user', 'configurable' => FALSE, - 'triggers' => array(), + 'triggers' => array('any'), ), ); } @@ -3384,22 +3384,25 @@ function user_action_info() { * @ingroup actions */ function user_block_user_action(&$entity, $context = array()) { + // First priority: If there is a $entity->uid, block that user. + // This is most likely a user object or the author if a node or comment. if (isset($entity->uid)) { $uid = $entity->uid; } elseif (isset($context['uid'])) { $uid = $context['uid']; } + // If neither of those are valid, then block the current user. else { - global $user; - $uid = $user->uid; + $uid = $GLOBALS['user']->uid; } db_update('users') ->fields(array('status' => 0)) ->condition('uid', $uid) ->execute(); drupal_session_destroy_uid($uid); - watchdog('action', 'Blocked user %name.', array('%name' => $user->name)); + $account = user_load($uid); + watchdog('action', 'Blocked user %name.', array('%name' => $account->name)); } /** diff --git a/modules/user/user.tokens.inc b/modules/user/user.tokens.inc index 70d4914d5..0c5f88b84 100644 --- a/modules/user/user.tokens.inc +++ b/modules/user/user.tokens.inc @@ -81,7 +81,8 @@ function user_tokens($type, $tokens, array $data = array(), array $options = arr switch ($name) { // Basic user account information. case 'uid': - $replacements[$original] = $account->uid; + // In the case of hook user_presave uid is not set yet. + $replacements[$original] = !empty($account->uid) ? $account->uid : t('not yet assigned'); break; case 'name': @@ -94,20 +95,21 @@ function user_tokens($type, $tokens, array $data = array(), array $options = arr break; case 'url': - $replacements[$original] = url("user/$account->uid", $url_options); + $replacements[$original] = !empty($account->uid) ? url("user/$account->uid", $url_options) : t('not yet assigned'); break; case 'edit-url': - $replacements[$original] = url("user/$account->uid/edit", $url_options); + $replacements[$original] = !empty($account->uid) ? url("user/$account->uid/edit", $url_options) : t('not yet assigned'); break; // These tokens are default variations on the chained tokens handled below. case 'last-login': - $replacements[$original] = format_date($account->login, 'medium', '', NULL, $language_code); + $replacements[$original] = !empty($account->login) ? format_date($account->login, 'medium', '', NULL, $language_code) : t('never'); break; case 'created': - $replacements[$original] = format_date($account->created, 'medium', '', NULL, $language_code); + // In the case of user_presave the created date may not yet be set. + $replacements[$original] = !empty($account->created) ? format_date($account->created, 'medium', '', NULL, $language_code) : t('not yet created'); break; } } |