Skip to content

Commit

Permalink
Fix KnpLabs#766: Ensure translatable is loaded when local variables a…
Browse files Browse the repository at this point in the history
…re accessed
  • Loading branch information
bobvandevijver authored Jun 11, 2024
1 parent aa7c160 commit c45681b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Model/Translatable/TranslatableMethodsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Persistence\Proxy;
use Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface;
use Knp\DoctrineBehaviors\Exception\TranslatableException;

Expand Down Expand Up @@ -104,6 +105,10 @@ public function setCurrentLocale(string $locale): void

public function getCurrentLocale(): string
{
if ($this instanceof Proxy && !$this->__isInitialized()) {
$this->__load();
}

return $this->currentLocale ?: $this->getDefaultLocale();
}

Expand All @@ -114,6 +119,10 @@ public function setDefaultLocale(string $locale): void

public function getDefaultLocale(): string
{
if ($this instanceof Proxy && !$this->__isInitialized()) {
$this->__load();
}

return $this->defaultLocale;
}

Expand Down

0 comments on commit c45681b

Please sign in to comment.