/** * @return Block\Item[] */ public function getElements() { // init $doc = Model\Document\Page::getById($this->getDocumentId()); $suffixes = (array) $this->suffixes; $suffixes[] = $this->getName(); $list = array(); foreach ($this->getData() as $index) { $list[] = new Block\Item($doc, $index, $suffixes); } return $list; }
public function saveAction() { if ($this->getParam("id")) { $page = Document\Page::getById($this->getParam("id")); $page = $this->getLatestVersion($page); $page->setUserModification($this->getUser()->getId()); if ($this->getParam("task") == "unpublish") { $page->setPublished(false); } if ($this->getParam("task") == "publish") { $page->setPublished(true); } $settings = array(); if ($this->getParam("settings")) { $settings = \Zend_Json::decode($this->getParam("settings")); } // check for redirects if ($this->getUser()->isAllowed("redirects") && $this->getParam("settings")) { if (is_array($settings)) { $redirectList = new Redirect\Listing(); $redirectList->setCondition("target = ?", $page->getId()); $existingRedirects = $redirectList->load(); $existingRedirectIds = array(); foreach ($existingRedirects as $existingRedirect) { $existingRedirectIds[$existingRedirect->getId()] = $existingRedirect->getId(); } for ($i = 1; $i < 100; $i++) { if (array_key_exists("redirect_url_" . $i, $settings)) { // check for existing if ($settings["redirect_id_" . $i]) { $redirect = Redirect::getById($settings["redirect_id_" . $i]); unset($existingRedirectIds[$redirect->getId()]); } else { // create new one $redirect = new Redirect(); } $redirect->setSource($settings["redirect_url_" . $i]); $redirect->setTarget($page->getId()); $redirect->setStatusCode(301); $redirect->save(); } } // remove existing redirects which were delete foreach ($existingRedirectIds as $existingRedirectId) { $redirect = Redirect::getById($existingRedirectId); $redirect->delete(); } } } // check if settings exist, before saving meta data if ($this->getParam("settings") && is_array($settings)) { $metaData = array(); for ($i = 1; $i < 30; $i++) { if (array_key_exists("metadata_idName_" . $i, $settings)) { $metaData[] = array("idName" => $settings["metadata_idName_" . $i], "idValue" => $settings["metadata_idValue_" . $i], "contentName" => $settings["metadata_contentName_" . $i], "contentValue" => $settings["metadata_contentValue_" . $i]); } } $page->setMetaData($metaData); } // only save when publish or unpublish if ($this->getParam("task") == "publish" && $page->isAllowed("publish") or $this->getParam("task") == "unpublish" && $page->isAllowed("unpublish")) { $this->setValuesToDocument($page); try { $page->save(); $this->saveToSession($page); $this->_helper->json(array("success" => true)); } catch (\Exception $e) { \Logger::err($e); $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } else { if ($page->isAllowed("save")) { $this->setValuesToDocument($page); try { $page->saveVersion(); $this->saveToSession($page); $this->_helper->json(array("success" => true)); } catch (\Exception $e) { \Logger::err($e); $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } } } $this->_helper->json(false); }
/** * @param $name * * @return Model\Document\Tag */ public function getElement($name) { // init $doc = Model\Document\Page::getById($this->getDocumentId()); $id = sprintf('%s%s%d', $name, $this->getName(), 1); $element = $doc->getElement($id); $element->suffixes = array($this->getName()); return $element; }
/** * @param $name * * @return Areablock\Item[] */ public function getElement($name) { // init $doc = Model\Document\Page::getById($this->getDocumentId()); $list = array(); foreach ($this->getData() as $index => $item) { if ($item['type'] == $name) { $list[$index] = new Areablock\Item($doc, $this->getName(), $item['key']); } } return $list; }
public function saveAction() { try { if ($this->getParam("id")) { $page = Document\Page::getById($this->getParam("id")); // check if there's a document in session which should be used as data-source // see also self::clearEditableDataAction() | this is necessary to reset all fields and to get rid of // outdated and unused data elements in this document (eg. entries of area-blocks) $pageSession = Session::useSession(function ($session) use($page) { if (isset($session->{"document_" . $page->getId()}) && isset($session->{"document_" . $page->getId() . "_useForSave"})) { if ($session->{"document_" . $page->getId() . "_useForSave"}) { // only use the page from the session once unset($session->{"document_" . $page->getId() . "_useForSave"}); return $session->{"document_" . $page->getId()}; } } return null; }, "pimcore_documents"); if ($pageSession) { $page = $pageSession; } else { $page = $this->getLatestVersion($page); } $page->setUserModification($this->getUser()->getId()); if ($this->getParam("task") == "unpublish") { $page->setPublished(false); } if ($this->getParam("task") == "publish") { $page->setPublished(true); } $settings = []; if ($this->getParam("settings")) { $settings = \Zend_Json::decode($this->getParam("settings")); } // check for redirects if ($this->getUser()->isAllowed("redirects") && $this->getParam("settings")) { if (is_array($settings)) { $redirectList = new Redirect\Listing(); $redirectList->setCondition("target = ?", $page->getId()); $existingRedirects = $redirectList->load(); $existingRedirectIds = []; foreach ($existingRedirects as $existingRedirect) { $existingRedirectIds[$existingRedirect->getId()] = $existingRedirect->getId(); } for ($i = 1; $i < 100; $i++) { if (array_key_exists("redirect_url_" . $i, $settings)) { // check for existing if ($settings["redirect_id_" . $i]) { $redirect = Redirect::getById($settings["redirect_id_" . $i]); unset($existingRedirectIds[$redirect->getId()]); } else { // create new one $redirect = new Redirect(); } $redirect->setSource($settings["redirect_url_" . $i]); $redirect->setTarget($page->getId()); $redirect->setStatusCode(301); $redirect->save(); } } // remove existing redirects which were delete foreach ($existingRedirectIds as $existingRedirectId) { $redirect = Redirect::getById($existingRedirectId); $redirect->delete(); } } } // check if settings exist, before saving meta data if ($this->getParam("settings") && is_array($settings)) { $metaData = []; for ($i = 1; $i < 30; $i++) { if (array_key_exists("metadata_" . $i, $settings)) { $metaData[] = $settings["metadata_" . $i]; } } $page->setMetaData($metaData); } // only save when publish or unpublish if ($this->getParam("task") == "publish" && $page->isAllowed("publish") or $this->getParam("task") == "unpublish" && $page->isAllowed("unpublish")) { $this->setValuesToDocument($page); try { $page->save(); $this->saveToSession($page); $this->_helper->json(["success" => true]); } catch (\Exception $e) { if (\Pimcore\Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) { throw $e; } Logger::err($e); $this->_helper->json(["success" => false, "message" => $e->getMessage()]); } } else { if ($page->isAllowed("save")) { $this->setValuesToDocument($page); try { $page->saveVersion(); $this->saveToSession($page); $this->_helper->json(["success" => true]); } catch (\Exception $e) { Logger::err($e); $this->_helper->json(["success" => false, "message" => $e->getMessage()]); } } } } } catch (\Exception $e) { Logger::log($e); if (\Pimcore\Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) { $this->_helper->json(["success" => false, "type" => "ValidationException", "message" => $e->getMessage(), "stack" => $e->getTraceAsString(), "code" => $e->getCode()]); } throw $e; } $this->_helper->json(false); }
public static function setup() { // Reset first page $document = Document\Page::getById(1); $document->setModule("Multilingual"); $document->setController("default"); $document->setAction('language-detection'); $document->save(); // Add predefined property $property = Property\Predefined::create(); $property->setValues(array('key' => 'doNotSyncProperties', 'name' => 'Multilingual: Do not sync properties', 'description' => 'Do not sync properties across documents in other languages', 'data' => 1, 'type' => 'bool', 'ctype' => 'document', 'inheritable' => false)); $property->save(); }