Skip to content
Open
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
5 changes: 5 additions & 0 deletions src/Doctrine/PersistentTranslatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Doctrine\Common\Collections\Selectable;
use Doctrine\ORM\UnitOfWork;
use Exception;
use InvalidArgumentException;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use ReflectionClass;
Expand Down Expand Up @@ -97,6 +98,10 @@ public function __construct(
$this->valueForEjection = $currentValue;
} elseif ($currentValue instanceof Translatable) {
$currentValue->copy($this);

if (!isset($this->primaryValue) && !(new ReflectionProperty($this, 'primaryValue'))->isInitialized($this)) {
throw new InvalidArgumentException('An object of class '.$class.' has no value set (not even NULL) for the property "'.$this->translatedProperty->getName().'" for the primary locale "'.$primaryLocale.'" configured for this class (e.g. via `#[Polyglot\Locale(primary: "'.$primaryLocale.'")]`). Check any assignments of `new Translatable`s to the property "'.$this->translatedProperty->getName().'": If a $locale is passed, it differs from the primary locale configured the class ("'.$primaryLocale.'"). If no $locale is passed, the primary locale configured the class ("'.$primaryLocale.'") differs from the application default locale (configured via `webfactory_polyglot.defaultLocale`).');
}
} else {
$this->primaryValue = $currentValue;
}
Expand Down