0

I have a content type with revision enabled, each time when I edit the node I can see authored on field has created date by default. I want this field to be empty so that it uses latest updated time as created time. How can I achieve it?

5
  • 2
    Why not just use the modified date? That's what it's for...
    – Clive
    May 11, 2016 at 11:03
  • I want to update created date too.
    – Vamsi
    May 11, 2016 at 11:17
  • 1
    I'm with @Clive I think you are using created date incorrectly. If you want the modified date use the modified date. Changing created date on every update is kind of pointless and borders on database corruption. May 11, 2016 at 16:12
  • @danielson317 - I think the reason might be that he want every new revision to be marked as created when the revision is first created from the original version? May 12, 2016 at 6:50
  • @Cyclone you're right.
    – Vamsi
    May 12, 2016 at 6:56

2 Answers 2

3

You might want to use rules 'After updating existing content of type typename' in events and 'set data value' timestamp to created date will accomplish your task easily.

2

You could use hook_node_presave() to accomplish this. Something like this might work:

function hook_node_presave($node) {
   // check so the node if of a specific type and a revision
   if ($node->type == 'your-type' && $node->revision == TRUE) {
     // sets creation date equal to the modification date
     $node->created = $node->modified;
   }
}

The above would go in a custom module file and you then have to rename the hook part to the actual name of your module.

Your Answer

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

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