Skip to content

[Form] 4.2+ form type extensions configuration does not consider using a parameter as the given class #31052

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

Closed
antoniocambados opened this issue Apr 10, 2019 · 1 comment

Comments

@antoniocambados
Copy link

Symfony version(s) affected: 4.2+

Description
When using a parameter as the class given to a service Definition, the FormPass will trigger a deprecation warning or throw an Exception for not being able to ensure method getExtendedTypes exists.

How to reproduce

Create a form type extension:

// src/App/Form/Extension/FooFormExtension
namespace App\Form\Extension;

use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\FormType;

class FooFormExtension extends AbstractTypeExtension
{
    public static function getExtendedTypes(): iterable
    {
        return [FormType::class];
    }
}

Set up the configuration:

# config/services.yaml
parameters:
    foo_form_service_class: 'App\Form\Extension\FooFormExtension'
services:
    foo_form_service:
        class: '%foo_form_service_class%'
        tags:
            - { name: form.type_extension, extended_type: Symfony\Component\Form\Extension\Core\Type\FormType }

Now, when running your app, you'lle get this deprecation warning:

Not implementing the static getExtendedTypes() method in %foo_form_service_class% when implementing the Symfony\Component\Form\FormTypeExtensionInterface is deprecated since Symfony 4.2. The method will be added to the interface in 5.0.

If you set up the service without a backwards-compatible definition such as:

# config/services.yaml
parameters:
    foo_form_service_class: 'App\Form\Extension\FooFormExtension'
services:
    foo_form_service:
        class: '%foo_form_service_class%'
        tags: ['form.type_extension']

Then an exception will be thrown:

(1/1) InvalidArgumentException "form.type_extension" tagged services have to implement the static getExtendedTypes() method. The class for service "foo_form_service" does not implement it.

Possible Solution
Other than trying to resolve the class as a parameter in Symfony\Component\Form\DependencyInjection\FormPass, it could be possible to deprecate using parameters to provide the class of a service altogether.

Additional context
This is all happening in Symfony\Component\Form\DependencyInjection\FormPass::processFormTypeExtensions().

I've noticed this while using LexikFormFilterBundle.

@xabbuh
Copy link
Member

xabbuh commented Apr 23, 2019

see #31201

@fabpot fabpot closed this as completed Apr 24, 2019
fabpot added a commit that referenced this issue Apr 24, 2019
This PR was merged into the 4.2 branch.

Discussion
----------

[Form] resolve class name parameters

| Q             | A
| ------------- | ---
| Branch?       | 4.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #31052
| License       | MIT
| Doc PR        |

Commits
-------

5235be4 resolve class name parameters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants