Skip to content

[make:form] suffix with "Form" instead of "Type" #1685

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

Merged
merged 1 commit into from
Apr 25, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions config/help/MakeForm.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
The <info>%command.name%</info> command generates a new form class.

<info>php %command.full_name% UserType</info>
<info>php %command.full_name% UserForm</info>

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

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

<info>php %command.full_name% UserType User</info>
<info>php %command.full_name% UserForm User</info>

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

<info>php %command.full_name% UserType \\App\\Dto\\UserData</info>
<info>php %command.full_name% UserForm \\App\\Dto\\UserData</info>

4 changes: 2 additions & 2 deletions src/Maker/MakeCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
$iter = 0;
do {
$formClassDetails = $generator->createClassNameDetails(
$entityClassDetails->getRelativeNameWithoutSuffix().($iter ?: '').'Type',
$entityClassDetails->getRelativeNameWithoutSuffix().($iter ?: ''),
'Form\\',
'Type'
'Form'
);
++$iter;
} while (class_exists($formClassDetails->getFullName()));
Expand Down
4 changes: 2 additions & 2 deletions src/Maker/MakeForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static function getCommandDescription(): string
public function configureCommand(Command $command, InputConfiguration $inputConfig): void
{
$command
->addArgument('name', InputArgument::OPTIONAL, \sprintf('The name of the form class (e.g. <fg=yellow>%sType</>)', Str::asClassName(Str::getRandomTerm())))
->addArgument('name', InputArgument::OPTIONAL, \sprintf('The name of the form class (e.g. <fg=yellow>%Form</>)', Str::asClassName(Str::getRandomTerm())))
->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)')
->setHelp($this->getHelpFileContents('MakeForm.txt'))
;
Expand Down Expand Up @@ -80,7 +80,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
$formClassNameDetails = $generator->createClassNameDetails(
$input->getArgument('name'),
'Form\\',
'Type'
'Form'
);

$formFields = ['field_name' => null];
Expand Down
2 changes: 1 addition & 1 deletion src/Maker/MakeRegistrationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ public function configureDependencies(DependencyBuilder $dependencies): void
private function generateFormClass(ClassNameDetails $userClassDetails, Generator $generator, string $usernameField): ClassNameDetails
{
$formClassDetails = $generator->createClassNameDetails(
'RegistrationFormType',
'RegistrationForm',
'Form\\'
);

Expand Down
8 changes: 4 additions & 4 deletions src/Maker/MakeResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
);

$requestFormTypeClassNameDetails = $generator->createClassNameDetails(
'ResetPasswordRequestFormType',
'ResetPasswordRequestForm',
'Form\\'
);

$changePasswordFormTypeClassNameDetails = $generator->createClassNameDetails(
'ChangePasswordFormType',
'ChangePasswordForm',
'Form\\'
);

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

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

$generator->generateClass(
$changePasswordFormTypeClassNameDetails->getFullName(),
'resetPassword/ChangePasswordFormType.tpl.php',
'resetPassword/ChangePasswordForm.tpl.php',
['use_statements' => $useStatements]
);

Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/FormTypeRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function render(ClassNameDetails $formClassDetails, array $formFields, ?C

$this->generator->generateClass(
$formClassDetails->getFullName(),
'form/Type.tpl.php',
'form/Form.tpl.php',
[
'use_statements' => $useStatements,
'bounded_class_name' => $boundClassDetails ? $boundClassDetails->getShortName() : null,
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions tests/Maker/MakeCrudTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getTestDetails(): \Generator
]);

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

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

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

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

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

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

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

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

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

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

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

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

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

$this->runCrudTest($runner, 'it_generates_basic_crud.php');
}),
Expand Down
16 changes: 8 additions & 8 deletions tests/Maker/MakeFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getTestDetails(): \Generator

$runner->runMaker([
// Entity name
'SourFoodType',
'SourFoodForm',
'SourFood',
]);

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

$runner->runMaker([
// Entity name
'TaskType',
'TaskForm',
'\\App\\Form\\Data\\TaskData',
]);

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

$runner->runMaker([
// Entity name
'SourFoodType',
'SourFoodForm',
'SourFood',
]);

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

$runner->runMaker([
// Entity name
'BookType',
'BookForm',
'Book',
]);

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

$runner->runMaker([
// Entity name
'AuthorType',
'AuthorForm',
'Author',
]);

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

$runner->runMaker([
// Entity name
'BookType',
'BookForm',
'Book',
]);

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

$runner->runMaker([
// Entity name
'LibraryType',
'LibraryForm',
'Library',
]);

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

$runner->runMaker([
// Entity name
'FoodType',
'FoodForm',
'Food',
]);

