Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Merged
nicolas-grekas merged 6 commits intosymfony:masterfrompmontoya:feature-26898
Jun 19, 2018

Conversation

@pmontoya
Copy link

@pmontoyapmontoya commentedApr 13, 2018
edited by nicolas-grekas
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#26898
LicenseMIT

Report unknown folders in templates/bundles in debug:twig and make suggestions if any

Developped with@bricejulia

$paths =array_unique($loaderPaths['(None)']);
$bundleNames =array();
foreach ($pathsas$path) {
$relativePath =$path.'/bundles/';
Copy link
Member

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:

if (file_exists($dir =$container->getParameterBag()->resolveValue($config['default_path']).'/bundles/'.$name)) {
$bundleHierarchy[$name][] =$dir;
}

Use the%twig.default_path% parameter instead.

Copy link
Member

@ycerutoycerutoApr 13, 2018
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Copy link
Author

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?

Copy link
Author

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?

Copy link
Member

@ycerutoycerutoApr 15, 2018
edited
Loading

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/Form

and 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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Done !

@nicolas-grekasnicolas-grekas changed the title[TwigBridge] Added bundle name suggestion on wrongly overrided templa…[TwigBridge] Added bundle name suggestion on wrongly overrided templates pathsApr 14, 2018
@nicolas-grekasnicolas-grekas added this to the4.1 milestoneApr 14, 2018
@pmontoyapmontoyaforce-pushed thefeature-26898 branch 6 times, most recently froma3159d4 to366d97aCompareApril 16, 2018 05:08
private$rootDir;

publicfunction__construct(Environment$twig,string$projectDir =null)
publicfunction__construct(Environment$twig,string$projectDir =null,array$bundlesMetadata =array(),string$twigDefaultPath,string$rootDir)
Copy link
Contributor

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.

Copy link
Author

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

@pmontoya
Copy link
Author

Status: Needs Review

@pmontoya
Copy link
Author

Is something missing?

$data['tests'] =array_keys($data['tests']);
$data['loader_paths'] =$this->getLoaderPaths();
$io->writeln(json_encode($data));
$this->displayAlternatives($this->findWrongBundleOverrides(),$io);
Copy link
Member

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Done. Thank you

@pmontoyapmontoyaforce-pushed thefeature-26898 branch 2 times, most recently from637598d to4ad9593CompareMay 3, 2018 15:41
-----

* add a`workflow_metadata` function
* add bundle name suggestion on wrongly overrided templates paths
Copy link
Member

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) {
Copy link
Member

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());
Copy link
Member

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();
Copy link
Member

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;
Copy link
Member

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks@xabbuh Code updated

@pmontoyapmontoyaforce-pushed thefeature-26898 branch 2 times, most recently fromd5bd6ec to54f66a7CompareMay 14, 2018 10:07
@pmontoya
Copy link
Author

pmontoya commentedJun 5, 2018
edited
Loading

Something to add?

-----

* add a`workflow_metadata` function
* add bundle name suggestion on wrongly overridden templates paths
Copy link
Member

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

Copy link
Author

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) {
Copy link
Member

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.

Copy link
Author

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

@pmontoyapmontoyaforce-pushed thefeature-26898 branch 2 times, most recently from9d534ee toc687afcCompareJune 13, 2018 12:23
$data['loader_paths'] =$this->getLoaderPaths();
if ($wrongBundles =$this->findWrongBundleOverrides()) {
$messages =$this->buildWarningMessages($wrongBundles);
$data['warnings'] =array_reduce(
Copy link
Member

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?

Copy link
Author

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));
Copy link
Member

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Done

Pascal Montoyaand others added6 commitsJune 18, 2018 12:27
@nicolas-grekas
Copy link
Member

Thank you@pmontoya.

@nicolas-grekasnicolas-grekas merged commitacfb325 intosymfony:masterJun 19, 2018
nicolas-grekas added a commit that referenced this pull requestJun 19, 2018
…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
@nicolas-grekasnicolas-grekas modified the milestones:next,4.2Nov 1, 2018
This was referencedNov 3, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@ycerutoycerutoyceruto left review comments

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@xabbuhxabbuhxabbuh approved these changes

+1 more reviewer

@fmatafmatafmata requested changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.2

Development

Successfully merging this pull request may close these issues.

6 participants

@pmontoya@nicolas-grekas@fmata@xabbuh@yceruto@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp