diff --git a/src/Contract/Entity/TranslatableInterface.php b/src/Contract/Entity/TranslatableInterface.php index 679c648..243186b 100644 --- a/src/Contract/Entity/TranslatableInterface.php +++ b/src/Contract/Entity/TranslatableInterface.php @@ -9,12 +9,12 @@ interface TranslatableInterface { /** - * @return Collection + * @return Collection */ public function getTranslations(); /** - * @return Collection + * @return Collection */ public function getNewTranslations(): Collection; diff --git a/src/EventSubscriber/TranslatableEventSubscriber.php b/src/EventSubscriber/TranslatableEventSubscriber.php index ff3004c..b8bc645 100644 --- a/src/EventSubscriber/TranslatableEventSubscriber.php +++ b/src/EventSubscriber/TranslatableEventSubscriber.php @@ -103,7 +103,6 @@ private function mapTranslatable(ClassMetadata $classMetadata): void $classMetadata->mapOneToMany([ 'fieldName' => 'translations', 'mappedBy' => 'translatable', - 'indexBy' => self::LOCALE, 'cascade' => ['persist', 'remove'], //FIX ME Merge is not supported for Doctrine/Orm see https://github.com/slevomat/doctrine-orm/blob/master/UPGRADE.md 'fetch' => $this->translatableFetchMode, 'targetEntity' => $classMetadata->getReflectionClass() diff --git a/src/Model/Translatable/TranslatableMethodsTrait.php b/src/Model/Translatable/TranslatableMethodsTrait.php index 5118323..19b8cb9 100644 --- a/src/Model/Translatable/TranslatableMethodsTrait.php +++ b/src/Model/Translatable/TranslatableMethodsTrait.php @@ -12,7 +12,7 @@ trait TranslatableMethodsTrait { /** - * @return Collection + * @return Collection */ public function getTranslations() { @@ -24,7 +24,7 @@ public function getTranslations() } /** - * @param Collection $translations + * @param Collection $translations * * @phpstan-param iterable $translations */ @@ -38,7 +38,7 @@ public function setTranslations(iterable $translations): void } /** - * @return Collection + * @return Collection */ public function getNewTranslations(): Collection { @@ -186,15 +186,18 @@ protected function proxyCurrentLocaleTranslation(string $method, array $argument protected function findTranslationByLocale(string $locale, bool $withNewTranslations = true): ?TranslationInterface { $translation = $this->getTranslations() - ->get($locale); + ->filter(static fn(TranslationInterface $translation) => $translation->getLocale() === $locale)->first(); if ($translation) { return $translation; } if ($withNewTranslations) { - return $this->getNewTranslations() - ->get($locale); + $newTranslation = $this->getNewTranslations() + ->filter(static fn(TranslationInterface $translation) => $translation->getLocale() === $locale)->first(); + if ($newTranslation) { + return $newTranslation; + } } return null; diff --git a/src/Model/Translatable/TranslatablePropertiesTrait.php b/src/Model/Translatable/TranslatablePropertiesTrait.php index 46087e8..2726e80 100644 --- a/src/Model/Translatable/TranslatablePropertiesTrait.php +++ b/src/Model/Translatable/TranslatablePropertiesTrait.php @@ -10,14 +10,14 @@ trait TranslatablePropertiesTrait { /** - * @var Collection + * @var Collection */ protected null|Collection $translations = null; /** * @see mergeNewTranslations * - * @var null|Collection + * @var null|Collection */ protected null|Collection $newTranslations = null;