views:

1239

answers:

3

Users on my site can add nodes of a custom type (let's call it "Player") but cannot publish them. Effectively they need moderating before posting. Once an admin / moderator has published them, I want the owner / publisher to be changed to an the relevant admin / moderator. This is so that the user is be unable to edit them and also so it is possible to track who approved them etc.

How do I go about this? I thought it might involve Actions / Rules / Workflow / Workflow-ng etc, but I've looked at each and can't seem to figure out how to make it work!

+1  A: 

You can do it manually when you're editing the Player nodes. There's a group of two settings towards the end where you can change the node creator and creation time.

Alternatively, can you give the non-admin users permission to create nodes, but remove their permission to edit these nodes. Might work, but could be painful for these users.

dave
Of course, this requires the user to have the 'administer content' permissions to change these settings. This may not be applicable as there may be other content on the site x3ja doesn't necessarily want his admin / moderators to have free run of.
BrianV
x3ja
+2  A: 

Another alternative is to write a short module that includes an 'approve' link using hook_link(). Point that link to a menu callback that changes the node's ownership from the current user to the user that clicked the 'Approve' link.

It could be nice, clean way of solving this, but requires a bit of Drupal knowhow. However, if you ask someone in the #drupal IRC channel on irc.freenode.net, they could show you how to get started, or even code it as a contributed module for you.

BrianV
+1  A: 

Just to add some more info - BrainV helped me develop the following code for a custom module - called publishtrigger here. I wanted the approve button to publish the Player node and then assign it to the "contentadmin" user, which has ID 6 in my case...

<?php
/**
 * Implementation of hook_perm().
 */
function publishtrigger_perm() {
  return array('approve nodes');
}

    /**
 * Implementation of hook_menu().
 */
function publishtrigger_menu() {
  $items['approve/%'] = array(
    'title' => 'Approve',
    'page callback' => 'publishtrigger_approve_node',
    'page arguments' => array(1),
    'access arguments' => array('approve nodes'),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Implementation of hook_link().
 */
function publishtrigger_link($type, $object, $teaser = FALSE) {

  // Show this link at the bottom of nodes of the Player type which are not yet
  // owned by contentadmin (UID 6).
  if ($type == 'node' && $object->type == 'player') {

    // Make sure user has permission to approve nodes.
    if (user_access('approve nodes')) {
      $links = array();
      if ($object->uid != 6 || $object->status == 0) {
        // Node is not owned by contentadmin (UID 6), and therefore not approved.
        $links['approve_link'] = array(
          'title' => 'Approve',
          'href' => 'approve/' . $object->nid,
        );
      }
      else {
        // Node is already approved
        $links['approve_link'] = array('title' => 'Already approved');
      }
      return $links;
    }
  }
}

/**
 * When this code is run, adjust the owner of the indicated node to 'contentadmin',
 * UID 6.
 *
 * @param $nid
 *  The node id of the node we want to change the owner of.
 */
function publishtrigger_approve_node($nid) {
  // Load the node.
  $node = node_load($nid);

  // Set the UID to 6 (for contentadmin).
  $node->uid = 6;

  // Publish the node
  $node->status = 1;

  // Save the node again.
  node_save($node);

  // Go back to the node page
  drupal_goto($node->path);
}
x3ja

related questions