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]);
}
}