-
Notifications
You must be signed in to change notification settings - Fork 76
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
Bugfix FS Loader #165
Bugfix FS Loader #165
Conversation
@peterrehm I am actually not sure if I completely understood the underlying issue. Can you give a concrete example that would fail without this change? |
I think the problem is for sure the implementation here in the ThemeBundle. Assume an app with 2 themes, I am having a login view With the Symfony Templating way of calling templates This is cause in the
This used to work since the With the changes in FOSUserBundle now templates names are provided which can be resolved from the But the parent file is resolved properly Does this make the issue more clear? |
On a side note I am not sure but without further investigation I think this bundle might need some work so that the Templating Component is fully optional? |
I do not know how this class initially was supposed to work so this idea might not work. But wouldn't it be better to not extend the |
I would assume it has been testes mainly against the :: notation. Also as you can see the What do you think? |
If I don't miss anything, the only thing that is different is the way cache entries are built. But in this case it IMO does not make much sense to duplicate the logic from TwigBundle, but only decorate it and populate the cache accordingly. Though maybe @lsmith77 has some more insights in why the loader was implemented this way. |
I think decorating does not make much sense from my understanding as you need to provide an entire loader class. I think this is why the Loader of the TwigBundle works the same other than decorating the original loader. |
Where is that necessary? I mean the |
That is what I mean, in order to comply with the |
After talking with @peterrehm about the issue I think that this PR is the right solution. |
@lsmith77 What do you think? |
@lsmith77 the issue is not specific to FOSUserBundle 2. The loader of LiipThemeBundle seems to be incompatible with the native Twig namespace syntax ( |
@stof ie. you also agree that this is the right approach? |
Well, I don't think this will allow theming templates using the Twig native syntax. The parser will not parse this syntax AFAIK. |
This will work perfectly, I tried it in my app. |
well, a test should still be added to ensure it keeps working IMO. this is what tests are for |
Oh and there is no parser in this bundle, only the locator is overriden. |
@peterrehm what @stof is saying there should be a test case with the |
I played around with it figuring out larger issues when it comes to the test: If I remove the Bundle prefix in this test, everything passes, but even when I change |
Okay, I did some further research on this matter with the conclusion this behaviour is already tested: The current locator is designed that in case of what this package sees as bundle notation (starting with @) it will add a Bundle suffix if the suffix has been omitted. https://github.com/liip/LiipThemeBundle/blob/master/Locator/FileLocator.php#L174 This is IMHO covered with this Test where If wanted I could add e.g. $this->assertResourcesEquals($fileLocator, '@ThemeBundle/Resources/views/template', '@Theme/Resources/views/template'); to be more explicit. This does have a drawback as the nativ Twig syntax will be modified to the Templating syntax which works for now, but this might need a complete rewrite to Symfony's intentions in this regard: http://symfony.com/blog/new-in-symfony-2-7-twig-as-a-first-class-citizen |
Hmm but why wasn't the test failing before this change? |
Nope, I was wondering why it was not failing. |
@lsmith77 What do you think? Any further concerns? |
nope .. merged. thx |
👍 |
@peterrehm @lsmith77 I guess you will have to create a test for the loader itself to see it breaking without this change as the order in which methods are called matters for the bugfix (didn't find the time to evaluate this further though, sorry). |
It should not but I just saw that I did not push the latest version of my branch to the PR. |
Due to the changes in FOSUserBundle (FriendsOfSymfony/FOSUserBundle#2378) the overriding of themes stopped working in some cases.
I digged into the code with 2 cases:
@FOSUser/Security/login.html.twig
Does not work since the call to
$file = parent::findTemplate((string) $template);
resolves a proper template not concerning the theme. However included templates do take the theme into account.FOSUserBundle:Security:login.html.twig
$file = parent::findTemplate((string) $template);
throws an Exception which I do not understand, but the call to the parser and locater are resolving the proper template.Reodering as done with this PR fixes that issue.
Potential side effects might be performance as the custom logic has a higher priority than the SF loader.
It is also strange that this has no effect on tests.
Tickets: