Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GeneratorBundle] refactored formpage generator #2245

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ class GenerateFormPageCommand extends KunstmaanGenerateCommand
/**
* @var array
*/
private $sections;
private $sections = [];

/**
* @var array
*/
private $parentPages;
private $parentPages = [];

/**
* @var bool
Expand Down Expand Up @@ -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());
}
}
9 changes: 5 additions & 4 deletions src/Kunstmaan/GeneratorBundle/Generator/FormPageGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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';
Expand All @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/Kunstmaan/GeneratorBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }