/** * Set up node structure */ public function setUp() { parent::setUp(); $site = new Site('example'); $site->setSiteResourcesPackageKey('TYPO3.TYPO3'); $context = new ContentContext('live'); $context->setCurrentSite($site); $nodeRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\NodeRepository'); ObjectAccess::setProperty($nodeRepository, 'context', $context, TRUE); $siteImportService = $this->objectManager->get('TYPO3\\TYPO3\\Domain\\Service\\SiteImportService'); $siteImportService->importSitesFromFile(__DIR__ . '/Fixtures/NodeStructure.xml'); $this->persistenceManager->persistAll(); $propertyMapper = $this->objectManager->get('TYPO3\\FLOW3\\Property\\PropertyMapper'); $this->homeNode = $propertyMapper->convert('/sites/example/home', 'TYPO3\\TYPO3CR\\Domain\\Model\\Node'); $this->assertFalse($propertyMapper->getMessages()->hasErrors()); }
/** * Returns the initialized node that is referenced by $relativeContextNodePath * * @param string $relativeContextNodePath * @return \TYPO3\TYPO3CR\Domain\Model\NodeInterface * @throws \TYPO3\TYPO3\Routing\Exception\NoWorkspaceException * @throws \TYPO3\TYPO3\Routing\Exception\NoSiteException * @throws \TYPO3\TYPO3\Routing\Exception\NoSuchNodeException * @throws \TYPO3\TYPO3\Routing\Exception\NoSiteNodeException * @throws \TYPO3\TYPO3\Routing\Exception\InvalidRequestPathException */ public function getNodeByContextNodePath($relativeContextNodePath) { if ($relativeContextNodePath !== '') { preg_match(NodeInterface::MATCH_PATTERN_CONTEXTPATH, $relativeContextNodePath, $matches); if (!isset($matches['NodePath'])) { throw new Exception\InvalidRequestPathException('The request path "' . $relativeContextNodePath . '" is not valid', 1346949309); } $relativeNodePath = $matches['NodePath']; } else { $relativeNodePath = ''; } if ($this->nodeRepository->getContext() === NULL) { $workspaceName = isset($matches['WorkspaceName']) ? $matches['WorkspaceName'] : 'live'; $contentContext = new ContentContext($workspaceName); $contentContext->setInvisibleContentShown(TRUE); $this->nodeRepository->setContext($contentContext); } else { $contentContext = $this->nodeRepository->getContext(); } $workspace = $contentContext->getWorkspace(FALSE); if (!$workspace) { throw new Exception\NoWorkspaceException('No workspace found for request path "' . $relativeContextNodePath . '"', 1346949318); } $site = $contentContext->getCurrentSite(); if (!$site) { throw new Exception\NoSiteException('No site found for request path "' . $relativeContextNodePath . '"', 1346949693); } $siteNode = $contentContext->getCurrentSiteNode(); if (!$siteNode) { throw new Exception\NoSiteNodeException('No site node found for request path "' . $relativeContextNodePath . '"', 1346949728); } $currentAccessModeFromContext = $contentContext->isInaccessibleContentShown(); $contentContext->setInaccessibleContentShown(TRUE); $node = $relativeNodePath === '' ? $siteNode->getPrimaryChildNode() : $siteNode->getNode($relativeNodePath); $contentContext->setInaccessibleContentShown($currentAccessModeFromContext); if (!$node instanceof NodeInterface) { throw new Exception\NoSuchNodeException('No node found on request path "' . $relativeContextNodePath . '"', 1346949857); } return $node; }
/** * Finds the node in the current breadcrumb path between current site node and * current node whose level matches the specified entry level. * * @param integer $givenSiteLevel The site level child nodes of the to be found parent node should have. See $this->entryLevel for possible values. * @param \TYPO3\TYPO3\Domain\Service\ContentContext $contentContext * @return \TYPO3\TYPO3CR\Domain\Model\NodeInterface The parent node of the node at the specified level or NULL if none was found */ private function findParentNodeInBreadcrumbPathByLevel($givenSiteLevel, \TYPO3\TYPO3\Domain\Service\ContentContext $contentContext) { $parentNode = NULL; $breadcrumbNodes = $contentContext->getNodesOnPath($contentContext->getCurrentSiteNode(), $contentContext->getCurrentNode()); if ($givenSiteLevel > 0 && isset($breadcrumbNodes[$givenSiteLevel - 1])) { $parentNode = $breadcrumbNodes[$givenSiteLevel - 1]; } elseif ($givenSiteLevel <= 0) { $currentSiteLevel = count($breadcrumbNodes) - 1; if ($currentSiteLevel + $givenSiteLevel < 1) { $parentNode = $breadcrumbNodes[0]; } else { $parentNode = $breadcrumbNodes[$currentSiteLevel + $givenSiteLevel - 1]; } } return $parentNode; }