You are here

function _metatag_isdefaultrevision in Metatag 7

Checks if this entity is the default revision (published).

Only needed when running Workbench Moderation v1; v3 is skipped.

Parameters

object $entity: The entity object, e.g., $node.

Return value

bool TRUE if the entity is the default revision, FALSE otherwise.

2 calls to _metatag_isdefaultrevision()
metatag_entity_insert in ./metatag.module
Implements hook_entity_insert().
metatag_entity_update in ./metatag.module
Implements hook_entity_update().

File

./metatag.module, line 2755
Primary hook implementations for Metatag.

Code

function _metatag_isdefaultrevision($entity) {

  // D7 "Forward revisioning" is complex and causes a node_save() with the
  // future node in node table. This fires hook_node_update() twice and cause
  // abnormal behaviour in metatag.
  //
  // The steps taken by Workbench Moderation is to save the forward revision
  // first and overwrite this with the live version in a shutdown function in
  // a second step. This will confuse metatag. D7 has no generic property
  // in the node object, if the node that is updated is the 'published' version
  // or only a draft of a future version.
  //
  // This behaviour will change in D8 where $node->isDefaultRevision has been
  // introduced. See below links for more details.
  // - https://www.drupal.org/node/1879482
  // - https://www.drupal.org/node/218755
  // - https://www.drupal.org/node/1522154
  //
  // Every moderation module saving a forward revision needs to return FALSE.
  // @todo Refactor this workaround under D8.
  // Workbench Moderation v1 uses the hook_node_presave() for some custom logic.
  // This was replaced with hook_entity_presave() in v3, so only proceed if the
  // old hook implementation is present.
  if (function_exists('workbench_moderation_node_presave')) {

    // If this is a node, check if the content type supports moderation.
    if (function_exists('workbench_moderation_node_type_moderated') && workbench_moderation_node_type_moderated($entity->type) === TRUE) {
      return !empty($entity->workbench_moderation['updating_live_revision']);
    }
  }
  return FALSE;
}