function action_example_unblock_user_action in Examples for Developers 7
Action function for action_example_unblock_user_action.
This action is expecting an entity object user, node or comment. If none of the above is provided (because it was not called from an user/node/comment trigger event), then the action will be taken on the current logged in user.
Unblock an user. This action can be fired from different trigger types:
- User trigger: this user will be unblocked.
- Node/Comment trigger: the author of the node or comment will be unblocked.
- Other: (including system or custom defined types), current user will be unblocked. (Yes, this seems like an incomprehensible use-case.)
Parameters
object $entity: An optional user object (could be a user, or an author if context is node or comment)
array $context: Array with parameters for this action: depends on the trigger. The context is not used in this example.
Related topics
1 string reference to 'action_example_unblock_user_action'
- ActionExampleTestCase::testActionExample in action_example/
action_example.test - Test Action Example.
File
- action_example/
action_example.module, line 233 - Action definition example module.
Code
function action_example_unblock_user_action(&$entity, $context = array()) {
// First we check that entity is a user object. If this is the case, then this
// is a user-type trigger.
if (isset($entity->uid)) {
$uid = $entity->uid;
}
elseif (isset($context['uid'])) {
$uid = $context['uid'];
}
else {
$uid = $GLOBALS['user']->uid;
}
$account = user_load($uid);
$account = user_save($account, array(
'status' => 1,
));
watchdog('action_example', 'Unblocked user %name.', array(
'%name' => $account->name,
));
drupal_set_message(t('Unblocked user %name', array(
'%name' => $account->name,
)));
}