-
-
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
Improve "sonata.admin.template_registry" tag #6566
Improve "sonata.admin.template_registry" tag #6566
Conversation
eba3dfd
to
05b8c2c
Compare
Since array are not allowed inside tags, WDYT about this solution ?
If this is confusing with
We maybe could have two tag, like |
I think about type => template too. IMO we should add |
Nice |
I just have a consideration about the proposed service |
Current we have tags like: WDYT? @sonata-project/contributors |
Indeed. Consistency is the key. |
I think the tags prefixed with
|
Why not using |
I'm sorry. Didn't noticed before that our services are not following the standard. |
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.
Upgrade note / Doc updates will be required. But this seems a great solution.
tests/App/AppKernel.php
Outdated
@@ -102,6 +102,8 @@ protected function configureContainer(ContainerBuilder $containerBuilder, Loader | |||
'strict_variables' => '%kernel.debug%', | |||
'exception_controller' => null, | |||
'form_themes' => ['@SonataAdmin/Form/form_admin_fields.html.twig'], | |||
'paths' => ['%kernel.project_dir%/Resources/views'], | |||
|
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.
You can remove this extra 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.
WIP. I will probably need it in functional tests. Set templates must exists.
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 was talking about the blank 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.
😄
src/DependencyInjection/Compiler/TemplateRegistryCompilerPass.php
Outdated
Show resolved
Hide resolved
{ | ||
const TEMPLATE_REGISTRY_TAG = 'sonata.admin.template_registry'; | ||
const MUTABLE_TEMPLATE_REGISTRY_TAG = 'sonata.admin.template_registry'; | ||
const TEMPLATE_REGISTRY_AWARE_TAG = 'sonata.admin.template_registry_aware'; |
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.
Both tags sound very technical / related to the concrete implementation. Maybe just sonata.admin.template
?
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.
They look like related to the concreate implementation but thye have diffrence functionality too.
"Nonmutable" tags sets template by constructor argument.
"Mutable" tags set template by setTemplate
method.
"Nonaware" tags are for mark template registry service.
"Aware" tags will auto generate template registry.
I will think about it.
Hi @wbloszyk, what's missing to finish the PR ? CC @sonata-project/contributors, any review is good to take. |
$templates = []; | ||
|
||
foreach ($tags as $attributes) { | ||
if (isset($attributes['type'], $attributes['template'])) { |
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, the name "type" for this option is too restrictive. Shouldn't this be "template_name"?
My concern is about scenarios where the passed template could be considered something more general than the "type" concept.
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.
template_name
seems better indeed.
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.
sonata.admin.template_registry.template
tag with name
and value
arguments.
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.
Isn't name
reserved ?
I mean, you currently used
- {name: sonata.admin.mutable_template_registry_aware, type:'edit', template: '@@FooAdmin/CRUD/edit.html.twig'}
So how could we use name
instead of type
since name
is already used ?
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.
My bad. template_name
and template_value
to be consider. I will finish it in friday evening or in saturday.
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'd use other name than template_value
. Maybe template_path
or just template
.
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.
template_path
will be the best.
src/DependencyInjection/Compiler/TemplateRegistryCompilerPass.php
Outdated
Show resolved
Hide resolved
$templateRegistryDefinition = $container->getDefinition($reference->__toString()); | ||
|
||
if (!is_a($templateRegistryDefinition->getClass(), $templateRegistryInterface, true)) { | ||
throw new \Exception(sprintf( |
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, this exception could use a less generic type (something like \InvalidArgumentException
, \BadMethodCallException
or similar.
I don't know if we have domain specific exceptions available under the Symfony\Component\DependencyInjection\
NS for cases like this.
tests/DependencyInjection/Compiler/TemplateRegistryCompilerPassTest.php
Outdated
Show resolved
Hide resolved
fc8cda9
to
d4324c2
Compare
What do you think about make simplest template configuration? |
Could you please rebase your PR and fix merge conflicts? |
c2cc237
to
959d7c2
Compare
@wbloszyk the changelog should be updated |
351717e
to
cff51fb
Compare
Could you please rebase your PR and fix merge conflicts? |
cff51fb
to
de31fc6
Compare
Could you please rebase your PR and fix merge conflicts? |
Tags | ||
====== | ||
|
||
sonata.admin.template_registry |
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 don't fully understand this doc.
In the first case you defined a app.admin.post.template_registry
but you never use it.
If it's not well documented, it will never be used.
Instead of a technical documentation about the tag, it seems better to have a functional documentation about the feature related: how to override an admin template.
- First case, directly in the configuration: thanks to the
sonata.admin.template_registry
tag. - Second case, with a re-usable template registry (and how to do 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.
In the first case you do not have to use template registry with admin. This service can be standalone registry. Service name is confusing, I will change it.
IMO template registry should be move to sonata-project/twig-extensions
with this tags.rst
file and documentation dedicated for override admin template should be add.
WDYT? @sonata-project/contributors
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 still don't understand how to use a template registry, so I cannot say if it's better in sonataAdmin or twigExtensions.
But currently, it's the only blocking point for Sonata 4.0.
So if we can't solve the situation, we should just un-deprecate setTemplate
, remove templateRegistry and delay this feature to the next major.
arguments: [~, Sonata\AdminBundle\Tests\App\Model\Foo, ~] | ||
tags: | ||
- {name: sonata.admin, manager_type: test, label: Foo} | ||
- {name: sonata.admin.template_registry, template_name:'edit', template_path: '@FooAdmin/CRUD/edit.html.twig'} |
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.
- {name: sonata.admin.template_registry, template_name:'edit', template_path: '@FooAdmin/CRUD/edit.html.twig'} | |
- {name: sonata.admin.template_registry, template_name: 'edit', template_path: '@FooAdmin/CRUD/edit.html.twig'} |
tags: | ||
- {name: sonata.admin, manager_type: test, label: Foo} | ||
- {name: sonata.admin.template_registry, template_name:'edit', template_path: '@FooAdmin/CRUD/edit.html.twig'} | ||
- {name: sonata.admin.template_registry, template_name:'list', template_path: '@FooAdmin/CRUD/list.html.twig'} |
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.
- {name: sonata.admin.template_registry, template_name:'list', template_path: '@FooAdmin/CRUD/list.html.twig'} | |
- {name: sonata.admin.template_registry, template_name: 'list', template_path: '@FooAdmin/CRUD/list.html.twig'} |
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 yaml need use double @
Close in favor of #6766 |
Subject
After move templates from
AbsractAdmin
toTemplateRegistry
some methods were deprecated (likesetTemplate
andsetTemplates
). To allow configuration templates in easy way like it was before some important change are require.Additional attributes on tag
Usages
with
TemplateRegistryInterface
You MUST set templates by argument but you can override it by tag.
with
MutableTemplateRegistryInterface
You CAN set templates by argument, override it by call
setTemplate
orsetTemplates
method and than override it again by tag.with
TemplateRegistryAwareInterface
setTemplateRegistry
is called. You should override template directly on this template registry then.setTemplateRegistry
is not called. In this caseTemplateRegistry
will be auto generate with id equal totagged_service_id
+.template_registry
.with
MutableTemplateRegistryAwareInterface
setTemplateRegistry
is called but it is not recommended.setTemplateRegistry
is not called. In this caseMutableTemplateRegistry
will be auto generate with id equal totagged_service_id
+.template_registry
.Examples
I am targeting this branch, because this change respect BC and should be done in 3.x.
Changelog
To do