action_example_unblock_user_action

  1. drupal
    1. 8
    2. 7
Versions
8 – 7 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

$entity An optional user object (could be a user, or an author if context is node or comment)

$context Array with parameters for this action: depends on the trigger. The context is not used in this example.

Related topics

Code

examples/action_example/action_example.module, line 236

<?php
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 = 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)));
}
?>