public function EntityLegalDocument::setPublishedVersion in Entity Legal 8.2
Same name and namespace in other branches
- 4.0.x src/Entity/EntityLegalDocument.php \Drupal\entity_legal\Entity\EntityLegalDocument::setPublishedVersion()
- 3.0.x src/Entity/EntityLegalDocument.php \Drupal\entity_legal\Entity\EntityLegalDocument::setPublishedVersion()
Set the published document version.
Parameters
EntityLegalDocumentVersionInterface $version_entity: The legal document version to set as the published version.
Return value
bool Whether or not the published version was set successfully.
Overrides EntityLegalDocumentInterface::setPublishedVersion
File
- src/
Entity/ EntityLegalDocument.php, line 163
Class
- EntityLegalDocument
- Defines the entity legal document entity.
Namespace
Drupal\entity_legal\EntityCode
public function setPublishedVersion(EntityLegalDocumentVersionInterface $version_entity) {
if (!$version_entity
->isNew()) {
/** @var \Drupal\entity_legal\EntityLegalDocumentVersionInterface $unchanged_version */
$unchanged_version = $this
->entityTypeManager()
->getStorage(ENTITY_LEGAL_DOCUMENT_VERSION_ENTITY_NAME)
->loadUnchanged($version_entity
->id());
if ($unchanged_version
->isPublished()) {
// An existing entity is already published.
return TRUE;
}
}
// If the version entity is not of this bundle, fail.
if ($version_entity
->bundle() != $this
->id()) {
return FALSE;
}
// Unpublish a published version.
if ($actual_published_version = $this
->getPublishedVersion()) {
$actual_published_version
->unpublish()
->save();
}
$version_entity
->publish()
->save();
return TRUE;
}