Created
April 6, 2021 20:22
-
-
Save hissy/4f37161596b14aa3f55487f5f3c04250 to your computer and use it in GitHub Desktop.
[concrete5] [V8] Create a draft detail page if you make a draft calendar event, and approve the page when you publish that event.
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 | |
// Add below code into your application/bootstrap/app.php | |
$app->bind(\Concrete\Core\Calendar\Event\EventService::class, \Application\Calendar\Event\EventService::class); |
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 | |
// Add below code into your application/bootstrap/autoload.php | |
$classLoader = new \Symfony\Component\ClassLoader\Psr4ClassLoader(); | |
$classLoader->addPrefix('Application\\Calendar', DIR_APPLICATION . '/' . DIRNAME_CLASSES . '/Calendar'); | |
$classLoader->register(); |
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 | |
// application/src/Calendar/Event/EventService.php | |
namespace Application\Calendar\Event; | |
use Concrete\Core\Entity\Calendar\Calendar; | |
use Concrete\Core\Entity\Calendar\CalendarEvent; | |
use Concrete\Core\Entity\Calendar\CalendarEventVersion; | |
use Concrete\Core\Page\Page; | |
use Concrete\Core\Page\Type\Type; | |
use Concrete\Core\Permission\Checker; | |
use Concrete\Core\Support\Facade\Application; | |
use Concrete\Core\User\User; | |
use Concrete\Core\Workflow\Request\ApprovePageRequest as ApprovePagePageWorkflowRequest; | |
class EventService extends \Concrete\Core\Calendar\Event\EventService | |
{ | |
public function addEventVersion(CalendarEvent $event, Calendar $calendar, CalendarEventVersion $version, $repetitions = []) | |
{ | |
parent::addEventVersion($event, $calendar, $version, $repetitions); | |
$enableMoreDetails = $calendar->enableMoreDetails(); | |
if ($enableMoreDetails === 'C' && !$version->getPageID()) { | |
// We haven't created a page yet. So let's make one, but keep it as draft | |
$parent = Page::getDraftsParentPage(); | |
if (is_object($parent) && !$parent->isError()) { | |
$type = Type::getByID($calendar->getEventPageTypeID()); | |
if (is_object($type)) { | |
$page = $parent->add($type, [ | |
'cName' => $version->getName(), | |
'cIsDraft' => 1, | |
'cIsActive' => 0, | |
'cvIsApproved' => 0, | |
'cAcquireComposerOutputControls' => true, | |
]); | |
$page->setAttribute($calendar->getEventPageAttributeKeyHandle(), $event); | |
$version->setPageID($page->getCollectionID()); | |
$version->setRelatedPageRelationType('C'); | |
$this->save($event); | |
} | |
} | |
} | |
} | |
public function approve(CalendarEventVersion $version) | |
{ | |
parent::approve($version); | |
/** @var CalendarEvent $event */ | |
$event = $version->getEvent(); | |
$calendar = $event->getCalendar(); | |
if ($version->getPageID()) { | |
// If the page is not approved, let's approve it also | |
$page = Page::getByID($version->getPageID()); | |
if (!$page->isActive()) { | |
$parent = Page::getByID($calendar->getEventPageParentID()); | |
$cp = new Checker($page); | |
if ($cp->canApprovePageVersions() && $cp->canMoveCopyTo($parent)) { | |
$page->move($parent); | |
$u = Application::getFacadeApplication()->make(User::class); | |
$pkr = new ApprovePagePageWorkflowRequest(); | |
$pkr->setRequestedPage($page); | |
$v = $page->getVersionToModify(); | |
$pkr->setRequestedVersionID($v->getVersionID()); | |
$pkr->setRequesterUserID($u->getUserID()); | |
$response = $pkr->trigger(); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment