Drupal - Why entity_metadata_wrapper->save() doesn't update node's revision?

When you edit a node via the UI, it is done via node_form(). This has a call near the top to node_object_prepare(), which sets up default values for that node. This includes setting the default value of $node->revision, which is used by node_save() to determine whether a new revision is needed or not.

The Entity API is revision aware, but node_object_prepare() is a node-specific thing. This means that you need to manage the values yourself, including setting the revision property to mimic what the node edit form will do.


None of these answers are actually correct, doing ->set(1) makes it sound like your actually changing the revision number and therefore should increment it.

This is actually just a boolean flag so the correct answer is $node->revision->set(true);

As zhuchun says: he doesn't understand why its needed, when explained as a boolean flag it makes perfect sense rather than the number.


Is the create new revision flag set on the node for the content type? Have you tried like $w->revision->set(1); before saving? ....

EDIT:

Author says setting $w->revision->set(1) solves his issue.

Tags:

Entities

Nodes

7