public static wrap ( |
||
$doc | ||
return |
public function getChilds() { if ($this->childs === null) { $hardLink = $this->getHardLinkSource(); $childs = array(); if ($hardLink->getChildsFromSource() && $hardLink->getSourceDocument() && !\Pimcore::inAdmin()) { foreach (parent::getChilds() as $c) { $sourceDocument = $c; $c = Service::wrap($c); if ($c) { $c->setHardLinkSource($hardLink); $c->setSourceDocument($sourceDocument); $c->setPath(preg_replace("@^" . preg_quote($hardLink->getSourceDocument()->getRealFullpath()) . "@", $hardLink->getRealFullpath(), $c->getRealPath())); $childs[] = $c; } } } $this->setChilds($childs); } return $this->childs; }
/** * @param bool $unpublished * @return array|null */ public function getChilds($unpublished = false) { if ($this->childs === null) { $childs = parent::getChilds(); $sourceChilds = array(); if ($this->getChildsFromSource() && $this->getSourceDocument() && !\Pimcore::inAdmin()) { $sourceChilds = $this->getSourceDocument()->getChilds(); foreach ($sourceChilds as &$c) { $c = Document\Hardlink\Service::wrap($c); $c->setHardLinkSource($this); $c->setPath(preg_replace("@^" . preg_quote($this->getSourceDocument()->getFullpath()) . "@", $this->getFullpath(), $c->getPath())); } } $childs = array_merge($sourceChilds, $childs); $this->setChilds($childs); } return $this->childs; }
/** * @return Document */ public function getDocument() { $docId = $this->getDocumentId(); if ($docId) { $doc = Document::getById($docId); if ($doc instanceof Document\Hardlink) { $doc = Document\Hardlink\Service::wrap($doc); } return $doc; } return null; }
/** * @param $parentDocument * @param bool $isRoot * @param callable $pageCallback * @return array */ protected function buildNextLevel($parentDocument, $isRoot = false, $pageCallback = null) { $pages = array(); $childs = $this->getChilds($parentDocument); if (is_array($childs)) { foreach ($childs as $child) { $classes = ""; if ($child instanceof Document\Hardlink) { $child = Document\Hardlink\Service::wrap($child); } if (($child instanceof Document\Page or $child instanceof Document\Link) and $child->getProperty("navigation_name")) { $path = $child->getFullPath(); if ($child instanceof Document\Link) { $path = $child->getHref(); } $page = new $this->_pageClass(); $page->setUri($path . $child->getProperty("navigation_parameters") . $child->getProperty("navigation_anchor")); $page->setLabel($child->getProperty("navigation_name")); $page->setActive(false); $page->setId($this->_htmlMenuIdPrefix . $child->getId()); $page->setClass($child->getProperty("navigation_class")); $page->setTarget($child->getProperty("navigation_target")); $page->setTitle($child->getProperty("navigation_title")); $page->setAccesskey($child->getProperty("navigation_accesskey")); $page->setTabindex($child->getProperty("navigation_tabindex")); $page->setRelation($child->getProperty("navigation_relation")); $page->setDocument($child); if ($child->getProperty("navigation_exclude") || !$child->getPublished()) { $page->setVisible(false); } if ($isRoot) { $classes .= " main"; } $page->setClass($page->getClass() . $classes); if ($pageCallback) { $pageCallback($page, $child); } if ($child->hasChilds()) { $childPages = $this->buildNextLevel($child, false); $page->setPages($childPages); } $pages[] = $page; } } } return $pages; }
/** * @param $path * @param bool $ignoreHardlinks * @param array $types * @return Document|Document\PageSnippet|null|string */ protected function getNearestDocumentByPath($path, $ignoreHardlinks = false, $types = array()) { if ($this->nearestDocumentByPath instanceof Document) { $document = $this->nearestDocumentByPath; } else { $pathes = array(); $pathes[] = "/"; $pathParts = explode("/", $path); $tmpPathes = array(); foreach ($pathParts as $pathPart) { $tmpPathes[] = $pathPart; $t = implode("/", $tmpPathes); if (!empty($t)) { $pathes[] = $t; } } $pathes = array_reverse($pathes); foreach ($pathes as $p) { if ($document = Document::getByPath($p)) { if (empty($types) || in_array($document->getType(), $types)) { $this->nearestDocumentByPath = $document; break; } } else { if (Site::isSiteRequest()) { // also check for a pretty url in a site $site = Site::getCurrentSite(); $documentService = new Document\Service(); // undo the changed made by the site detection in self::match() $originalPath = preg_replace("@^" . $site->getRootPath() . "@", "", $p); $sitePrettyDocId = $documentService->getDocumentIdByPrettyUrlInSite($site, $originalPath); if ($sitePrettyDocId) { if ($sitePrettyDoc = Document::getById($sitePrettyDocId)) { $this->nearestDocumentByPath = $sitePrettyDoc; break; } } } } } } if ($document) { if (!$ignoreHardlinks) { if ($document instanceof Document\Hardlink) { if ($hardLinkedDocument = Document\Hardlink\Service::getNearestChildByPath($document, $path)) { $document = $hardLinkedDocument; } else { $document = Document\Hardlink\Service::wrap($document); } } } return $document; } return null; }
<?php foreach ($this->allChildren as $child) { ?> <?php if ($child instanceof \Pimcore\Model\Document\Hardlink) { $child = \Pimcore\Model\Document\Hardlink\Service::wrap($child); } ?> <?php echo $this->inc($child); }