/** * Create a new proxy object from the given document for * the given target node. * * TODO: We only pass the document here in order to correctly evaluate its locale * later. I wonder if it necessary. * * @param object $fromDocument * @param NodeInterface $targetNode * * @return \ProxyManager\Proxy\GhostObjectInterface */ public function createProxyForNode($fromDocument, NodeInterface $targetNode) { $eventDispatcher = $this->dispatcher; $registry = $this->registry; $targetMetadata = $this->metadataFactory->getMetadataForPhpcrNode($targetNode); // if node is already registered then just return the registered document if ($this->registry->hasNode($targetNode)) { $document = $this->registry->getDocumentForNode($targetNode); $locale = $registry->getOriginalLocaleForDocument($fromDocument); // If the parent is not loaded in the correct locale, reload it in the correct locale. if ($registry->getOriginalLocaleForDocument($document) !== $locale) { $hydrateEvent = new HydrateEvent($targetNode, $locale); $hydrateEvent->setDocument($document); $this->dispatcher->dispatch(Events::HYDRATE, $hydrateEvent); } return $document; } $initializer = function (LazyLoadingInterface $document, $method, array $parameters, &$initializer) use($fromDocument, $targetNode, $eventDispatcher, $registry) { $locale = $registry->getOriginalLocaleForDocument($fromDocument); $hydrateEvent = new HydrateEvent($targetNode, $locale); $hydrateEvent->setDocument($document); $eventDispatcher->dispatch(Events::HYDRATE, $hydrateEvent); $initializer = null; }; $proxy = $this->proxyFactory->createProxy($targetMetadata->getClass(), $initializer); $locale = $registry->getOriginalLocaleForDocument($fromDocument); $this->registry->registerDocument($proxy, $targetNode, $locale); return $proxy; }
/** * @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); } }
private function upgradeNode(NodeInterface $node, Webspace $webspace, Localization $localization, OutputInterface $output, $depth = 0) { $locale = $localization->getLocale(); $localizedTemplatePropertyName = $this->propertyEncoder->localizedSystemName('template', $locale); if (!$node->hasProperty($localizedTemplatePropertyName)) { return; } $structureMetadata = $this->structureMetadataFactory->getStructureMetadata($this->metadataFactory->getMetadataForPhpcrNode($node)->getAlias(), $node->getPropertyValue($localizedTemplatePropertyName)); $property = $structureMetadata->getPropertyByTagName('sulu.rlp'); if (!$property) { return; } $nodeType = $node->getPropertyValue($this->propertyEncoder->localizedSystemName('nodeType', $locale)); if ($property->getContentTypeName() !== 'resource_locator' && $nodeType !== Structure::NODE_TYPE_CONTENT) { return; } $baseRoutePath = $this->sessionManager->getRoutePath($webspace->getKey(), $localization->getLocale()); foreach ($node->getReferences('sulu:content') as $routeProperty) { if (strpos($routeProperty->getPath(), $baseRoutePath) !== 0) { continue; } $routeNode = $routeProperty->getParent(); if ($routeNode->getPropertyValue('sulu:history') === true) { continue; } $resourceLocator = substr($routeNode->getPath(), strlen($baseRoutePath)); if ($resourceLocator) { // only set if resource locator is not empty // if the resource locator is empty it is the homepage, whose url should not be changed $node->setProperty($this->propertyEncoder->localizedContentName($property->getName(), $locale), $resourceLocator); $prefix = ' '; for ($i = 0; $i < $depth; ++$i) { $prefix .= '-'; } $title = $node->getPropertyValue($this->propertyEncoder->localizedContentName('title', $locale)); $output->writeln($prefix . '> "' . $title . '": ' . $resourceLocator); } break; } }
/** * Instantiate a new document. The class is determined from * the mixins present in the PHPCR node for legacy reasons. * * @param NodeInterface $node * * @return object */ private function getDocumentFromNode(NodeInterface $node) { $metadata = $this->metadataFactory->getMetadataForPhpcrNode($node); return $this->instantiateFromMetadata($metadata); }