Skip to content

Commit 86d24f3

Browse files
author
Thibaut Salanon
committed
Create new template_path var and replace route_name var in render method parameter in controller template
1 parent 60b0e27 commit 86d24f3

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+
'template_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('<?= $template_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('<?= $template_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('<?= $template_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('<?= $template_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('<?= $template_path ?>/edit.html.twig', [
8585
'<?= $entity_twig_var_singular ?>' => $<?= $entity_var_singular ?>,
8686
'form' => $form->createView(),
8787
]);

0 commit comments

Comments
 (0)