Skip to content

Prepend Child Bundle paths before the parent #9112

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

Closed
wants to merge 8 commits into from
Closed

Prepend Child Bundle paths before the parent #9112

wants to merge 8 commits into from

Conversation

trsteel88
Copy link
Contributor

This fixes #9085

Say you have AcmeDemoBundle and AppDemoBundle. AcmeDemoBundle is the parent of AppDemoBundle.

If you load templates using @AcmeDemoBundle/ControllerDir/template.html.twig it means that you cannot override the template in AppDemoBundle. The patch below prepends the AppDemoBundle Resources directory to the AcmeDemo namespace.

The namespace directories would not result in:

[AcmeDemo] => Array(
    [0] => [absolute-dir-here]/src/App/DemoBundle/Resources/views
    [1] => [absolute-dir-here]/app/Resources/AcmeDemoBundle/views
    [2] => [absolute-dir-here]/src/Acme/DemoBundle/Resources/views
)

@jakzal
Copy link
Contributor

jakzal commented Sep 24, 2013

Imo the application level Resources should be loaded first.

@trsteel88
Copy link
Contributor Author

You are right. I will update shortly.

@@ -78,6 +78,16 @@ public function load(array $configs, ContainerBuilder $container)
if (is_dir($dir = dirname($reflection->getFilename()).'/Resources/views')) {
$this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $bundle);
}

if ($reflection->hasMethod('getParent')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The getParent() method is always there since it's a part of Symfony\Component\HttpKernel\Bundle\BundleInterface. There's no need to verify its existence.

@jakzal
Copy link
Contributor

jakzal commented Sep 24, 2013

And finally, would be good to cover this with tests.

@trsteel88
Copy link
Contributor Author

@jakzal app Resources will now take priority. I had to sort it by Child bundles (and removed prepending) to ensure that the priority is correct.

@trsteel88
Copy link
Contributor Author

@jakzal I am not too sure how to write tests for this use case as there will be no parent/child bundles to access from the tests?

$reflection = new \ReflectionClass($class);

$bundleInstance = $reflection->newInstance();
if (null === $parentBundle = $bundleInstance->getParent()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can't see the need of $parentBundlehere

fabpot added a commit that referenced this pull request Dec 31, 2013
This PR was submitted for the 2.3-dev branch but it was merged into the 2.3 branch instead (closes #9112).

Discussion
----------

Prepend Child Bundle paths before the parent

This fixes #9085

Say you have AcmeDemoBundle and AppDemoBundle. AcmeDemoBundle is the parent of AppDemoBundle.

If you load templates using @AcmeDemoBundle/ControllerDir/template.html.twig it means that you cannot override the template in AppDemoBundle. The patch below prepends the AppDemoBundle Resources directory to the AcmeDemo namespace.

The namespace directories would not result in:

```
[AcmeDemo] => Array(
    [0] => [absolute-dir-here]/src/App/DemoBundle/Resources/views
    [1] => [absolute-dir-here]/app/Resources/AcmeDemoBundle/views
    [2] => [absolute-dir-here]/src/Acme/DemoBundle/Resources/views
)
```

Commits
-------

19fad88 Prepend Child Bundle paths before the parent
@fabpot fabpot closed this Dec 31, 2013
@stof
Copy link
Member

stof commented Jan 2, 2014

@fabpot I suggest reverting this for now as it is not BC. It forbids using constructor arguments in bundle classes

@jakzal
Copy link
Contributor

jakzal commented Jan 2, 2014

👍 for reverting. I'm not sure if that patch works correctly anyway (no test case was added).

@bendavies
Copy link
Contributor

can't newInstanceWithoutConstructor just be used, and whatever the work around is for that for php < 5.4?

fabpot added a commit that referenced this pull request Jan 2, 2014
…el88)"

This reverts commit cfa99a9, reversing
changes made to f8965b6.
@fabpot
Copy link
Member

fabpot commented Jan 2, 2014

reverted

fabpot added a commit that referenced this pull request Jan 2, 2014
* 2.3:
  Revert "bug #9112 Prepend Child Bundle paths before the parent (trsteel88)"
fabpot added a commit that referenced this pull request Jan 2, 2014
* 2.4:
  Revert "bug #9112 Prepend Child Bundle paths before the parent (trsteel88)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Twig] Namespaced template paths
6 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy