-
-
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
Fix TemplateRegistry usages #6387
Conversation
a19f538
to
cf2b06c
Compare
This should probably be done on master to avoid BC breaks |
cf2b06c
to
c42767a
Compare
I think I should revert NEXT_MAJOR. Someone can override |
c42767a
to
9cc0d9f
Compare
9cc0d9f
to
ced1804
Compare
@core23 Can we merge it? |
9561893
to
c255ef3
Compare
b37989a
to
0bbfc79
Compare
@phansys Sorry for another request for review. I click it before icon refresh. :) |
If the plan is to call |
0bbfc79
to
c61566f
Compare
c61566f
to
d796b42
Compare
src/Admin/AbstractAdmin.php
Outdated
{ | ||
return $query; | ||
return $this->templateRegistry instanceof MutableTemplateRegistryInterface; |
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.
Is there any constraint requiring setTemplate()
or setTemplates()
to be defined? If not, I think we should use TemplateRegistryInterface
instead of MutableTemplateRegistryInterface
.
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.
In 3.x branch:
public function setTemplates(array $templates)
{
// NEXT_MAJOR: Remove this line
$this->templates = $templates;
$this->getTemplateRegistry()->setTemplates($templates);
}
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.
I understand that's the case for 3.x
, but then we should add a NEXT_MAJOR
comment explaining how to proceed in the next major release.
The changes at AdminInterface
should refer to TemplateRegistryInterface
, right?
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.
$admin->getTemplateRegistry() should be equal to admin_code.template_registry
service. It is created on:
final class TemplateRegistry implements MutableTemplateRegistryInterface
So MutableTemplateRegistryInterface
will be correct.
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.
IMO we should check against null.
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.
Checking will be add in master. We can't throw exeption becouse someone compare getTemplateRegistry()
to null. What we can do in 3.x is only add custom description for $this->getTemplateRegistry()->setTemplates($templates); exception.
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.
I mean: return $this->... !== null
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.
done
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.
I think @phansys is right, there is no need to return MutableTemplateRegistryInterface
if we are not using setTemplates
or setTemplate
.
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.
Update src/Admin/AbstractAdmin.php Co-authored-by: Javier Spagnoletti <[email protected]> Update src/Admin/AbstractAdmin.php Co-authored-by: Javier Spagnoletti <[email protected]> Update src/Admin/AbstractAdmin.php Co-authored-by: Javier Spagnoletti <[email protected]>
d796b42
to
4313bfc
Compare
* @method array configureActionButtons(string $action, ?object $object = null) | ||
* @method string getSearchResultLink(object $object) | ||
* @method void showMosaicButton(bool $isShown) | ||
* @method bool isDefaultFilter(string $name) // NEXT_MAJOR: Remove this |
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.
Not related to this PR, but we can remove this line
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.
To many change on this PR. Lets do it in another PR. Mybe we should create "Clean up" PR? 😅
@phansys sugestion is made and accepted by @jordisala1991.
} | ||
|
||
protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface | ||
final public function hasTemplateRegistry(): bool |
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.
Is this method used outside the AbstractAdmin
? If so, should be added to the interface?
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.
It is new method, so it is not used for now. IMO all setTemplateRegistry
, getTemplateRegistry
and hasTemplateRegistry
should be add to seperate TemplateRegistryOwnerInterface
. AdminInterface
should inplemented it.
…()` and `setTemplates()` in `AbstractAdmin` PR sonata-project#6387 deprecates methods `AbstractAdmin::setTemplate()` and `AbstractAdmin::setTemplates()`, but the documentation still recommends to use them. These calls were updated in order to use the template registry services.
…()` and `setTemplates()` in `AbstractAdmin` PR sonata-project#6387 deprecates methods `AbstractAdmin::setTemplate()` and `AbstractAdmin::setTemplates()`, but the documentation still recommends to use them. These calls were updated in order to use the template registry services.
Subject
Based on #6383 (comment) I made some research and I found what can be improve.
admin_code
// Admin objectadmin_code.template_registry
// TemplateRegistry object dedicated for specify AdminIt mean We should be able to get
TemplateRegistry
object directly from admin, becouse we can get it from container.I also remove some unnecessary
NEXT_MAJOR
I am targeting this branch, because this change respect BC.
Changelog