1 action_example.module action_example_unblock_user_action(&$entity, $context = array())

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 a user/node/comment trigger event, then the action will be taken on the current logged-in user.

Unblock a 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.)


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. The context is not used in this example.

Related topics


modules/examples/action_example/action_example.module, line 198
Hook implementations for the Action Example module.


function action_example_unblock_user_action(&$entity, $context = array()) {
  // If the entity is a user object, this is a user-type trigger.
  if (isset($entity->uid)) {
    $uid = $entity->uid;
  elseif (isset($context['uid'])) {
    $uid = $context['uid'];
  // If neither of those are valid, block the logged-in user.
  else {
    $uid = $GLOBALS['user']->uid;
  $account = user_load($uid);

  $account->status = 1;
  watchdog('action_example', 'Unblocked user %name.', array('%name' => $account->name));
  backdrop_set_message(t('Unblocked user %name', array('%name' => $account->name)));