diff --git a/src/Doctrine/PersistentTranslatable.php b/src/Doctrine/PersistentTranslatable.php index a78d7aa..ba21eb8 100644 --- a/src/Doctrine/PersistentTranslatable.php +++ b/src/Doctrine/PersistentTranslatable.php @@ -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; @@ -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; }