-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move appendParentObject into createNewInstance (#7549)
* move appendParentObject into createNewInstance to allow creating new instances for which the parent entity will not be managed by sonata * add upgrade notes * Update UPGRADE-4.x.md Co-authored-by: Vincent Langlet <[email protected]> Co-authored-by: Christian Gripp <[email protected]> Co-authored-by: Vincent Langlet <[email protected]>
- Loading branch information
1 parent
3d0cbd1
commit 2f6213e
Showing
4 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
UPGRADE 4.x | ||
=========== | ||
|
||
UPGRADE FROM 4.x to 4.x | ||
=========================== | ||
|
||
### appendParentObject is called inside createNewInstance with child admins | ||
|
||
In a child admin, if you were overriding `createNewInstance` and relying on sonata to provide the needed "parent" entity | ||
to the instance, now you have to call `appendParentObject` manually. | ||
|
||
Before: | ||
```php | ||
final class PostAdmin extends AbstractAdmin | ||
{ | ||
public function createNewInstance(): object | ||
{ | ||
return new Post(); | ||
} | ||
} | ||
``` | ||
|
||
After: | ||
```php | ||
|
||
final class PostAdmin extends AbstractAdmin | ||
{ | ||
public function createNewInstance(): object | ||
{ | ||
$object = new Post(); | ||
|
||
// set the post author if the parent admin is "AuthorAdmin" | ||
$this->appendParentObject($object); | ||
|
||
return $object; | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\Tests\Fixtures\Admin; | ||
|
||
use Sonata\AdminBundle\Admin\AbstractAdmin; | ||
use Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\Tag; | ||
|
||
/** | ||
* @phpstan-extends AbstractAdmin<Tag> | ||
*/ | ||
final class TagWithoutPostAdmin extends AbstractAdmin | ||
{ | ||
protected function createNewInstance(): object | ||
{ | ||
return new Tag(); | ||
} | ||
} |