Skip to content

[Form] Add default implementation for AbstractType::getName() #15008

Closed
@webmozart

Description

@webmozart

As originally discussed in #11185, a default implementation should be added for AbstractType::getName():

  • getName() should return the type's FQCN by default
  • the alias should be se4t to the class name by default in the DI config
  • the form name should be set to the lower-cased short name of the type by default, minus the "type" suffix

Before:

class TaskType extends AbstractType
{
    public function getName()
    {
        return 'task';
    }
}
services:
    acme.demo.form.task:
        class: Acme\DemoBundle\Form\TaskType
        tags:
            - { name: form.type, alias: task }
$form = $this->createForm(new TaskType());
// or
$form = $this->createForm('task');

echo $form->getName();
// task

After:

class TaskType extends AbstractType
{
}
services:
    acme.demo.form.task:
        class: Acme\DemoBundle\Form\TaskType
        tags:
            - { name: form.type }
$form = $this->createForm(new TaskType());
// or
$form = $this->createForm(TaskType::class);
// or
$form = $this->createForm('Acme\DemoBundle\Form\TaskType');

echo $form->getName();
// task

Metadata

Metadata

Assignees

No one assigned

    Labels

    DXDX = Developer eXperience (anything that improves the experience of using Symfony)EnhancementForm

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions