I'm developing a module to update nodes(enable revision). It looks like this.
$nodes = node_load_multiple(array(), array('type' => $bundleType));
foreach ($ndoes as $node){
$w = entity_metadata_wrapper('node',$node);
$w->MyFields->set($someValue);
$w->save();
}
It set fields correctly but node's revision-id didn't change after $w->save()
.
How can I update the revision ID?
create new revision
flag set on the node for the content type? Have you tried like$w->revision->set(1);
before saving? ....$w->revision->set(1)
, is that a manual way to let the drupal knows that the node has been updated? I will try it.$w->revision->set()
works. It seems I misunderstand$w->save()
. I thought it should increase the revision-id automatically while saving. Is there anyway to get next increase revision id? Thank yourevision->set(1)
tells the node to record a new revision on the upcoming/current edit of the node. I'm not sure why the metadata wrapper isn't seeing the global setting of create new revision ..... but setting the revision flag is a very simple workaround as you've now seen. I'm provided my comment as an answer below if you care to upvote it to help other users in the future find a correct answer.