public function saveForm(Page $c) { $controls = Control::getList($this->type); $outputControls = array(); foreach ($controls as $cn) { $data = $cn->getRequestValue(); $cn->publishToPage($c, $data, $controls); $outputControls[] = $cn; } // set page name from controls // now we see if there's a page name field in there $containsPageNameControl = false; foreach ($outputControls as $cn) { if ($cn instanceof NameCorePageProperty) { $containsPageNameControl = true; break; } } if (!$containsPageNameControl) { foreach ($outputControls as $cn) { if ($cn->canPageTypeComposerControlSetPageName()) { $pageName = $cn->getPageTypeComposerControlPageNameValue($c); $c->updateCollectionName($pageName); } } } // remove all but the most recent X drafts. if ($c->isPageDraft()) { $vl = new VersionList($c); $vl->setItemsPerPage(-1); // this will ensure that we only ever keep X versions. $vArray = $vl->getPage(); if (count($vArray) > $this->ptDraftVersionsToSave) { for ($i = $this->ptDraftVersionsToSave; $i < count($vArray); ++$i) { $v = $vArray[$i]; @$v->delete(); } } } $c = Page::getByID($c->getCollectionID(), 'RECENT'); $controls = array(); foreach ($outputControls as $oc) { $oc->setPageObject($c); $controls[] = $oc; } $ev = new Event($c); $ev->setPageType($this->type); $ev->setArgument('controls', $controls); \Events::dispatch('on_page_type_save_composer_form', $ev); return $controls; }
public function publish(Page $c, $requestOrDateTime = null) { $this->stripEmptyPageTypeComposerControls($c); $parent = Page::getByID($c->getPageDraftTargetParentPageID()); if ($c->isPageDraft()) { // this is still a draft, which means it has never been properly published. // so we need to move it, check its permissions, etc... Section::registerPage($c); $c->move($parent); if (!$parent->overrideTemplatePermissions()) { // that means the permissions of pages added beneath here inherit from page type permissions // this is a very poorly named method. Template actually used to mean Type. // so this means we need to set the permissions of this current page to inherit from page types. $c->inheritPermissionsFromDefaults(); } $c->activate(); } else { $c->rescanCollectionPath(); } $u = new User(); if (!$requestOrDateTime instanceof ApprovePagePageWorkflowRequest) { $v = CollectionVersion::get($c, 'RECENT'); $pkr = new ApprovePagePageWorkflowRequest(); $pkr->setRequestedPage($c); $pkr->setRequestedVersionID($v->getVersionID()); $pkr->setRequesterUserID($u->getUserID()); if ($requestOrDateTime) { // That means it's a date time $pkr->scheduleVersion($requestOrDateTime); } } else { $pkr = $requestOrDateTime; } $pkr->trigger(); $u->unloadCollectionEdit($c); CacheLocal::flush(); $ev = new Event($c); $ev->setPageType($this); $ev->setUser($u); \Events::dispatch('on_page_type_publish', $ev); }