public function EntityModeratedRevision::isPublishedRevision in Acquia Content Hub 8.2
Determines whether an entity revision is "published".
The following conditions have to be met for an entity revision to NOT be considered published:
- It does not have a "published" translation.
- It has at least a published translation but the revision is not the current revision.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity revision to be checked.
Return value
bool TRUE if entity is considered "published", FALSE otherwise.
Throws
\Exception
File
- modules/
acquia_contenthub_publisher/ src/ EntityModeratedRevision.php, line 49
Class
- EntityModeratedRevision
- Determines whether an entity revision is "published".
Namespace
Drupal\acquia_contenthub_publisherCode
public function isPublishedRevision(EntityInterface $entity) : bool {
if (!$this
->revisionHasPublishedTranslation($entity)) {
// This revision has no published translation = not "published".
return FALSE;
}
// If this revision has at least one published translation, then check
// that this revision is the current revision.
$revision_col = $entity
->getEntityType()
->hasKey("revision") ? $entity
->getEntityType()
->getKey("revision") : NULL;
if (!$revision_col || !$entity instanceof RevisionableInterface) {
// If it does not have a revision column or entity is not
// "revisionable" then we can assume it to be "published".
return TRUE;
}
// Checking if this is the current revision.
$table = $entity
->getEntityType()
->getBaseTable();
$id_col = $entity
->getEntityType()
->getKey("id");
$query = \Drupal::database()
->select($table)
->fields($table, [
$revision_col,
]);
$query
->condition("{$table}.{$id_col}", $entity
->id());
// Verify if the entity revision being saved is the current revision
// by checking that the entity revision id with the one specified in
// its base table.
$revision_id = $query
->execute()
->fetchField();
// It is not a current revision, then it is not "published".
return $revision_id !== $entity
->getRevisionId() ? FALSE : TRUE;
}