/** * {@inheritdoc} */ protected function initialize() { if (true === $this->initialized) { return; } $references = $this->node->getReferences(); // TODO: Performance: calling getParent adds overhead when the collection is // initialized, but if we don't do this, we won't know how many items are in the // collection, as one node could have many referring properties. foreach ($references as $reference) { /* @var PropertyInterface $reference */ $referrerNode = $reference->getParent(); $this->documents[$referrerNode->getIdentifier()] = $referrerNode; } $this->initialized = true; }
/** * changes path node to history node. * * @param NodeInterface $node * @param SessionInterface $session * @param string $absSrcPath * @param string $absDestPath */ private function changePathToHistory(NodeInterface $node, SessionInterface $session, $absSrcPath, $absDestPath) { // get new path node $relPath = str_replace($absSrcPath, '', $node->getPath()); $newPath = PathHelper::normalizePath($absDestPath . $relPath); $newPathNode = $session->getNode($newPath); // set history to true and set content to new path $node->setProperty('sulu:content', $newPathNode); $node->setProperty('sulu:history', true); // get referenced history /** @var PropertyInterface $property */ foreach ($node->getReferences('sulu:content') as $property) { $property->getParent()->setProperty('sulu:content', $newPathNode); } }
/** * Iterates over all route nodes assigned by the given node, and executes the callback on it. * * @param NodeInterface $node * @param callable $callback will be called foreach route node (stops and return value if not false) * @param string $webspaceKey * @param string $languageCode * @param string $segmentKey * * @return \PHPCR\NodeInterface */ private function iterateRouteNodes(NodeInterface $node, $callback, $webspaceKey, $languageCode, $segmentKey = null) { if ($node->isNew()) { return; } $routePath = $this->sessionManager->getRoutePath($webspaceKey, $languageCode); // search for references with name 'content' foreach ($node->getReferences('sulu:content') as $ref) { if ($ref instanceof \PHPCR\PropertyInterface) { $routeNode = $ref->getParent(); if (0 !== strpos($routeNode->getPath(), $routePath)) { continue; } $resourceLocator = $this->getResourceLocator($ref->getParent()->getPath(), $webspaceKey, $languageCode, $segmentKey); $result = $callback($resourceLocator, $routeNode); if (false !== $result) { return $result; } } } return; }
/** * {@inheritdoc} */ public function getReferences($name = null) { return $this->node->getReferences($name); }
/** * @param $node */ private function removeReferencesForNode(NodeInterface $node) { $references = $node->getReferences(); foreach ($references as $reference) { $referrer = $reference->getParent(); $metadata = $this->metadataFactory->getMetadataForPhpcrNode($referrer); if ($metadata->getClass() === RouteDocument::class) { continue; } $this->dereferenceProperty($node, $reference); } }