From bcdbbb891e45c80879bfa5d30987105d7e5e36a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anke=20H=C3=A4slich?= Date: Mon, 10 Jun 2024 14:54:25 +0200 Subject: [PATCH] TASK: Create a custom document node type for the site root node Relates: neos/neos-development-collection#4563 Relates: neos/neos-development-collection#4567 --- Classes/Generator/AfxTemplateGenerator.php | 28 +++++++------------ .../Fusion/Document/Homepage.fusion | 1 + .../NodeTypes/Document.Homepage.yaml | 11 ++++++++ .../Document.Page.yaml} | 0 4 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 Resources/Private/AfxGenerator/Fusion/Document/Homepage.fusion create mode 100644 Resources/Private/AfxGenerator/NodeTypes/Document.Homepage.yaml rename Resources/Private/AfxGenerator/{Configuration/NodeTypes.Document.Page.yaml => NodeTypes/Document.Page.yaml} (100%) diff --git a/Classes/Generator/AfxTemplateGenerator.php b/Classes/Generator/AfxTemplateGenerator.php index dc6118b..78551df 100755 --- a/Classes/Generator/AfxTemplateGenerator.php +++ b/Classes/Generator/AfxTemplateGenerator.php @@ -13,7 +13,6 @@ * source code. */ -use Neos\ContentRepository\Core\SharedModel\Node\NodeName; use Neos\Flow\Annotations as Flow; use Neos\Flow\Package\PackageManager; use Neos\Kickstarter\Service\GeneratorService; @@ -86,11 +85,8 @@ protected function generateSitesFusionDirectory(string $packageKey, string $site $contextVariables['siteNodeName'] = $packageKeyDomainPart; $fusionRecursiveDirectoryRenderer = new FusionRecursiveDirectoryRenderer(); - - $packageDirectory = $this->packageManager->getPackage('Neos.SiteKickstarter')->getResourcesPath(); - $fusionRecursiveDirectoryRenderer->renderDirectory( - $packageDirectory . 'Private/AfxGenerator/Fusion', + $this->getTemplateFolder() . 'Fusion', $this->packageManager->getPackage($packageKey)->getResourcesPath() . 'Private/Fusion', $contextVariables ); @@ -104,16 +100,18 @@ protected function generateSitesFusionDirectory(string $packageKey, string $site */ protected function generateNodeTypesConfiguration(string $packageKey) : void { - $templatePathAndFilename = $this->getResourcePathForFile('Configuration/NodeTypes.Document.Page.yaml'); + $templateFolder = $this->getTemplateFolder() . 'NodeTypes'; + $targetFolder = $this->packageManager->getPackage($packageKey)->getPackagePath() . 'NodeTypes'; $contextVariables = [ 'packageKey' => $packageKey ]; - $fileContent = $this->simpleTemplateRenderer->render($templatePathAndFilename, $contextVariables); - - $sitesNodeTypesPathAndFilename = $this->packageManager->getPackage($packageKey)->getConfigurationPath() . 'NodeTypes.Document.Page.yaml'; - $this->generateFile($sitesNodeTypesPathAndFilename, $fileContent); + foreach (Files::readDirectoryRecursively($templateFolder, '.yaml') as $templatePathAndFilename) { + $fileContent = $this->simpleTemplateRenderer->render($templatePathAndFilename, $contextVariables); + $targetPathAndFilename = str_replace($templateFolder, $targetFolder, $templatePathAndFilename); + $this->generateFile($targetPathAndFilename, $fileContent); + } } /** @@ -133,15 +131,9 @@ protected function generateAdditionalFolders(string $packageKey) : void } } - /** - * returns resource path for the generator - * - * @param $pathToFile - * @return string - */ - protected function getResourcePathForFile(string $pathToFile) : string + protected function getTemplateFolder(): string { - return 'resource://Neos.SiteKickstarter/Private/AfxGenerator/' . $pathToFile; + return $this->packageManager->getPackage('Neos.SiteKickstarter')->getResourcesPath() . 'Private/AfxGenerator/'; } public function getGeneratorName(): string diff --git a/Resources/Private/AfxGenerator/Fusion/Document/Homepage.fusion b/Resources/Private/AfxGenerator/Fusion/Document/Homepage.fusion new file mode 100644 index 0000000..8737907 --- /dev/null +++ b/Resources/Private/AfxGenerator/Fusion/Document/Homepage.fusion @@ -0,0 +1 @@ +prototype({packageKey}:Document.Homepage) < prototype({packageKey}:Document.AbstractPage) diff --git a/Resources/Private/AfxGenerator/NodeTypes/Document.Homepage.yaml b/Resources/Private/AfxGenerator/NodeTypes/Document.Homepage.yaml new file mode 100644 index 0000000..a51a0e6 --- /dev/null +++ b/Resources/Private/AfxGenerator/NodeTypes/Document.Homepage.yaml @@ -0,0 +1,11 @@ +# This is a custom root node type which has been auto-generated for your site package +# by Neos. You can customize this to your needs. +'{packageKey}:Document.Homepage': + superTypes: + 'Neos.Neos:Site': true + ui: + icon: globe + label: '{packageKey} Homepage' + childNodes: + main: + type: 'Neos.Neos:ContentCollection' diff --git a/Resources/Private/AfxGenerator/Configuration/NodeTypes.Document.Page.yaml b/Resources/Private/AfxGenerator/NodeTypes/Document.Page.yaml similarity index 100% rename from Resources/Private/AfxGenerator/Configuration/NodeTypes.Document.Page.yaml rename to Resources/Private/AfxGenerator/NodeTypes/Document.Page.yaml