Skip to content

Commit

Permalink
Fix BC break with DoctrineType::reset() for Symfony 3.4-4.1
Browse files Browse the repository at this point in the history
Fixes BC break with mistakenly removed `kernel.reset` tag from
`form.type.entity` service, because `DoctrineType` implements
`ResetInterface` only in Symfony 4.2+, therefore all previous
versions starting from 3.4 are affected.

This BC break was introduced in version 1.11.0 in commit 6b25ea4
  • Loading branch information
javer committed May 16, 2019
1 parent 09a3841 commit 400be2e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions DependencyInjection/DoctrineExtension.php
Expand Up @@ -11,6 +11,7 @@
use Doctrine\ORM\Version;
use LogicException;
use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension;
use Symfony\Bridge\Doctrine\Form\Type\DoctrineType;
use Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware;
use Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor;
use Symfony\Bridge\Doctrine\Validator\DoctrineLoader;
Expand All @@ -28,6 +29,7 @@
use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface;
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
use Symfony\Contracts\Service\ResetInterface;
use function class_exists;
use function sprintf;

Expand Down Expand Up @@ -343,6 +345,13 @@ protected function ormLoad(array $config, ContainerBuilder $container)
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('orm.xml');

// This check can be removed when support for Symfony < 4.2 is dropped
if (! interface_exists(ResetInterface::class)
|| ! is_a(DoctrineType::class, ResetInterface::class)
|| ! $container->getDefinition('form.type.entity')->hasTag('kernel.reset')) {
$container->getDefinition('form.type.entity')->addTag('kernel.reset', ['method' => 'reset']);
}

$entityManagers = [];
foreach (array_keys($config['entity_managers']) as $name) {
$entityManagers[$name] = sprintf('doctrine.orm.%s_entity_manager', $name);
Expand Down

0 comments on commit 400be2e

Please sign in to comment.