I have a situation where I want a node to be created by a user and put in to a 'review' workflow state. An editor will then later update the state to 'published'. What I want is for the node author to be changed to the editor who changed the workflow state.

I noticed that there is a similar action which allows changing a node author to a predetermined user but in my case I want the new author to be the user who changes the node state.

Is there currently some way to do this?

Thanks, :)

Comments

Soren Jones’s picture

This is a modification of the function action_node_assign_owner() found in actions.inc that is working for me. I've wrapped it in a module called myactions.module.

/**
 * Implementation of a Drupal action.
 * Assigns ownership of a node to the current user.
 */
function action_node_currentuser_owner($op, $edit = array(), &$node) {
  switch($op) {
    case 'metadata':
      return array(
        'description' => t('Change node author to current user'),
        'type' => t('Node'),
        'batchable' => TRUE,
        'configurable' => FALSE,
      );

    case 'do':
      global $user;
      $uid = $user->uid;
      $node->uid = $uid;
      $node->revision = '0';
      if (!$edit['defer']) {
        node_save($node);
      }
      watchdog('action', t('Changed owner of node %id to uid %uid', array('%id' => intval($node->nid), '%uid' => intval($uid))));
      break;

    // return an HTML config form for the action
    case 'form':
      return '';

    // validate the HTML form
    case 'validate':
      return TRUE;

    // process the HTML form to store configuration
    case 'submit':
      return '';
  }
}
MediaMunkey’s picture

Status: Active » Closed (fixed)

Hi,

Thanks for the helpful reply. Since posting this issue I've changed my mind in how to achieve the desired outcome. Instead of changing the user of the node I want to instead call up the editor who changed the workflow state using some sql querying in the node.tpl page. This will be used to simply make it appear that the owner of the node is the editor. I have yet to figure this one out though as I'm not able to code.

Again, thanks for the help anyway.

Bastlynn’s picture

Even if it wasn't helpful to the original poster - it was quite helpful to me - Thank you! :)

jonaliz55’s picture

This is exactly what I require - but does it work the same way in Drupal 6? -
I could not find the function action_node_assign_owner() in actions.inc.
If not, what modifications are need to make this work in Drupal 6?

jvandyk’s picture

HenkBredell’s picture

The link - In Drupal 6: http://api.drupal.org/api/function/node_assign_owner_action/6 appears to refer to the current standard code and not to new code.

I also need an action to change the author to the "current user" so that users are able to take on work by changing the author name and have the nodes appear in their own workspace views. Is a possible way to have an additional user reference in the action configuration dropdown - [current user]. When this selection is made it would always return the "current user" instead of a selected fixed user.

Is something like this possible within the current framework?

Thanks in advance
Henk

jonaliz55’s picture

Thanks to jvandyk for the node_assign_owner_action link, though I am not a programmer and would like some code which does what HenkBredell requested in #6 above.