Skip to content

Commit 21f7699

Browse files
committed
feature #1685 [make:form] suffix with "Form" instead of "Type" (kbond)
This PR was merged into the 1.x branch. Discussion ---------- [make:form] suffix with "Form" instead of "Type" This may be controversial but I've always found the term "Type" confusing for your forms. For the purposes of what this maker creates, these are "Forms". If there is agreement on this change, I'll fix up the tests. Commits ------- 6456718 [make:form] suffix with "Form" instead of "Type"
2 parents ebb00c7 + 6456718 commit 21f7699

29 files changed

+69
-68
lines changed

config/help/MakeForm.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
The <info>%command.name%</info> command generates a new form class.
22

3-
<info>php %command.full_name% UserType</info>
3+
<info>php %command.full_name% UserForm</info>
44

55
If the argument is missing, the command will ask for the form class interactively.
66

77
You can optionally specify the bound class in a second argument.
88
This can be the name of an entity like <info>User</info>
99

10-
<info>php %command.full_name% UserType User</info>
10+
<info>php %command.full_name% UserForm User</info>
1111

1212
You can also specify a fully qualified name to another class like <info>\App\Dto\UserData</info>.
1313
Slashes must be escaped in the argument.
1414

15-
<info>php %command.full_name% UserType \\App\\Dto\\UserData</info>
15+
<info>php %command.full_name% UserForm \\App\\Dto\\UserData</info>
1616

src/Maker/MakeCrud.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
140140
$iter = 0;
141141
do {
142142
$formClassDetails = $generator->createClassNameDetails(
143-
$entityClassDetails->getRelativeNameWithoutSuffix().($iter ?: '').'Type',
143+
$entityClassDetails->getRelativeNameWithoutSuffix().($iter ?: ''),
144144
'Form\\',
145-
'Type'
145+
'Form'
146146
);
147147
++$iter;
148148
} while (class_exists($formClassDetails->getFullName()));

src/Maker/MakeForm.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static function getCommandDescription(): string
5151
public function configureCommand(Command $command, InputConfiguration $inputConfig): void
5252
{
5353
$command
54-
->addArgument('name', InputArgument::OPTIONAL, \sprintf('The name of the form class (e.g. <fg=yellow>%sType</>)', Str::asClassName(Str::getRandomTerm())))
54+
->addArgument('name', InputArgument::OPTIONAL, \sprintf('The name of the form class (e.g. <fg=yellow>%Form</>)', Str::asClassName(Str::getRandomTerm())))
5555
->addArgument('bound-class', InputArgument::OPTIONAL, 'The name of Entity or fully qualified model class name that the new form will be bound to (empty for none)')
5656
->setHelp($this->getHelpFileContents('MakeForm.txt'))
5757
;
@@ -80,7 +80,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
8080
$formClassNameDetails = $generator->createClassNameDetails(
8181
$input->getArgument('name'),
8282
'Form\\',
83-
'Type'
83+
'Form'
8484
);
8585

8686
$formFields = ['field_name' => null];

src/Maker/MakeRegistrationForm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ public function configureDependencies(DependencyBuilder $dependencies): void
548548
private function generateFormClass(ClassNameDetails $userClassDetails, Generator $generator, string $usernameField): ClassNameDetails
549549
{
550550
$formClassDetails = $generator->createClassNameDetails(
551-
'RegistrationFormType',
551+
'RegistrationForm',
552552
'Form\\'
553553
);
554554

src/Maker/MakeResetPassword.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
227227
);
228228

229229
$requestFormTypeClassNameDetails = $generator->createClassNameDetails(
230-
'ResetPasswordRequestFormType',
230+
'ResetPasswordRequestForm',
231231
'Form\\'
232232
);
233233

234234
$changePasswordFormTypeClassNameDetails = $generator->createClassNameDetails(
235-
'ChangePasswordFormType',
235+
'ChangePasswordForm',
236236
'Form\\'
237237
);
238238

@@ -301,7 +301,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
301301

302302
$generator->generateClass(
303303
$requestFormTypeClassNameDetails->getFullName(),
304-
'resetPassword/ResetPasswordRequestFormType.tpl.php',
304+
'resetPassword/ResetPasswordRequestForm.tpl.php',
305305
[
306306
'use_statements' => $useStatements,
307307
'email_field' => $this->emailPropertyName,
@@ -322,7 +322,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
322322

323323
$generator->generateClass(
324324
$changePasswordFormTypeClassNameDetails->getFullName(),
325-
'resetPassword/ChangePasswordFormType.tpl.php',
325+
'resetPassword/ChangePasswordForm.tpl.php',
326326
['use_statements' => $useStatements]
327327
);
328328

src/Renderer/FormTypeRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function render(ClassNameDetails $formClassDetails, array $formFields, ?C
7070

7171
$this->generator->generateClass(
7272
$formClassDetails->getFullName(),
73-
'form/Type.tpl.php',
73+
'form/Form.tpl.php',
7474
[
7575
'use_statements' => $useStatements,
7676
'bounded_class_name' => $boundClassDetails ? $boundClassDetails->getShortName() : null,
File renamed without changes.

tests/Maker/MakeCrudTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function getTestDetails(): \Generator
3939
]);
4040

4141
$this->assertStringContainsString('src/Controller/SweetFoodController.php', $output);
42-
$this->assertStringContainsString('src/Form/SweetFoodType.php', $output);
42+
$this->assertStringContainsString('src/Form/SweetFoodForm.php', $output);
4343

4444
$this->runCrudTest($runner, 'it_generates_basic_crud.php');
4545
}),
@@ -59,7 +59,7 @@ public function getTestDetails(): \Generator
5959
]);
6060

