-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[TwigBundle] Adds bundle view path in a delayed compiler pass #30527
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
Conversation
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 looks better than before :) Thank you!
It will be good to have a test where we can see this feature in action.
src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/BundleViewPathPass.php
Outdated
Show resolved
Hide resolved
I'm working on it |
src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/BundleViewPathPass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php
Outdated
Show resolved
Hide resolved
I've added a test of the feature |
@yceruto @nicolas-grekas Any idea on how to fix the error on AppVeyor/Travis ? |
The |
@alterphp please rebase to master again and update the PR template for "master" branch and "New feature", the current one belongs to the previous PR. I guess @nicolas-grekas has been confused because of it, and has changed the base branch to 4.2. |
That was my mistake to leave |
It will be great to have this for 4.2, but to be honest, I think this is a new feature, there is no faulty behavior in 4.2 |
I think using the PrependExtensionInterface in your bundle to inject some config for TwigBundle for the path is a better way than delaying the configuration of the bundle. |
Yea, I thought that too (#30360 (comment)) as workaround, but when two extra bundles are involved then it is very hard to configure the paths order. |
To be clear, this is the workaround through twig:
paths:
# user-configured paths
# ...
# added from CompanyBundle through PrependExtensionInterface
'templates/bundles/EasyAdminBundle/': EasyAdmin # the first one wins
'vendor/acme/company-bundle/src/Resources/views': EasyAdmin
# added from CommonBundle through PrependExtensionInterface
'templates/bundles/EasyAdminBundle/': EasyAdmin # it doesn't really added
'vendor/acme/common-bundle/src/Resources/views': EasyAdmin
# added from TwigExtension
'templates/bundles/EasyAdminBundle/': EasyAdmin # never reached
'vendor/easycorp/easyadmin-bundle/src/Resources/views': EasyAdmin
'vendor/easycorp/easyadmin-bundle/src/Resources/views': !EasyAdmin Code: class CompanyExtension extends Extension implements PrependExtensionInterface
{
// ...
public function prepend(ContainerBuilder $container)
{
$twigConfigs = $container->getExtensionConfig('twig');
$paths = [];
// keeping user-configured paths
foreach ($twigConfigs as $twigConfig) {
if (isset($twigConfig['paths'])) {
$paths += $twigConfig['paths'];
}
}
// the overriding dir at project level (make sure the dir exists first)
$paths['templates/bundles/EasyAdminBundle/'] = 'EasyAdmin';
// new overriding dir at vendor level
$paths[\dirname(__DIR__).'/Resources/views/'] = 'EasyAdmin';
$container->prependExtensionConfig('twig', ['paths' => $paths]);
}
} Same for |
This is what I get by making my 2 bundles using
What I want is :
2 issues :
This could work by configuring at project-level, not trough bundle config. |
Ok, done |
@alterphp Have you tried with the code #30527 (comment) that I've prepared just for you?
The order in which the extensions are executed depends on the order in which the bundles are registered. Try registering
You need to add the EasyAdmin path again, see #30527 (comment). |
@yceruto Yes I used what you've written especially for me ;-) Here is
Here is
KiplinAdminBundle is loaded after EasyAdminExtensionBundle, let's see
This is what I dislike the most with this workaround, you have to push again a path that should, by definition, stay on top of the namespace paths stack. This is the promise of TwigBundle configuration IMO. And as a third-party bundle provider, this is a pain to explain to users that they have to add configuration to their projects to keep the default expected behavior of Twig templates cascading paths... WDYT ? |
As @javiereguiluz told on Slack, I ping to include this before 4.3 feature freeze ! @nicolas-grekas |
Hi @alterphp, this is what I meant #30527 (comment): // ...
// the overriding dir at project level (make sure the dir exists first)
$paths['templates/bundles/TwigBundle/'] = 'EasyAdmin';
// ... The user/dev doesn't care about it, they are internal details. |
For project developers, why not (but it's some overhead, unoptimized memory usage anyway). As a framework, Symfony goal is also to ease the development of third-party bundles, it's not only a matter of end-users/developers. |
btw, the diff of this PR should be cleaned. There is no reason for it to change the Cache component. |
@stof done |
Here is the workaround required without this PR enhancement : alterphp/EasyAdminExtensionBundle#115
It works but it is pretty unstable and not at the quality level a 3rd party bundle should offer, IMO. |
I'll create a small demo to see the differences between both approaches, I hope this helps to decide what to do here. |
and here is it https://github.com/yceruto/twigpathprepend Yes, the path So I think @stof is right and probably delaying the bundle paths registration is not worth it. |
@yceruto Does it mean that we can close this PR? |
Yes, I think so, also others arguments here:
|
@alterphp Thank you so much for your work on this topic; you spent a lot of time on it. Please, don't hesitate to contact me to continue talking about this topic if you want, I'm glad to help you. |
Hi @yceruto. Thanks for your support. I finally implemented your workaround in my bundles. It does the job ! It's a bit tricky because I have 2 overriding bundles above EasyAdmin but it works. |
Replaces #30360.
Delaies bundle view path registration into Twig filesystem loader in order to let 3rd party bundle override them if needed.