From 9878aac3a0079bf7bda338d8f1bdd2cd5e01bc50 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Thu, 26 Nov 2026 10:47:37 +0000 Subject: [PATCH 1/2] Allow doctrine/collections ^3.0 Doctrine ORM 3.7+ already supports doctrine/collections 3.x, and nothing in this bundle's usage of the Collections API hits a breaking change between 2.x and 3.0. The only effect of resolving to collections 3.x was a new deprecation notice, because `Criteria::create()` now treats its former `$accessRawFieldValues` argument as a deprecated no-op. Older, still-supported collections versions (2.4 up to <3.0) still need that argument to avoid their own deprecation about not opting in to raw field access, so `createLocaleCriteria()` now detects at runtime which behaviour the installed collections version expects. --- composer.json | 2 +- src/Doctrine/PersistentTranslatable.php | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 10d6ea1..13e81d3 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "require": { "php": ">= 8.1", - "doctrine/collections": "^1.6 || ^2.0", + "doctrine/collections": "^1.6 || ^2.0 || ^3.0", "doctrine/dbal": "^3.0 || ^4.0", "doctrine/event-manager": "^1.1 || ^2.0", "doctrine/orm": "^2.13 || ^3.0", diff --git a/src/Doctrine/PersistentTranslatable.php b/src/Doctrine/PersistentTranslatable.php index 5e419bc..b9012b4 100644 --- a/src/Doctrine/PersistentTranslatable.php +++ b/src/Doctrine/PersistentTranslatable.php @@ -10,6 +10,7 @@ namespace Webfactory\Bundle\PolyglotBundle\Doctrine; use Doctrine\Common\Collections\Criteria; +use Doctrine\Common\Collections\ReadableCollection; use Doctrine\Common\Collections\Selectable; use Doctrine\ORM\UnitOfWork; use Exception; @@ -253,10 +254,16 @@ private function cacheTranslation(string $locale): void private function createLocaleCriteria(string $locale): Criteria { - return Criteria::create(true) - ->where( - Criteria::expr()->eq($this->localeField->getName(), $locale) - ); + // doctrine/collections >= 3.0 always uses raw field access and made the opt-in parameter a + // deprecated no-op; older versions still need it passed explicitly to avoid their own + // deprecation warning about not opting in. + $criteria = \in_array(Selectable::class, class_implements(ReadableCollection::class), true) + ? Criteria::create() + : Criteria::create(true); + + return $criteria->where( + Criteria::expr()->eq($this->localeField->getName(), $locale) + ); } private function getCachedTranslation(string $locale): ?object From 83b2c3c6f8f13c792c0ce6d4aafe70095b6541d4 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Thu, 26 Nov 2026 10:51:49 +0000 Subject: [PATCH 2/2] Drop the runtime switch for Criteria::create()'s raw-field-access flag Accepting the one deprecation notice doctrine/collections 3.x emits here is simpler than detecting at runtime which collections version is installed. --- src/Doctrine/PersistentTranslatable.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/Doctrine/PersistentTranslatable.php b/src/Doctrine/PersistentTranslatable.php index b9012b4..5e419bc 100644 --- a/src/Doctrine/PersistentTranslatable.php +++ b/src/Doctrine/PersistentTranslatable.php @@ -10,7 +10,6 @@ namespace Webfactory\Bundle\PolyglotBundle\Doctrine; use Doctrine\Common\Collections\Criteria; -use Doctrine\Common\Collections\ReadableCollection; use Doctrine\Common\Collections\Selectable; use Doctrine\ORM\UnitOfWork; use Exception; @@ -254,16 +253,10 @@ private function cacheTranslation(string $locale): void private function createLocaleCriteria(string $locale): Criteria { - // doctrine/collections >= 3.0 always uses raw field access and made the opt-in parameter a - // deprecated no-op; older versions still need it passed explicitly to avoid their own - // deprecation warning about not opting in. - $criteria = \in_array(Selectable::class, class_implements(ReadableCollection::class), true) - ? Criteria::create() - : Criteria::create(true); - - return $criteria->where( - Criteria::expr()->eq($this->localeField->getName(), $locale) - ); + return Criteria::create(true) + ->where( + Criteria::expr()->eq($this->localeField->getName(), $locale) + ); } private function getCachedTranslation(string $locale): ?object