Expand Down
14 changes: 7 additions & 7 deletions tests/Maker/MakeResetPasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function getTestDetails(): \Generator
$generatedFiles = [
'src/Controller/ResetPasswordController.php',
'src/Entity/ResetPasswordRequest.php',
'src/Form/ChangePasswordFormType.php',
'src/Form/ResetPasswordRequestFormType.php',
'src/Form/ChangePasswordForm.php',
'src/Form/ResetPasswordRequestForm.php',
'src/Repository/ResetPasswordRequestRepository.php',
'templates/reset_password/check_email.html.twig',
'templates/reset_password/email.html.twig',
Expand Down Expand Up @@ -148,8 +148,8 @@ public function getTestDetails(): \Generator
$generatedFiles = [
'src/Controller/ResetPasswordController.php',
'src/Entity/ResetPasswordRequest.php',
'src/Form/ChangePasswordFormType.php',
'src/Form/ResetPasswordRequestFormType.php',
'src/Form/ChangePasswordForm.php',
'src/Form/ResetPasswordRequestForm.php',
'src/Repository/ResetPasswordRequestRepository.php',
'templates/reset_password/check_email.html.twig',
'templates/reset_password/email.html.twig',
Expand Down Expand Up @@ -208,8 +208,8 @@ public function getTestDetails(): \Generator
$generatedFiles = [
'src/Controller/ResetPasswordController.php',
'src/Entity/ResetPasswordRequest.php',
'src/Form/ChangePasswordFormType.php',
'src/Form/ResetPasswordRequestFormType.php',
'src/Form/ChangePasswordForm.php',
'src/Form/ResetPasswordRequestForm.php',
'src/Repository/ResetPasswordRequestRepository.php',
'templates/reset_password/check_email.html.twig',
'templates/reset_password/email.html.twig',
Expand Down Expand Up @@ -361,7 +361,7 @@ public function getTestDetails(): \Generator
$this->assertStringContainsString('ORM\ManyToOne', $contentResetPasswordRequest);

// check ResetPasswordRequestFormType
$contentResetPasswordRequestFormType = file_get_contents($runner->getPath('/src/Form/ResetPasswordRequestFormType.php'));
$contentResetPasswordRequestFormType = file_get_contents($runner->getPath('/src/Form/ResetPasswordRequestForm.php'));
$this->assertStringContainsString('->add(\'emailAddress\', EmailType::class, [', $contentResetPasswordRequestFormType);
// check request.html.twig
$contentRequestHtml = file_get_contents($runner->getPath('templates/reset_password/request.html.twig'));
Expand Down
6 changes: 3 additions & 3 deletions tests/fixtures/make-crud/expected/WithCustomRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Controller;

use App\Entity\SweetFood;
use App\Form\SweetFoodType;
use App\Form\SweetFoodForm;
use App\Repository\SweetFoodRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand All @@ -26,7 +26,7 @@ public function index(SweetFoodRepository $sweetFoodRepository): Response
public function new(Request $request, EntityManagerInterface $entityManager): Response
{
$sweetFood = new SweetFood();
$form = $this->createForm(SweetFoodType::class, $sweetFood);
$form = $this->createForm(SweetFoodForm::class, $sweetFood);
$form->handleRequest($request);

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

if ($form->isSubmitted() && $form->isValid()) {
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/make-crud/tests/it_generates_basic_crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testIndexAction()
$this->assertStringContainsString('New SweetFood', $client->getResponse()->getContent());

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

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

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

$crawler = $client->followRedirect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testIndexAction()
$this->assertStringContainsString('New SweetFood', $client->getResponse()->getContent());

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

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

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

$crawler = $client->followRedirect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testIndexAction()
$this->assertStringContainsString('New SweetFood', $client->getResponse()->getContent());

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

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

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

$crawler = $client->followRedirect();
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/make-form/tests/it_generates_basic_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Tests;

use App\Form\FooBarType;
use App\Form\FooBarForm;
use Symfony\Component\Form\Test\TypeTestCase;

class GeneratedFormTest extends TypeTestCase
Expand All @@ -13,7 +13,7 @@ public function testGeneratedForm()
'field_name' => 'field_value',
];

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

$this->assertTrue($form->isSynchronized());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Tests;

use App\Entity\Food;
use App\Form\FoodType;
use App\Form\FoodForm;
use Symfony\Component\Form\Test\TypeTestCase;

class GeneratedFormTest extends TypeTestCase
Expand All @@ -14,7 +14,7 @@ public function testGeneratedForm()
'title' => 'lemon',
];

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

$object = new Food();
Expand Down
Loading