In my Symfony 6.4 project, I’m trying to declare an abstract service in services.yaml by doing the following :
services:
_defaults:
autowire: true
autoconfigure: true
AppAdminFormHostingFormAbstract:
arguments:
$authorizationChecker: '@security.authorization_checker'
$tokenStorage: '@security.token_storage'
$phpHandlers: '%php_handlers%'
$nodeJsHandlers: '%nodeJs_handlers%'
abstract: true
...
The HostingFormAbstract class is extending AbstractType from symfony/form package :
namespace AppAdminForm;
use SymfonyComponentFormAbstractType;
use SymfonyComponentFormExtensionCoreTypeChoiceType;
use SymfonyComponentFormExtensionCoreTypeCollectionType;
use SymfonyComponentFormExtensionCoreTypeTextareaType;
use SymfonyComponentFormExtensionCoreTypeTextType;
use SymfonyComponentFormExtensionCoreTypeCheckboxType;
use SymfonyComponentFormFormBuilderInterface;
use SymfonyComponentSecurityCoreAuthenticationTokenStorageTokenStorageInterface;
use SymfonyComponentSecurityCoreAuthorizationAuthorizationCheckerInterface;
use SymfonyComponentSecurityCoreUserUserInterface;
use SymfonyComponentValidatorConstraintsNotBlank;
abstract class HostingFormAbstract extends AbstractType
{
private TokenStorageInterface $tokenStorage;
private AuthorizationCheckerInterface $authorizationChecker;
private array $phpHandlers;
private array $nodeJsHandlers;
public function __construct(TokenStorageInterface $tokenStorage, AuthorizationCheckerInterface $authorizationChecker, array $phpHandlers, array $nodeJsHandlers)
{
$this->tokenStorage = $tokenStorage;
$this->authorizationChecker = $authorizationChecker;
$this->phpHandlers = $phpHandlers;
$this->nodeJsHandlers = $nodeJsHandlers;
}
...
And with that, I get the following error while going on my symfony app :
The service "AppAdminFormHostingFormAbstract" tagged "form.type" must not be abstract.
For more context, I’m rewriting a Symfony 3.4 app into a new Symfony 6.4 app.
It was working fine on 3.4, but now it seems that in services.yaml, you can’t declare an abstract service/class extending the AbstractType class.
I tried to add a custom tag in the yaml for this service, but it didn’t change anything.
I didn’t find any workaround on Symfony documentation, and it seems odd to me that you can’t do that. Maybe I missed something.
If anyone as an idea on how to do this…
Thanks !