Skip to content

Commit

Permalink
Add alterObject method (#6864)
Browse files Browse the repository at this point in the history
* Add alterObject method

* Fix null object case
  • Loading branch information
VincentLanglet authored Feb 16, 2021
1 parent b1e0ff8 commit 26cca4b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1330,13 +1330,21 @@ public function attachAdminClass(FieldDescriptionInterface $fieldDescription)
$fieldDescription->setAssociationAdmin($admin);
}

/**
* @final since sonata-project/admin-bundle 3.x
*/
public function getObject($id)
{
if (null === $id) {
return null;
}

$object = $this->getModelManager()->find($this->getClass(), $id);
if (null === $object) {
return null;
}

$this->alterObject($object);
foreach ($this->getExtensions() as $extension) {
$extension->alterObject($this, $object);
}
Expand Down Expand Up @@ -2879,6 +2887,13 @@ protected function alterNewInstance(object $object): void
{
}

/**
* @phpstan-param T $object
*/
protected function alterObject(object $object): void
{
}

/**
* @return string[]
*/
Expand Down

0 comments on commit 26cca4b

Please sign in to comment.