mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
bug #10082 [Theme] Allow overriding templates from plugins (1.2.*) (Zales0123, pamil)
This PR was merged into the 1.2 branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | 1.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | fixes https://github.com/Sylius/Sylius/issues/9654 | License | MIT It's hard to test this change with some functional test in a current tests structure, as it would require to use `SyliusPluginTrait` in test bundle/plugin, but it's in a core bundle :/ I have some idea have to test it properly with a Behat scenario, but I need to spend a few more minutes on that :) It would be nice if someone could incorporate these changes into their application and see does it work as expected (cc @jacquesbh :)). I've of course done that, but _better safe than sorry_ 🐃 This change only applies to `1.2` branch, for Sylius `^1.3` take a look here: https://github.com/Sylius/Sylius/pull/10083. Commits -------2add023996Fix plugin templates resolving on 1.2b4084c44e2Replace regexp with plain string operation
This commit is contained in:
commit
2401264739
2 changed files with 21 additions and 1 deletions
|
|
@ -57,7 +57,7 @@ final class TemplateNameParser implements TemplateNameParserInterface
|
|||
}
|
||||
|
||||
$template = new TemplateReference(
|
||||
$matches[1] ? $matches[1] . 'Bundle' : '',
|
||||
$this->getBundleOrPluginName($matches[1]),
|
||||
$matches[2],
|
||||
$matches[3],
|
||||
$matches[4],
|
||||
|
|
@ -74,4 +74,13 @@ final class TemplateNameParser implements TemplateNameParserInterface
|
|||
|
||||
return $this->cache[$name] = $template;
|
||||
}
|
||||
|
||||
private function getBundleOrPluginName(string $name): string
|
||||
{
|
||||
if (substr($name, -6) === 'Plugin') {
|
||||
return $name;
|
||||
}
|
||||
|
||||
return $name ? $name . 'Bundle' : '';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,17 @@ final class TemplateNameParserSpec extends ObjectBehavior
|
|||
$this->parse('@Acme/Nested/Directory/app.html.twig')->shouldBeLike(new TemplateReference('AcmeBundle', 'Nested/Directory', 'app', 'html', 'twig'));
|
||||
}
|
||||
|
||||
function it_generates_plugin_template_references_from_namespaced_paths(KernelInterface $kernel): void
|
||||
{
|
||||
$kernel->getBundle('AcmePlugin')->willReturn(null); // just do not throw an exception
|
||||
|
||||
$this->parse('@AcmePlugin/app.html.twig')->shouldBeLike(new TemplateReference('AcmePlugin', '', 'app', 'html', 'twig'));
|
||||
$this->parse('@AcmePlugin/Directory/app.html.twig')->shouldBeLike(new TemplateReference('AcmePlugin', 'Directory', 'app', 'html', 'twig'));
|
||||
$this->parse('@AcmePlugin/Directory.WithDot/app.html.twig')->shouldBeLike(new TemplateReference('AcmePlugin', 'Directory.WithDot', 'app', 'html', 'twig'));
|
||||
$this->parse('@AcmePlugin/Directory/app.with.dots.html.twig')->shouldBeLike(new TemplateReference('AcmePlugin', 'Directory', 'app.with.dots', 'html', 'twig'));
|
||||
$this->parse('@AcmePlugin/Nested/Directory/app.html.twig')->shouldBeLike(new TemplateReference('AcmePlugin', 'Nested/Directory', 'app', 'html', 'twig'));
|
||||
}
|
||||
|
||||
function it_delegates_custom_namespace_to_decorated_parser(
|
||||
KernelInterface $kernel,
|
||||
TemplateNameParserInterface $decoratedParser,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue