Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Contract/Entity/TranslatableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
interface TranslatableInterface
{
/**
* @return Collection<string, TranslationInterface>
* @return Collection<int, TranslationInterface>
*/
public function getTranslations();

/**
* @return Collection<string, TranslationInterface>
* @return Collection<int, TranslationInterface>
*/
public function getNewTranslations(): Collection;

Expand Down
1 change: 0 additions & 1 deletion src/EventSubscriber/TranslatableEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 9 additions & 6 deletions src/Model/Translatable/TranslatableMethodsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
trait TranslatableMethodsTrait
{
/**
* @return Collection<string, TranslationInterface>
* @return Collection<int, TranslationInterface>
*/
public function getTranslations()
{
Expand All @@ -24,7 +24,7 @@ public function getTranslations()
}

/**
* @param Collection<string, TranslationInterface> $translations
* @param Collection<int, TranslationInterface> $translations
*
* @phpstan-param iterable<TranslationInterface> $translations
*/
Expand All @@ -38,7 +38,7 @@ public function setTranslations(iterable $translations): void
}

/**
* @return Collection<string, TranslationInterface>
* @return Collection<int, TranslationInterface>
*/
public function getNewTranslations(): Collection
{
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Translatable/TranslatablePropertiesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
trait TranslatablePropertiesTrait
{
/**
* @var Collection<string, TranslationInterface>
* @var Collection<int, TranslationInterface>
*/
protected null|Collection $translations = null;

/**
* @see mergeNewTranslations
*
* @var null|Collection<string, TranslationInterface>
* @var null|Collection<int, TranslationInterface>
*/
protected null|Collection $newTranslations = null;

Expand Down
Loading