6161
$this->assertStringContainsString('src/Controller/SweetFoodAdminController.php', $output);
62-
$this->assertStringContainsString('src/Form/SweetFoodType.php', $output);
62+
$this->assertStringContainsString('src/Form/SweetFoodForm.php', $output);
6363

6464
$this->runCrudTest($runner, 'it_generates_crud_with_custom_controller.php');
6565
}),
@@ -80,7 +80,7 @@ public function getTestDetails(): \Generator
8080
]);
8181

8282
$this->assertStringContainsString('src/Controller/SweetFoodController.php', $output);
83-
$this->assertStringContainsString('src/Form/SweetFoodType.php', $output);
83+
$this->assertStringContainsString('src/Form/SweetFoodForm.php', $output);
8484
$this->assertStringContainsString('tests/Controller/SweetFoodControllerTest.php', $output);
8585

8686
$this->runCrudTest($runner, 'it_generates_basic_crud.php');
@@ -107,7 +107,7 @@ public function getTestDetails(): \Generator
107107
]);
108108

109109
$this->assertStringContainsString('src/Controller/SweetFoodController.php', $output);
110-
$this->assertStringContainsString('src/Form/SweetFoodType.php', $output);
110+
$this->assertStringContainsString('src/Form/SweetFoodForm.php', $output);
111111
$this->assertStringContainsString('tests/Controller/SweetFoodControllerTest.php', $output);
112112

113113
$this->runCrudTest($runner, 'it_generates_basic_crud.php');
@@ -145,7 +145,7 @@ public function getTestDetails(): \Generator
145145
]);
146146

147147
$this->assertStringContainsString('src/Controller/SweetFoodController.php', $output);
148-
$this->assertStringContainsString('src/Form/SweetFoodType.php', $output);
148+
$this->assertStringContainsString('src/Form/SweetFoodForm.php', $output);
149149

150150
$this->runCrudTest($runner, 'it_generates_crud_with_custom_root_namespace.php');
151151
}),
@@ -169,7 +169,7 @@ public function getTestDetails(): \Generator
169169
]);
170170

171171
$this->assertStringContainsString('src/Controller/SweetFoodController.php', $output);
172-
$this->assertStringContainsString('src/Form/SweetFoodType.php', $output);
172+
$this->assertStringContainsString('src/Form/SweetFoodForm.php', $output);
173173

174174
$this->runCrudTest($runner, 'it_generates_basic_crud.php');
175175
self::assertFileEquals(
@@ -195,7 +195,7 @@ public function getTestDetails(): \Generator
195195
]);
196196

197197
$this->assertStringContainsString('src/Controller/SweetFoodController.php', $output);
198-
$this->assertStringContainsString('src/Form/SweetFoodType.php', $output);
198+
$this->assertStringContainsString('src/Form/SweetFoodForm.php', $output);
199199

200200
$this->runCrudTest($runner, 'it_generates_basic_crud.php');
201201
}),

tests/Maker/MakeFormTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function getTestDetails(): \Generator
5050

5151
$runner->runMaker([
5252
// Entity name
53-
'SourFoodType',
53+
'SourFoodForm',
5454
'SourFood',
5555
]);
5656

@@ -67,7 +67,7 @@ public function getTestDetails(): \Generator
6767

6868
$runner->runMaker([
6969
// Entity name
70-
'TaskType',
70+
'TaskForm',
7171
'\\App\\Form\\Data\\TaskData',
7272
]);
7373

@@ -89,7 +89,7 @@ public function getTestDetails(): \Generator
8989

9090
$runner->runMaker([
9191
// Entity name
92-
'SourFoodType',
92+
'SourFoodForm',
9393
'SourFood',
9494
]);
9595

@@ -111,7 +111,7 @@ public function getTestDetails(): \Generator
111111

112112
$runner->runMaker([
113113
// Entity name
114-
'BookType',
114+
'BookForm',
115115
'Book',
116116
]);
117117

