You are here

function drafty_entity_presave in Drafty 7

Implements hook_entity_presave().

File

./drafty.module, line 51
Hook implementations and API functions for the Drafty module.

Code

function drafty_entity_presave($entity, $type) {
  $recursion_level =& drupal_static('drafty_recursion_level', 0);
  if (!$recursion_level && !drafty_entity_is_new($entity, $type) && !empty($entity->is_draft_revision)) {

    // Since this is a draft revision, after saving we want the current,
    // published revision to remain in place in the base entity table and
    // field_data_*() tables. Set the revision to publish once the draft entity
    // has been written to the database.
    list($id) = entity_extract_ids($type, $entity);
    $vid = drafty()
      ->getPublishedRevisionId($type, $id);
    drafty()
      ->setRevisionToBePublished($type, $id, $vid);
  }
  $recursion_level++;
}