private function initializeWebspace(OutputInterface $output, Webspace $webspace) { $homePath = $this->pathBuilder->build(['%base%', $webspace->getKey(), '%content%']); $routesPath = $this->pathBuilder->build(['%base%', $webspace->getKey(), '%route%']); $webspaceLocales = []; foreach ($webspace->getAllLocalizations() as $localization) { $webspaceLocales[] = $localization->getLocalization(); } if ($this->nodeManager->has($homePath)) { $homeDocument = $this->documentManager->find($homePath, 'fr', ['load_ghost_content' => false, 'auto_create' => true, 'path' => $homePath]); $existingLocales = $this->inspector->getLocales($homeDocument); } else { $homeDocument = new HomeDocument(); $homeDocument->setTitle('Homepage'); $homeDocument->setStructureType($webspace->getTheme()->getDefaultTemplate('homepage')); $homeDocument->setWorkflowStage(WorkflowStage::PUBLISHED); $existingLocales = []; } foreach ($webspaceLocales as $webspaceLocale) { $output->writeln(sprintf('<info>Homepage</info>: %s (%s)', $homePath, $webspaceLocale)); if (in_array($webspaceLocale, $existingLocales)) { continue; } $this->nodeManager->createPath($routesPath . '/' . $webspaceLocale); $this->documentManager->persist($homeDocument, $webspaceLocale, ['path' => $homePath]); } }
/** * Create a webspace node with the given locales. * * @param string $name * @param string[] $locales */ protected function createHomeDocument($name, array $locales) { $documentManager = $this->getContainer()->get('sulu_document_manager.document_manager'); $nodeManager = $this->getContainer()->get('sulu_document_manager.node_manager'); $homeDocument = new HomeDocument(); $homeDocument->setTitle('Homepage'); $homeDocument->setStructureType('default'); $homeDocument->setWorkflowStage(WorkflowStage::PUBLISHED); foreach ($locales as $locale) { $nodeManager->createPath('/cmf/' . $name . '/routes/' . $locale); $documentManager->persist($homeDocument, $locale, ['path' => '/cmf/' . $name . '/contents', 'auto_create' => true, 'load_ghost_content' => false]); } $documentManager->flush(); }