Skip to content

Extend Shopware's TwigEnvironment in TwigDecorator - #86

Merged
shyim merged 1 commit into
FriendsOfShopware:mainfrom
iMi-digital:fix-twig-decorator-shopware-environment
Sep 15, 2026
Merged

shyim merged 1 commit into
FriendsOfShopware:mainfrom
iMi-digital:fix-twig-decorator-shopware-environment

Conversation

@amenk

@amenk amenk commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

CustomProfilerExtensions replaces the class of the twig service with TwigDecorator. Shopware sets that service's class to Shopware\Core\Framework\Adapter\Twig\TwigEnvironment, so extending plain Twig\Environment silently drops Shopware's own Twig behaviour -- use_yield, the CoreExtension and EscaperRuntime overrides in compile(), and ResetInterface.

Since Shopware 6.7.14.0 it also breaks the shop. The new DocumentV2 subsystem type-hints the concrete TwigEnvironment:

Shopware\Core\Checkout\DocumentV2\Template\DocumentTemplateRenderer::__construct():
Argument #2 ($twig) must be of type
Shopware\Core\Framework\Adapter\Twig\TwigEnvironment,
Frosh\DevelopmentHelper\Component\Profiler\TwigDecorator given

GenerateDocumentAction now receives both DocumentGenerator and DocumentV2Generator, and FlowExecutor instantiates flow actions eagerly, so the renderer is constructed on any flow dispatch. A plain POST /api/customer answers 500 with the plugin installed, which takes down acceptance tests across the board.

TwigEnvironment extends Twig\Environment, and it exists in both 6.6 and 6.7, so this stays within the plugin's ~6.6.0 || ~6.7.0 requirement.

CustomProfilerExtensions replaces the class of the `twig` service with
TwigDecorator. Shopware sets that service's class to
Shopware\Core\Framework\Adapter\Twig\TwigEnvironment, so extending plain
Twig\Environment silently drops Shopware's own Twig behaviour -- `use_yield`,
the CoreExtension and EscaperRuntime overrides in compile(), and ResetInterface.

Since Shopware 6.7.14.0 it also breaks the shop. The new DocumentV2 subsystem
type-hints the concrete TwigEnvironment:

    Shopware\Core\Checkout\DocumentV2\Template\DocumentTemplateRenderer::__construct():
    Argument FriendsOfShopware#2 ($twig) must be of type
    Shopware\Core\Framework\Adapter\Twig\TwigEnvironment,
    Frosh\DevelopmentHelper\Component\Profiler\TwigDecorator given

GenerateDocumentAction now receives both DocumentGenerator and
DocumentV2Generator, and FlowExecutor instantiates flow actions eagerly, so the
renderer is constructed on any flow dispatch. A plain POST /api/customer
answers 500 with the plugin installed, which takes down acceptance tests across
the board.

TwigEnvironment extends Twig\Environment, and it exists in both 6.6 and 6.7, so
this stays within the plugin's `~6.6.0 || ~6.7.0` requirement.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@shyim
shyim merged commit 6271e01 into FriendsOfShopware:main Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants