1

I have an article type where a content admin role can Create an Article. There are 10 Content Admins in system. If one content admin creates the node, I can see eg: Submitted by username. If user2 edits the same article, I want to store who edited it and when in database and display the edited by: OR Updated by:

Its same like in SE websites, you can see who edited the post at what time. How do I do this in Drupal 7 ?

P.S. I am still new in Drupal and haven't explored all the big ocean of Modules in Drupal, so, there might be easy solutions for these things somewhere which I couldn't come across using Google Search.

1 Answer 1

0

Node Revisions are stored in node_revision table.This table keep track of what user edited what nodes as separate revision.

Also the last uid who has revised/updated the node is available in $node entity.So try something as below in your theme template.php

function mytheme_preprocess_node(&$variables) {
  $node = $variables['node'];

  // Gather last updated author info
  $revision_uid = !empty($node->revision_uid) ? $node->revision_uid : 0;
  if (!$revision_uid) {
    $revision_username = variable_get('anonymous', 'Anonymous');
  }
  else {
    $revision_user = user_load(array('uid' => $revision_uid));
    if ($variables['is_admin']) {
      $revision_username = l($revision_user->name, 'user/'. $revision_uid);
    }
    else{
      $revision_username = $revision_user->name;
    }
  }
  $variables['revision_username'] = $revision_username;

Then just <?php print $revision_username; ?> in your .tpl files.

Reference Link:

https://drupal.org/node/236523

Since above code will show only the last editor info,if you want to get all users you can query the node_revisions table.

Your Answer

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