0

I have created a user based view and I used the Views Bulk Operations module, but I don't see Unblock user or something like that. I also want to show tree-based roles in the bulk operation options list.

How can I achieve this?

2

Below is the code to add 'Unblock the user' option in Views Bulk Operations field.

/**
* Implements hook_action_info().
*/
function mymodule_action_info() {
return array(
'mymodule_unblock_user_action' => array(
'label' => t('Unblock the user'),
'type' => 'user',
'configurable' => FALSE,
'triggers' => array('any'),
 ),
 );
}

/**
 * Unblocks a user, defaulting to the current user.
  *
 * @ingroup actions
 */
 function mymodule_unblock_user_action($entity, $context = array()) {
 // First priority: If there is a $entity->uid, unblock that user.
 // This is most likely a user object or the author if a node or comment.
 if (isset($entity->uid)) {
 $uid = $entity->uid;
    }
   // Otherwise get user ID from the context.
 elseif (isset($context['uid'])) {
  $uid = $context['uid'];
  }
 $account = user_load($uid);
  $account = user_save($account, array('status' => 1));
 watchdog('action', 'Unblocked user %name.', array('%name' => $account->name));
    }

Taken answer from This Link.

4

In drupal 7-

We need a Rules module, after enable Rules module and Rules UI go to

1- Configuration -> Workflow-> Rules-> Component-> Add Component

In Component plugin dropdown-> select Action Set then add next page Fill the mandatory field Name as (Ex: Unblock user)

2- Select Data type from list User ---Label Unblock user ---machine name unblock_user -- usage parameter

3- In setting option you can set Permission roles wise.

then click on continue button then click on Add Action Link

4- then Select the action to add User ->Unblock User

5- Select Data Selector -> unblock-user and Save

6- Now go to- Views Page add field Bulk operations there will be present Unblock user option

for reference - Add Unblock user option by rules in views and set permission

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.