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 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

File

modules/examples/action_example/action_example.module, line 206
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'];
  }
  // If neither of those are valid, then block the current user.
  else {
    $uid = $GLOBALS['user']->uid;
  }
  $account = user_load($uid);

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