Skip to content

Commit

Permalink
bug #6601 Fix create form when entity id not set (alexndlm)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 4.x branch.

Discussion
----------

Fix create form when entity id not set

Fix for #6549

Commits
-------

9fb215f Fix create form when entity id not set
  • Loading branch information
javiereguiluz committed Dec 3, 2024
2 parents 3513817 + 9fb215f commit 6ea974b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Dto/EntityDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
use Symfony\Component\ExpressionLanguage\Expression;
use Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException;
use Symfony\Component\PropertyAccess\PropertyAccess;

/**
Expand Down Expand Up @@ -103,7 +104,11 @@ public function getPrimaryKeyValue(): mixed
->enableExceptionOnInvalidIndex()
->getPropertyAccessor();

$primaryKeyValue = $propertyAccessor->getValue($this->instance, $this->primaryKeyName);
try {
$primaryKeyValue = $propertyAccessor->getValue($this->instance, $this->primaryKeyName);
} catch (UninitializedPropertyException $exception) {
$primaryKeyValue = null;
}

return $this->primaryKeyValue = $primaryKeyValue;
}
Expand Down

0 comments on commit 6ea974b

Please sign in to comment.