Skip to content

Instantly share code, notes, and snippets.

@hissy
Last active December 24, 2023 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hissy/1eb6374a79ca8f420fab3bdfebb4371b to your computer and use it in GitHub Desktop.
Save hissy/1eb6374a79ca8f420fab3bdfebb4371b to your computer and use it in GitHub Desktop.
[Concrete CMS] Unapprove page versions when a page is duplicated
<?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