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?
-
2Why 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.– VamsiMay 11, 2016 at 11:17
-
1I'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.– danielson317May 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?– CyclonecodeMay 12, 2016 at 6:50
-
@Cyclone you're right.– VamsiMay 12, 2016 at 6:56
2 Answers
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.
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.