diff --git a/src/Bundle/DependencyInjection/Compiler/DoctrineTargetEntitiesResolverPass.php b/src/Bundle/DependencyInjection/Compiler/DoctrineTargetEntitiesResolverPass.php index 18cc0dd75..10234ae31 100644 --- a/src/Bundle/DependencyInjection/Compiler/DoctrineTargetEntitiesResolverPass.php +++ b/src/Bundle/DependencyInjection/Compiler/DoctrineTargetEntitiesResolverPass.php @@ -13,6 +13,7 @@ namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler; +use Doctrine\Common\EventSubscriber; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; @@ -44,7 +45,12 @@ public function process(ContainerBuilder $container): void ]); } - if (!$resolveTargetEntityListener->hasTag('doctrine.event_listener')) { + $resolveTargetEntityListenerClass = $container->getParameterBag()->resolveValue($resolveTargetEntityListener->getClass()); + if (is_a($resolveTargetEntityListenerClass, EventSubscriber::class, true)) { + if (!$resolveTargetEntityListener->hasTag('doctrine.event_subscriber')) { + $resolveTargetEntityListener->addTag('doctrine.event_subscriber'); + } + } elseif (!$resolveTargetEntityListener->hasTag('doctrine.event_listener')) { $resolveTargetEntityListener->addTag('doctrine.event_listener', ['event' => 'loadClassMetadata']); } }