@@ -132,7 +132,7 @@ public function getTestDetails(): \Generator
132132

133133
$runner->runMaker([
134134
// Entity name
135-
'AuthorType',
135+
'AuthorForm',
136136
'Author',
137137
]);
138138

@@ -153,7 +153,7 @@ public function getTestDetails(): \Generator
153153

154154
$runner->runMaker([
155155
// Entity name
156-
'BookType',
156+
'BookForm',
157157
'Book',
158158
]);
159159

@@ -174,7 +174,7 @@ public function getTestDetails(): \Generator
174174

175175
$runner->runMaker([
176176
// Entity name
177-
'LibraryType',
177+
'LibraryForm',
178178
'Library',
179179
]);
180180

@@ -195,7 +195,7 @@ public function getTestDetails(): \Generator
195195

196196
$runner->runMaker([
197197
// Entity name
198-
'FoodType',
198+
'FoodForm',
199199
'Food',
200200
]);
201201

tests/Maker/MakeResetPasswordTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public function getTestDetails(): \Generator
4444
$generatedFiles = [
4545
'src/Controller/ResetPasswordController.php',
4646
'src/Entity/ResetPasswordRequest.php',
47-
'src/Form/ChangePasswordFormType.php',
48-
'src/Form/ResetPasswordRequestFormType.php',
47+
'src/Form/ChangePasswordForm.php',
48+
'src/Form/ResetPasswordRequestForm.php',
4949
'src/Repository/ResetPasswordRequestRepository.php',
5050
'templates/reset_password/check_email.html.twig',
5151
'templates/reset_password/email.html.twig',
@@ -148,8 +148,8 @@ public function getTestDetails(): \Generator
148148
$generatedFiles = [
149149
'src/Controller/ResetPasswordController.php',
150150
'src/Entity/ResetPasswordRequest.php',
151-
'src/Form/ChangePasswordFormType.php',
152-
'src/Form/ResetPasswordRequestFormType.php',
151+
'src/Form/ChangePasswordForm.php',
152+
'src/Form/ResetPasswordRequestForm.php',
153153
'src/Repository/ResetPasswordRequestRepository.php',
154154
'templates/reset_password/check_email.html.twig',
155155
'templates/reset_password/email.html.twig',
@@ -208,8 +208,8 @@ public function getTestDetails(): \Generator
208208
$generatedFiles = [
209209
'src/Controller/ResetPasswordController.php',
210210
'src/Entity/ResetPasswordRequest.php',
211-
'src/Form/ChangePasswordFormType.php',
212-
'src/Form/ResetPasswordRequestFormType.php',
211+
'src/Form/ChangePasswordForm.php',
212+
'src/Form/ResetPasswordRequestForm.php',
213213
'src/Repository/ResetPasswordRequestRepository.php',
214214
'templates/reset_password/check_email.html.twig',
215215
'templates/reset_password/email.html.twig',
@@ -361,7 +361,7 @@ public function getTestDetails(): \Generator
361361
$this->assertStringContainsString('ORM\ManyToOne', $contentResetPasswordRequest);
362362

363363
// check ResetPasswordRequestFormType
364-
$contentResetPasswordRequestFormType = file_get_contents($runner->getPath('/src/Form/ResetPasswordRequestFormType.php'));
364+
$contentResetPasswordRequestFormType = file_get_contents($runner->getPath('/src/Form/ResetPasswordRequestForm.php'));
365365
$this->assertStringContainsString('->add(\'emailAddress\', EmailType::class, [', $contentResetPasswordRequestFormType);
366366
// check request.html.twig
367367
$contentRequestHtml = file_get_contents($runner->getPath('templates/reset_password/request.html.twig'));

tests/fixtures/make-crud/expected/WithCustomRepository.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace App\Controller;
44

55
use App\Entity\SweetFood;
6-
use App\Form\SweetFoodType;
6+
use App\Form\SweetFoodForm;
77
use App\Repository\SweetFoodRepository;
88
use Doctrine\ORM\EntityManagerInterface;
99
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -26,7 +26,7 @@ public function index(SweetFoodRepository $sweetFoodRepository): Response
2626
public function new(Request $request, EntityManagerInterface $entityManager): Response
2727
{
2828
$sweetFood = new SweetFood();
29-
$form = $this->createForm(SweetFoodType::class, $sweetFood);
29+
$form = $this->createForm(SweetFoodForm::class, $sweetFood);
3030
$form->handleRequest($request);
3131

3232
if ($form->isSubmitted() && $form->isValid()) {
@@ -53,7 +53,7 @@ public function show(SweetFood $sweetFood): Response
5353
#[Route('/{id}/edit', name: 'app_sweet_food_edit', methods: ['GET', 'POST'])]
5454
public function edit(Request $request, SweetFood $sweetFood, EntityManagerInterface $entityManager): Response
5555
{
56-
$form = $this->createForm(SweetFoodType::class, $sweetFood);
56+
$form = $this->createForm(SweetFoodForm::class, $sweetFood);
5757
$form->handleRequest($request);
5858

5959
if ($form->isSubmitted() && $form->isValid()) {

tests/fixtures/make-crud/tests/it_generates_basic_crud.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testIndexAction()
2222
$this->assertStringContainsString('New SweetFood', $client->getResponse()->getContent());
2323

2424
$newForm = $crawler->selectButton('Save')->form();
25-
$client->submit($newForm, ['sweet_food[title]' => 'Candy']);
25+
$client->submit($newForm, ['sweet_food_form[title]' => 'Candy']);
2626
$this->assertTrue($client->getResponse()->isRedirect());
2727

2828
$crawler = $client->followRedirect();
@@ -38,7 +38,7 @@ public function testIndexAction()
3838
$this->assertGreaterThan(0, $crawler->filter('input[type=text]')->count());
3939

4040
$editForm = $crawler->selectButton('Update')->form();
41-
$client->submit($editForm, ['sweet_food[title]' => 'Candy edited']);
41+
$client->submit($editForm, ['sweet_food_form[title]' => 'Candy edited']);
4242
$this->assertTrue($client->getResponse()->isRedirect());
4343

4444
$crawler = $client->followRedirect();

tests/fixtures/make-crud/tests/it_generates_crud_with_custom_controller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testIndexAction()
2222
$this->assertStringContainsString('New SweetFood', $client->getResponse()->getContent());
2323

2424
$newForm = $crawler->selectButton('Save')->form();
25-
$client->submit($newForm, ['sweet_food[title]' => 'Candy']);
25+
$client->submit($newForm, ['sweet_food_form[title]' => 'Candy']);
2626
$this->assertTrue($client->getResponse()->isRedirect());
2727

2828
$crawler = $client->followRedirect();
@@ -38,7 +38,7 @@ public function testIndexAction()
3838
$this->assertGreaterThan(0, $crawler->filter('input[type=text]')->count());
3939

4040
$editForm = $crawler->selectButton('Update')->form();
41-
$client->submit($editForm, ['sweet_food[title]' => 'Candy edited']);
41+
$client->submit($editForm, ['sweet_food_form[title]' => 'Candy edited']);
4242
$this->assertTrue($client->getResponse()->isRedirect());
4343

4444
$crawler = $client->followRedirect();

tests/fixtures/make-crud/tests/it_generates_crud_with_custom_root_namespace.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testIndexAction()
2222
$this->assertStringContainsString('New SweetFood', $client->getResponse()->getContent());
2323

2424
$newForm = $crawler->selectButton('Save')->form();
25-
$client->submit($newForm, ['sweet_food[title]' => 'Candy']);
25+
$client->submit($newForm, ['sweet_food_form[title]' => 'Candy']);
2626
$this->assertTrue($client->getResponse()->isRedirect());
2727

2828
$crawler = $client->followRedirect();
@@ -38,7 +38,7 @@ public function testIndexAction()
3838
$this->assertGreaterThan(0, $crawler->filter('input[type=text]')->count());
3939

4040
$editForm = $crawler->selectButton('Update')->form();
41-
$client->submit($editForm, ['sweet_food[title]' => 'Candy edited']);
41+
$client->submit($editForm, ['sweet_food_form[title]' => 'Candy edited']);
4242
$this->assertTrue($client->getResponse()->isRedirect());
4343

4444
$crawler = $client->followRedirect();

tests/fixtures/make-form/tests/it_generates_basic_form.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace App\Tests;
44

5-
use App\Form\FooBarType;
5+
use App\Form\FooBarForm;
66
use Symfony\Component\Form\Test\TypeTestCase;
77

88
class GeneratedFormTest extends TypeTestCase
@@ -13,7 +13,7 @@ public function testGeneratedForm()
1313
'field_name' => 'field_value',
1414
];
1515

16-
$form = $this->factory->create(FooBarType::class);
16+
$form = $this->factory->create(FooBarForm::class);
1717
$form->submit($formData);
1818

1919
$this->assertTrue($form->isSynchronized());

tests/fixtures/make-form/tests/it_generates_form_with_embeddable_entity.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace App\Tests;
44

55
use App\Entity\Food;
6-
use App\Form\FoodType;
6+
use App\Form\FoodForm;
77
use Symfony\Component\Form\Test\TypeTestCase;
88

99
class GeneratedFormTest extends TypeTestCase
@@ -14,7 +14,7 @@ public function testGeneratedForm()
1414
'title' => 'lemon',
1515
];
1616

17-
$form = $this->factory->create(FoodType::class);
17+
$form = $this->factory->create(FoodForm::class);
1818
$form->submit($formData);
1919

2020
$object = new Food();

0 commit comments

Comments
 (0)