Skip to content

Commit fd712d1

Browse files
committed
bug #286 Fix crud controller template (Thibaut Salanon)
This PR was squashed before being merged into the 1.0-dev branch (closes #286). Discussion ---------- Fix crud controller template There is a mistake in crud controller template : Example (`src/Resources/skeleton/crud/controller/Controller.tpl.php` - line 35) : `return $this->render('<?= $route_name ?>/index.html.twig', ['<?= $entity_twig_var_plural ?>' => $<?= $entity_var_plural ?>]);` With an entity with following path :` Entity/Foo/BarBar.php` , `$route_name` will be equal to `foo_bar_bar` and does not correspond with the `index.html.twig` path (should be `foo/bar_bar`). This pull request fix this by adding the `$templatesPath` var, used to create twig templates, for the controller generation. :) Commits ------- f77a843 Rename template_var with templates_path (plural) 86d24f3 Create new template_path var and replace route_name var in render method parameter in controller template
2 parents 705d3a2 + f77a843 commit fd712d1

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/Maker/MakeCrud.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
126126
$entityTwigVarSingular = Str::asTwigVariable($entityVarSingular);
127127

128128
$routeName = Str::asRouteName($controllerClassDetails->getRelativeNameWithoutSuffix());
129+
$templatesPath = Str::asFilePath($controllerClassDetails->getRelativeNameWithoutSuffix());
129130

130131
$generator->generateController(
131132
$controllerClassDetails->getFullName(),
@@ -137,6 +138,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
137138
'form_class_name' => $formClassDetails->getShortName(),
138139
'route_path' => Str::asRoutePath($controllerClassDetails->getRelativeNameWithoutSuffix()),
139140
'route_name' => $routeName,
141+
'templates_path' => $templatesPath,
140142
'entity_var_plural' => $entityVarPlural,
141143
'entity_twig_var_plural' => $entityTwigVarPlural,
142144
'entity_var_singular' => $entityVarSingular,
@@ -157,8 +159,6 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
157159
]
158160
);
159161

160-
$templatesPath = Str::asFilePath($controllerClassDetails->getRelativeNameWithoutSuffix());
161-
162162
$templates = [
163163
'_delete_form' => [
164164
'route_name' => $routeName,

src/Resources/skeleton/crud/controller/Controller.tpl.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class <?= $class_name ?> extends <?= $parent_class_name; ?><?= "\n" ?>
2323
<?php if (isset($repository_full_class_name)): ?>
2424
public function index(<?= $repository_class_name ?> $<?= $repository_var ?>): Response
2525
{
26-
return $this->render('<?= $route_name ?>/index.html.twig', ['<?= $entity_twig_var_plural ?>' => $<?= $repository_var ?>->findAll()]);
26+
return $this->render('<?= $templates_path ?>/index.html.twig', ['<?= $entity_twig_var_plural ?>' => $<?= $repository_var ?>->findAll()]);
2727
}
2828
<?php else: ?>
2929
public function index(): Response
@@ -32,7 +32,7 @@ public function index(): Response
3232
->getRepository(<?= $entity_class_name ?>::class)
3333
->findAll();
3434

35-
return $this->render('<?= $route_name ?>/index.html.twig', ['<?= $entity_twig_var_plural ?>' => $<?= $entity_var_plural ?>]);
35+
return $this->render('<?= $templates_path ?>/index.html.twig', ['<?= $entity_twig_var_plural ?>' => $<?= $entity_var_plural ?>]);
3636
}
3737
<?php endif ?>
3838

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

56-
return $this->render('<?= $route_name ?>/new.html.twig', [
56+
return $this->render('<?= $templates_path ?>/new.html.twig', [
5757
'<?= $entity_twig_var_singular ?>' => $<?= $entity_var_singular ?>,
5858
'form' => $form->createView(),
5959
]);
@@ -64,7 +64,7 @@ public function new(Request $request): Response
6464
*/
6565
public function show(<?= $entity_class_name ?> $<?= $entity_var_singular ?>): Response
6666
{
67-
return $this->render('<?= $route_name ?>/show.html.twig', ['<?= $entity_twig_var_singular ?>' => $<?= $entity_var_singular ?>]);
67+
return $this->render('<?= $templates_path ?>/show.html.twig', ['<?= $entity_twig_var_singular ?>' => $<?= $entity_var_singular ?>]);
6868
}
6969

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

84-
return $this->render('<?= $route_name ?>/edit.html.twig', [
84+
return $this->render('<?= $templates_path ?>/edit.html.twig', [
8585
'<?= $entity_twig_var_singular ?>' => $<?= $entity_var_singular ?>,
8686
'form' => $form->createView(),
8787
]);

0 commit comments

Comments
 (0)