Last active
December 24, 2023 23:57
-
-
Save hissy/1eb6374a79ca8f420fab3bdfebb4371b to your computer and use it in GitHub Desktop.
[Concrete CMS] Unapprove page versions when a page is duplicated
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ($app->isInstalled()) { | |
// Register Events | |
/** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher */ | |
$eventDispatcher = $app->make(\Symfony\Component\EventDispatcher\EventDispatcherInterface::class); | |
// Unapprove page versions when a page is duplicated | |
$eventDispatcher->addListener('on_page_duplicate', function ($event) { | |
/** @var \Concrete\Core\Page\DuplicatePageEvent $event */ | |
$newPage = $event->getNewPageObject(); | |
$versionList = new \Concrete\Core\Page\Collection\Version\VersionList($newPage); | |
$versionList->setItemsPerPage(-1); | |
$versions = $versionList->getPage(); | |
/** @var \Concrete\Core\Page\Collection\Version\Version $version */ | |
foreach ($versions as $version) { | |
if ($version->isApproved()) { | |
$version->deny(); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment