-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add AbstractAdmin::createNewInstance method #6883
Conversation
Is it needed to make it public ? Cant it be protected instead ? And should we deprecate alterNewInstance in favor of createNewInstance then ? |
mmm not really, I'll change it. |
tests/App/Admin/TranslatedAdmin.php
Outdated
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
|
||
final class TranslatedAdmin extends AbstractAdmin | ||
{ | ||
public function createNewInstance(): object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function createNewInstance(): object | |
protected function createNewInstance(): object |
tests/App/Admin/FooAdmin.php
Outdated
@@ -25,7 +25,7 @@ | |||
|
|||
class FooAdmin extends AbstractAdmin | |||
{ | |||
public function getNewInstance() | |||
public function createNewInstance(): object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected
I'm not sure about this one to be honest, since it's called after |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but the commit message (and PR title) are a bit misleading since we are not adding anything to AdminInterface
Instead of overriding ModelManagerInterface::getModelInstance to custom construct their objects, now the user can do it from the related Admin class. The Instantiator class will be use in 4.0 and its code is copied from the persistence bundles.
Thanks @franmomu |
Subject
Ref: #6850 (comment)
In 4.0, if a user wants to override the way in which their objects are created, they will have to override
ModelManagerInterface::getModelInstance
for each class.The code from
ModelManagerInterface::getModelInstance()
in our persistence bundles (which has been copied toInstantiator::instantiate()
), is not persistence related.So this PR adds a
AdminInterface::createNewInstance()
method which the user can override to use a factory, service or any other pattern to create their objects.I am targeting this branch, because this is BC.
Changelog