You are here

function workbench_moderation_entity_presave in Workbench Moderation 7.3

Same name and namespace in other branches
  1. 8.2 workbench_moderation.module \workbench_moderation_entity_presave()
  2. 8 workbench_moderation.module \workbench_moderation_entity_presave()

Implements hook_entity_presave().

File

./workbench_moderation.module, line 664
Content moderation for Workbench.

Code

function workbench_moderation_entity_presave($entity, $entity_type) {

  // Note: this only supports nodes at the moment.
  if ($entity_type != 'node') {
    return;
  }

  // Is the content type under moderation?
  if (!workbench_moderation_node_type_moderated($entity->type)) {
    return;
  }

  // Load our data onto the entity.
  if (!$entity->is_new) {
    workbench_moderation_set_node_state($entity);
  }
  $published = FALSE;

  // Ensure the entity is marked as published.
  if (isset($entity->workbench_moderation_state_new) && $entity->workbench_moderation_state_new == workbench_moderation_state_published()) {
    $published = TRUE;
    $entity->status = NODE_PUBLISHED;
  }

  // If we are unpublishing a node, do not force revision.
  if (!$entity->status) {
    $entity->is_draft_revision = FALSE;
  }
  elseif (!isset($entity->is_draft_revision) && !$published) {
    $entity->is_draft_revision = TRUE;
  }
}