1

I know that this is most probably and easy question but I simply can't get it to work. I have a custom module which generates a form to create a content (unpublished) of a certain type and also register the anonymous user creating that content with a username and password.

I am using the User verification module to send a validation mail, and when the client clicks the link the account is unblocked.

I want a rule (I tried using the Rules module) to publish the content when the account is unblocked or validated (i need it to work on one of these to events) , but I can't find either of these events, nor can I manage to set the data selector to publish that specific content when setting the action to publish content.

If anyone can explain to me what I am missing or doing wrong it would help me a lot.

1 Answer 1

0

In your custom module you could use a hook_user_update and if the $account->original->status == 0 & $account->status == 1 (meaning that the user just got active [untested]), publish the content.

something like:

<?php
/**
 * Implementation of hook_user_update()
 */
function MODULE_user_update(&$edit, $account, $category) {
  if($account->status && $account->status != $account->original->status) {
    // with the user id you can find (i suppose) the content this user has just 
    // created and publish it, using something like the link below
  }
}

publish-unpublish

7
  • and this function runs no matter when the user update happens? That would be pretty nice. I will try it tomorow and update with the results. Thank you
    – Cristi
    Commented Jul 24, 2014 at 15:56
  • I tried to use the hook to simply change the username but it's not triggered by the User verification module ... Should I go and edit the contributed module (my experience says NO ) or am I still missing something?
    – Cristi
    Commented Jul 25, 2014 at 11:04
  • No, don't do that.You could check if the contrib module exposes a hook you could implement on that particular state of the user or something?Note:you might need to user_save($account) in the hook_user_update for this to work?
    – Pan Chrono
    Commented Jul 25, 2014 at 12:21
  • Now you lost me. What do you mean by "exposes a hook you could implement on that particular state of the user"? I am still new to drupal , 1 month and counting
    – Cristi
    Commented Jul 25, 2014 at 12:27
  • from what I understood in the code , the module has a _user_verify($account,$code) function which is called when the user clicks the validation link . If the code provided by the user coresponds with the one assisgned to his account , then the function _user_verify_cleanup is called ( this function is called in many other scenarios), a variable $success is set to TRUE and the user is unblocked (db_update('users')->fields(array('status' => 1))->execute(). How can I set my hook to interact with that event without tampering the contrib module code?
    – Cristi
    Commented Jul 25, 2014 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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