Esempio n. 1
0
    public function publish() {
		if ($this->validateAction()) {
			$r = $this->save();
			$ptr = $r[0];
			$pagetype = $r[1];
			$outputControls = $r[2];

			$c = $this->page;
			$e = $ptr->error;
			if (!$c->getPageDraftTargetParentPageID()) {
				$e->add(t('You must choose a page to publish this page beneath.'));
			} else {
				$target = \Page::getByID($c->getPageDraftTargetParentPageID());
				$ppc = new \Permissions($target);
				$pagetype = $c->getPageTypeObject();
				if (!$ppc->canAddSubCollection($pagetype)) {
					$e->add(t('You do not have permission to publish a page in this location.'));
				}
			}
			$validator = $pagetype->getPageTypeValidatorObject();
			$e->add($validator->validatePublishDraftRequest($c));

			$ptr->setError($e);

			if (!$e->has()) {
				$pagetype->publish($c);
				$ptr->setRedirectURL(Loader::helper('navigation')->getLinkToCollection($c));
			}
			$ptr->outputJSON();
		} else {
			throw new \Exception(t('Access Denied.'));
		}
	}
Esempio n. 2
0
 public function publish()
 {
     $r = $this->save();
     $ptr = $r[0];
     $pagetype = $r[1];
     $outputControls = $r[2];
     $c = $this->page;
     $e = Loader::helper('validation/error');
     if (!$c->getPageDraftTargetParentPageID()) {
         $e->add(t('You must choose a page to publish this page beneath.'));
     } else {
         $target = \Page::getByID($c->getPageDraftTargetParentPageID());
         $ppc = new \Permissions($target);
         if (!$ppc->canAddSubCollection($target)) {
             $e->add(t('You do not have permission to publish a page in this location.'));
         }
     }
     foreach ($outputControls as $oc) {
         if ($oc->isPageTypeComposerFormControlRequiredOnThisRequest()) {
             $r = $oc->validate();
             if ($r instanceof \Concrete\Core\Error\Error) {
                 $e->add($r);
             }
         }
     }
     $ptr->setError($e);
     if (!$e->has()) {
         $pagetype->publish($c);
         $ptr->setRedirectURL(Loader::helper('navigation')->getLinkToCollection($c));
     }
     $ptr->outputJSON();
 }