예제 #1
0
 /**
  * @param PageType $pt
  * @param \Controller $cnt
  */
 public function addAssetsToRequest(PageType $pt, \Controller $cnt)
 {
     $list = PageTypeComposerControl::getList($pt);
     foreach ($list as $l) {
         $l->addAssetsToRequest($cnt);
     }
 }
예제 #2
0
 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 validatePublishDraftRequest(Page $page = null)
 {
     $e = Core::make('error');
     $controls = Control::getList($this->type);
     foreach ($controls as $oc) {
         if (is_object($page)) {
             $oc->setPageObject($page);
         }
         if ($oc->isPageTypeComposerFormControlRequiredOnThisRequest()) {
             $r = $oc->validate();
             if ($r instanceof ErrorList) {
                 $e->add($r);
             }
         }
     }
     return $e;
 }
예제 #4
0
 protected function checkForPublishing()
 {
     $c = $this->page;
     // verify this page type has all the items necessary to be approved.
     $e = Loader::helper('validation/error');
     if ($c->isPageDraft()) {
         if (!$c->getPageDraftTargetParentPageID()) {
             $e->add(t('You must choose a page to publish this page beneath.'));
         }
     }
     $pagetype = $c->getPageTypeObject();
     if (is_object($pagetype)) {
         $controls = PageTypeComposerControl::getList($pagetype);
         foreach ($controls as $oc) {
             if ($oc->isPageTypeComposerFormControlRequiredOnThisRequest()) {
                 $oc->setPageObject($c);
                 $r = $oc->validate();
                 if ($r instanceof \Concrete\Core\Error\Error) {
                     $e->add($r);
                 }
             }
         }
     }
     if ($c->isPageDraft() && !$e->has()) {
         $targetParentID = $c->getPageDraftTargetParentPageID();
         if ($targetParentID) {
             $tp = Page::getByID($targetParentID, 'ACTIVE');
             $pp = new Permissions($tp);
             if (!is_object($tp) || $tp->isError()) {
                 $e->add(t('Invalid target page.'));
             } else {
                 if (!$pp->canAddSubCollection($pagetype)) {
                     $e->add(t('You do not have permissions to add a page of this type in the selected location.'));
                 }
             }
         }
     }
     return $e;
 }
예제 #5
0
파일: Type.php 프로젝트: ceko/concrete5-1
 public function createDraft(PageTemplate $pt, $u = false)
 {
     if (!is_object($u)) {
         $u = new User();
     }
     $db = Loader::db();
     $ptID = $this->getPageTypeID();
     $parent = Page::getByPath(Config::get('concrete.paths.drafts'));
     $data = array('cvIsApproved' => 0);
     $p = $parent->add($this, $data, $pt);
     $p->deactivate();
     // now we setup in the initial configurated page target
     $target = $this->getPageTypePublishTargetObject();
     $cParentID = $target->getDefaultParentPageID();
     if ($cParentID > 0) {
         $p->setPageDraftTargetParentPageID($cParentID);
     }
     // we have to publish the controls to the page. i'm not sure why
     $controls = PageTypeComposerControl::getList($this);
     $outputControls = array();
     foreach ($controls as $cn) {
         $cn->publishToPage($p, array(), $controls);
     }
     // now we need to clear out the processed controls in case we
     // save again in the same request
     CorePagePropertyPageTypeComposerControl::clearComposerRequestProcessControls();
     return $p;
 }
예제 #6
0
 public function addToPageTypeComposerFormLayoutSet(PageTypeComposerFormLayoutSet $set, $import = false)
 {
     $layoutSetControl = parent::addToPageTypeComposerFormLayoutSet($set, $import);
     $pagetype = $set->getPageTypeObject();
     $pagetype->rescanPageTypeComposerOutputControlObjects();
     return $layoutSetControl;
 }
예제 #7
0
 public function createDraft(\Concrete\Core\Entity\Page\Template $pt, $u = false)
 {
     if (!is_object($u)) {
         $u = new User();
     }
     $db = Loader::db();
     $ptID = $this->getPageTypeID();
     $parent = Page::getByPath(Config::get('concrete.paths.drafts'));
     $data = array('cvIsApproved' => 0, 'cIsActive' => false, 'cAcquireComposerOutputControls' => true);
     $p = $parent->add($this, $data, $pt);
     // now we setup in the initial configurated page target
     $target = $this->getPageTypePublishTargetObject();
     $cParentID = $target->getDefaultParentPageID();
     if ($cParentID > 0) {
         $p->setPageDraftTargetParentPageID($cParentID);
     }
     $controls = PageTypeComposerControl::getList($this);
     foreach ($controls as $cn) {
         $cn->onPageDraftCreate($p);
     }
     return $p;
 }
 public function addToPageTypeComposerFormLayoutSet(PageTypeComposerFormLayoutSet $set, $import = false)
 {
     $layoutSetControl = parent::addToPageTypeComposerFormLayoutSet($set, $import);
     $pagetype = $set->getPageTypeObject();
     $pagetype->rescanPageTypeComposerOutputControlObjects();
     if (!$import) {
         // we ensure that an output control block exists in the main area.
         $bt = \BlockType::getByHandle(BLOCK_HANDLE_PAGE_TYPE_OUTPUT_PROXY);
         $pagetype = $set->getPageTypeObject();
         $templates = $pagetype->getPageTypePageTemplateObjects();
         foreach ($templates as $template) {
             $c = $pagetype->getPageTypePageTemplateDefaultPageObject($template);
             $outputControl = $layoutSetControl->getPageTypeComposerOutputControlObject($template);
             if (is_object($c) && !$c->isError()) {
                 $c->addBlock($bt, 'Main', array('ptComposerOutputControlID' => $outputControl->getPageTypeComposerOutputControlID()));
             }
         }
     }
     return $layoutSetControl;
 }