From bc1ae5a2dfcb2b2039b51dc84a10ad12d0f95e32 Mon Sep 17 00:00:00 2001 From: Peter Zentjens Date: Mon, 21 Jan 2019 16:54:03 +0100 Subject: [PATCH] [GeneratorBundle] refactored formpage generator --- .../GeneratorBundle/Command/GenerateFormPageCommand.php | 6 +++--- .../GeneratorBundle/Generator/FormPageGenerator.php | 9 +++++---- .../GeneratorBundle/Resources/config/services.yml | 8 ++++++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Kunstmaan/GeneratorBundle/Command/GenerateFormPageCommand.php b/src/Kunstmaan/GeneratorBundle/Command/GenerateFormPageCommand.php index b026d027ca..cbf316973c 100644 --- a/src/Kunstmaan/GeneratorBundle/Command/GenerateFormPageCommand.php +++ b/src/Kunstmaan/GeneratorBundle/Command/GenerateFormPageCommand.php @@ -41,12 +41,12 @@ class GenerateFormPageCommand extends KunstmaanGenerateCommand /** * @var array */ - private $sections; + private $sections = []; /** * @var array */ - private $parentPages; + private $parentPages = []; /** * @var bool @@ -224,6 +224,6 @@ protected function createGenerator() $filesystem = $this->getContainer()->get('filesystem'); $registry = $this->getContainer()->get('doctrine'); - return new FormPageGenerator($filesystem, $registry, '/page', $this->assistant); + return new FormPageGenerator($filesystem, $registry, '/page', $this->assistant, $this->getContainer()); } } diff --git a/src/Kunstmaan/GeneratorBundle/Generator/FormPageGenerator.php b/src/Kunstmaan/GeneratorBundle/Generator/FormPageGenerator.php index ac09c39bd3..5528748971 100644 --- a/src/Kunstmaan/GeneratorBundle/Generator/FormPageGenerator.php +++ b/src/Kunstmaan/GeneratorBundle/Generator/FormPageGenerator.php @@ -127,6 +127,7 @@ private function generatePageEntity() 'sections' => $this->sections, 'adminType' => '\\' . $this->bundle->getNamespace() . '\\Form\\Pages\\' . $this->entity . 'AdminType', 'namespace' => $this->registry->getAliasNamespace($this->bundle->getName()) . '\\Pages\\' . $this->entity, + 'isV4' => $this->isSymfony4(), ); $extraCode = $this->render('/Entity/Pages/ExtraFunctions.php', $params); @@ -212,12 +213,12 @@ private function copyTemplateConfig() */ private function updateParentPages() { - $phpCode = " array(\n"; + $phpCode = " [\n"; $phpCode .= " 'name' => '" . $this->entity . "',\n"; $phpCode .= " 'class'=> '" . $this->bundle->getNamespace() . '\\Entity\\Pages\\' . $this->entity . "'\n"; - $phpCode .= ' ),'; + $phpCode .= ' ],'."\n "; // When there is a BehatTestPage, we should also allow the new page as sub page $behatTestPage = $this->bundle->getPath() . '/Entity/Pages/BehatTestPage.php'; @@ -228,8 +229,8 @@ private function updateParentPages() foreach ($this->parentPages as $file) { $data = file_get_contents($file); $data = preg_replace( - '/(function\s*getPossibleChildTypes\s*\(\)\s*\{\s*return\s*array\s*\()/', - "$1\n$phpCode", + '/(function\s*getPossibleChildTypes\s*\(\)\s*\{\s*)(return\s*\[|return\s*array\()/', + "$1$2\n$phpCode", $data ); file_put_contents($file, $data); diff --git a/src/Kunstmaan/GeneratorBundle/Resources/config/services.yml b/src/Kunstmaan/GeneratorBundle/Resources/config/services.yml index 544f1e7d29..d04c168a3c 100644 --- a/src/Kunstmaan/GeneratorBundle/Resources/config/services.yml +++ b/src/Kunstmaan/GeneratorBundle/Resources/config/services.yml @@ -26,3 +26,11 @@ services: Kunstmaan\GeneratorBundle\Command\GeneratePageCommand: tags: - { name: console.command } + + Kunstmaan\GeneratorBundle\Command\GenerateFormPageCommand: + tags: + - { name: console.command } + + Kunstmaan\GeneratorBundle\Command\GenerateFormPagePartsCommand: + tags: + - { name: console.command }