Skip to content

Commit

Permalink
Create new template_path var and replace route_name var in render met…
Browse files Browse the repository at this point in the history
…hod parameter in controller template
  • Loading branch information
Thibaut Salanon committed Oct 10, 2018
1 parent 60b0e27 commit 86d24f3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Maker/MakeCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
$entityTwigVarSingular = Str::asTwigVariable($entityVarSingular);

$routeName = Str::asRouteName($controllerClassDetails->getRelativeNameWithoutSuffix());
$templatesPath = Str::asFilePath($controllerClassDetails->getRelativeNameWithoutSuffix());

$generator->generateController(
$controllerClassDetails->getFullName(),
Expand All @@ -137,6 +138,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
'form_class_name' => $formClassDetails->getShortName(),
'route_path' => Str::asRoutePath($controllerClassDetails->getRelativeNameWithoutSuffix()),
'route_name' => $routeName,
'template_path' => $templatesPath,
'entity_var_plural' => $entityVarPlural,
'entity_twig_var_plural' => $entityTwigVarPlural,
'entity_var_singular' => $entityVarSingular,
Expand All @@ -157,8 +159,6 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
]
);

$templatesPath = Str::asFilePath($controllerClassDetails->getRelativeNameWithoutSuffix());

$templates = [
'_delete_form' => [
'route_name' => $routeName,
Expand Down
10 changes: 5 additions & 5 deletions src/Resources/skeleton/crud/controller/Controller.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class <?= $class_name ?> extends <?= $parent_class_name; ?><?= "\n" ?>
<?php if (isset($repository_full_class_name)): ?>
public function index(<?= $repository_class_name ?> $<?= $repository_var ?>): Response
{
return $this->render('<?= $route_name ?>/index.html.twig', ['<?= $entity_twig_var_plural ?>' => $<?= $repository_var ?>->findAll()]);
return $this->render('<?= $template_path ?>/index.html.twig', ['<?= $entity_twig_var_plural ?>' => $<?= $repository_var ?>->findAll()]);
}
<?php else: ?>
public function index(): Response
Expand All @@ -32,7 +32,7 @@ public function index(): Response
->getRepository(<?= $entity_class_name ?>::class)
->findAll();

return $this->render('<?= $route_name ?>/index.html.twig', ['<?= $entity_twig_var_plural ?>' => $<?= $entity_var_plural ?>]);
return $this->render('<?= $template_path ?>/index.html.twig', ['<?= $entity_twig_var_plural ?>' => $<?= $entity_var_plural ?>]);
}
<?php endif ?>

Expand All @@ -53,7 +53,7 @@ public function new(Request $request): Response
return $this->redirectToRoute('<?= $route_name ?>_index');
}

return $this->render('<?= $route_name ?>/new.html.twig', [
return $this->render('<?= $template_path ?>/new.html.twig', [
'<?= $entity_twig_var_singular ?>' => $<?= $entity_var_singular ?>,
'form' => $form->createView(),
]);
Expand All @@ -64,7 +64,7 @@ public function new(Request $request): Response
*/
public function show(<?= $entity_class_name ?> $<?= $entity_var_singular ?>): Response
{
return $this->render('<?= $route_name ?>/show.html.twig', ['<?= $entity_twig_var_singular ?>' => $<?= $entity_var_singular ?>]);
return $this->render('<?= $template_path ?>/show.html.twig', ['<?= $entity_twig_var_singular ?>' => $<?= $entity_var_singular ?>]);
}

/**
Expand All @@ -81,7 +81,7 @@ public function edit(Request $request, <?= $entity_class_name ?> $<?= $entity_va
return $this->redirectToRoute('<?= $route_name ?>_edit', ['<?= $entity_identifier ?>' => $<?= $entity_var_singular ?>->get<?= ucfirst($entity_identifier) ?>()]);
}

return $this->render('<?= $route_name ?>/edit.html.twig', [
return $this->render('<?= $template_path ?>/edit.html.twig', [
'<?= $entity_twig_var_singular ?>' => $<?= $entity_var_singular ?>,
'form' => $form->createView(),
]);
Expand Down

0 comments on commit 86d24f3

Please sign in to comment.