public function initialize(OutputInterface $output, $purge = false) { $nodeTypeManager = $this->sessionManager->getSession()->getWorkspace()->getNodeTypeManager(); foreach ([new CustomUrlNodeType(), new CustomUrlRouteNodeType()] as $nodeType) { $nodeTypeManager->registerNodeType($nodeType, true); } /** @var Webspace $webspace */ foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) { $itemsPath = $this->pathBuilder->build(['%base%', $webspace->getKey(), '%custom_urls%', '%custom_urls_items%']); $routesPath = $this->pathBuilder->build(['%base%', $webspace->getKey(), '%custom_urls%', '%custom_urls_routes%']); $output->writeln(sprintf(' <info>%s</info>:', $webspace->getName())); if (true === $this->nodeManager->has($itemsPath)) { $output->writeln(sprintf(' [ ] <info>items path:</info>: %s ', $itemsPath)); } else { $output->writeln(sprintf(' [+] <info>items path:</info>: %s ', $itemsPath)); $this->nodeManager->createPath($itemsPath); } if (true === $this->nodeManager->has($routesPath)) { $output->writeln(sprintf(' [ ] <info>items path:</info>: %s ', $routesPath)); } else { $output->writeln(sprintf(' [+] <info>items path:</info>: %s ', $routesPath)); $this->nodeManager->createPath($routesPath); } $this->nodeManager->save(); } }
public function handlePersist(PersistEvent $event) { $document = $event->getDocument(); if (!$this->supports($document)) { return; } $parentName = $this->getParentName($document); $path = sprintf('%s/%s', $this->basePath, $parentName); $parentNode = $this->nodeManager->createPath($path); $event->setParentNode($parentNode); }
private function resolveParent($parentPath, array $options) { $autoCreate = $options['auto_create']; if ($autoCreate) { return $this->nodeManager->createPath($parentPath); } return $this->nodeManager->find($parentPath); }
/** * It should set the parent document. */ public function testSetParentDocument() { $this->persistEvent->getDocument()->willReturn($this->document->reveal()); $this->persistEvent->getLocale()->willReturn('fr'); $this->metadataFactory->getMetadataForClass(get_class($this->document->reveal()))->willReturn($this->metadata->reveal()); $this->metadata->getAlias()->willReturn('test'); $this->nodeManager->createPath('/')->willReturn($this->parentNode->reveal()); $this->persistEvent->hasParentNode()->shouldBeCalled(); $this->persistEvent->setParentNode($this->parentNode->reveal())->shouldBeCalled(); $this->documentManager->find('/test', 'fr')->willReturn($this->parentDocument); $this->subscriber->handlePersist($this->persistEvent->reveal()); }