Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[TwigBridge] Added bundle name suggestion on wrongly overrided templates paths#26919
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| $paths =array_unique($loaderPaths['(None)']); | ||
| $bundleNames =array(); | ||
| foreach ($pathsas$path) { | ||
| $relativePath =$path.'/bundles/'; |
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 don't need to check all paths because only<twig.default_path>/bundles/... is taking into account:
symfony/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php
Lines 170 to 172 in6bbb5bc
| if (file_exists($dir =$container->getParameterBag()->resolveValue($config['default_path']).'/bundles/'.$name)) { | |
| $bundleHierarchy[$name][] =$dir; | |
| } |
Use the%twig.default_path% parameter instead.
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.
and<kernel.root_dir>/Resources/<BundleName>/views should be checked too?
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 had the same question but has it's a 4.1 feature, I prefered to use the new Twig override convention. The previous one is no more present in official documentation. Do you think it's necessary?
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.
For your first comment, I had the same idea but I did this choice for two reasons :
- I don't check all paths, just generic ones
- I prefered to use the result of other methods in the command that to duplicate code from another bundle.
Could you please tell me why is better to use the default path parameter?
Can someone give me another point of vue on it?
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.
Sorry for my short explanation, I'll try to be more--vvv now :)
I don't check all paths, just generic ones
For instance, this is a generic one registered byTwigBundle:
(None) : vendor/symfony/twig-bridge/Resources/views/Formand shouldn't be taken into account in this process because this path:
vendor/symfony/twig-bridge/Resources/views/Form/bundles/<BundleName>/doesn't exists either as a Twig's path nor as a directory.
I prefered to use the result of other methods in the command that to duplicate code from another bundle.
My suggestion is about injecting the%twig.default_path% parameter to the command and check in one of the path convention to override templates:<twig.default_path>/bundles/<BundleName>. The another one<kernel.root_dir>/Resources/<BundleName>/views is not promoted anymore but still is available, IMO would be good have this feature here too, so someone using this path can still benefit from it.
Could you please tell me why is better to use the default path parameter?
BecauseTwigBundle has just two paths convention to override templates where you need looking for, hence isn't necessary other paths.
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 !
a3159d4 to366d97aCompare| private$rootDir; | ||
| publicfunction__construct(Environment$twig,string$projectDir =null) | ||
| publicfunction__construct(Environment$twig,string$projectDir =null,array$bundlesMetadata =array(),string$twigDefaultPath,string$rootDir) |
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.
New parameters must have a default value to prevent a BC.
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.
Sorry for forgetting. I wrote it in the first version and forget it in the second one. Thank you
257aea3 to94629b8Comparepmontoya commentedApr 16, 2018
Status: Needs Review |
pmontoya commentedMay 2, 2018
Is something missing? |
| $data['tests'] =array_keys($data['tests']); | ||
| $data['loader_paths'] =$this->getLoaderPaths(); | ||
| $io->writeln(json_encode($data)); | ||
| $this->displayAlternatives($this->findWrongBundleOverrides(),$io); |
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'll break the json output, maybe should be included into a new$data['warning'] above?
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. Thank you
637598d to4ad9593Comparesrc/Symfony/Bridge/Twig/CHANGELOG.md Outdated
| ----- | ||
| * add a`workflow_metadata` function | ||
| * add bundle name suggestion on wrongly overrided templates paths |
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.
overridden
| $data['tests'] =array_keys($data['tests']); | ||
| $data['loader_paths'] =$this->getLoaderPaths(); | ||
| $wrongBundles =$this->findWrongBundleOverrides(); | ||
| if ($wrongBundles) { |
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.
if ($wrongBundles = $this->findWrongBundleOverrides()) {
| if ($wrongBundles) { | ||
| $data['warnings'] =array(); | ||
| $messages =$this->buildWarningMessages($this->findWrongBundleOverrides()); |
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.
Use$wrongBundles here?
| $data['loader_paths'] =$this->getLoaderPaths(); | ||
| $wrongBundles =$this->findWrongBundleOverrides(); | ||
| if ($wrongBundles) { | ||
| $data['warnings'] =array(); |
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.
this var is overridden three lines below
| } | ||
| if (\count($bundleNames)) { | ||
| $loadedBundles =$this->bundlesMetadata; |
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 see why we need that variable
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.
Thanks@xabbuh Code updated
d5bd6ec to54f66a7Comparepmontoya commentedJun 5, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Something to add? |
src/Symfony/Bridge/Twig/CHANGELOG.md Outdated
| ----- | ||
| * add a`workflow_metadata` function | ||
| * add bundle name suggestion on wrongly overridden templates paths |
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.
this needs to be an item under a to be added4.2.0 section
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.
Updated. Thank you
| $alternatives =array(); | ||
| $bundleNames =array(); | ||
| if ($this->rootDir) { |
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 we need to account for$this->projectDir beingnull here too.
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 for this one and the next if too. Thank you
9d534ee toc687afcCompare| $data['loader_paths'] =$this->getLoaderPaths(); | ||
| if ($wrongBundles =$this->findWrongBundleOverrides()) { | ||
| $messages =$this->buildWarningMessages($wrongBundles); | ||
| $data['warnings'] =array_reduce( |
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 am not sure I understand for what we needarray_reduce() here.$messages already is just an array of strings, isn't it?
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're right. It was just dead code. Done
| array_walk( | ||
| $messages, | ||
| function ($message)use ($io) { | ||
| $io->warning(trim($message)); |
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.
Can't we just trim inbuildWarningMessages() and then iterate the array here?
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
Move changelog entry to 4.1.0 to 4.2.0
Check if projectDir is not null before loop
Remove unnecessary loopTrim messages on build rather than on display
nicolas-grekas commentedJun 19, 2018
Thank you@pmontoya. |
…verrided templates paths (pmontoya, Pascal Montoya)This PR was merged into the 4.2-dev branch.Discussion----------[TwigBridge] Added bundle name suggestion on wrongly overrided templates paths| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#26898| License | MITReport unknown folders in templates/bundles in debug:twig and make suggestions if anyDevelopped with@bricejuliaCommits-------acfb325 refs#26898 Remove unnecessary loop Trim messages on build rather than on displayda42b3e refs#26898 Check if projectDir is not null before loopda0c589 refs#26898 Move changelog entry to 4.1.0 to 4.2.07d9467a Add an entry on json export formatbab9d99 Use %twig.default_path% parameter and search in old folder structure too1758de2 [TwigBridge] Added bundle name suggestion on wrongly overrided templates paths
Uh oh!
There was an error while loading.Please reload this page.
Report unknown folders in templates/bundles in debug:twig and make suggestions if any
Developped with@bricejulia