Skip to content

[6.x] Twig factory/service#18440

Merged
brandonkelly merged 3 commits into6.xfrom
feature/twig-environment-factory
Feb 17, 2026
Merged

[6.x] Twig factory/service#18440
brandonkelly merged 3 commits into6.xfrom
feature/twig-environment-factory

Conversation

@riasvdv
Copy link
Contributor

@riasvdv riasvdv commented Feb 17, 2026

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new request-scoped CraftCms\Cms\Twig\Twig service to centralize Twig environment creation/caching and begins migrating legacy Yii2 adapter code to use it, with compatibility shims and deprecations for the old APIs.

Changes:

  • Added CraftCms\Cms\Twig\Twig (scoped) to manage Cp/Site Twig environments, extension registration, and option caching.
  • Added new CraftCms\Cms\Twig\Environment + TwigCreated event and bridged the legacy Yii event (View::EVENT_AFTER_CREATE_TWIG) to the new Laravel event.
  • Deprecated/aliased legacy Twig environment + updated imports/usages, plus added unit tests for the new service.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
yii2-adapter/legacy/web/twig/Environment.php Replaced legacy implementation with a deprecated alias to the new environment class.
yii2-adapter/legacy/web/View.php Routed Twig environment lifecycle/extension registration through the new Twig service; added event bridge to legacy Yii event.
yii2-adapter/legacy/events/CreateTwigEvent.php Updated event typing to the new Twig environment class.
src/Twig/Twig.php New scoped service that creates/caches Twig environments and manages extension registration/options.
src/Twig/Environment.php New Twig environment subclass with default escaper strategy and compile profiling via debugbar.
src/Twig/Events/TwigCreated.php New Laravel event dispatched when a Twig environment is created.
src/helpers.php Added a namespaced debugbar() helper used by Twig compilation profiling.
src/FieldLayout/LayoutElements/Template.php Updated Twig environment import to the new class.
tests/Unit/Twig/TwigTest.php Added unit coverage for the new Twig service behavior.
CHANGELOG-WIP.md Documented new service/classes/events and related deprecations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@riasvdv riasvdv marked this pull request as ready for review February 17, 2026 13:14
@riasvdv riasvdv requested a review from brandonkelly February 17, 2026 13:14
Base automatically changed from feature/twig-template-resolver to 6.x February 17, 2026 14:05
@brandonkelly brandonkelly merged commit c3d4608 into 6.x Feb 17, 2026
12 checks passed
@brandonkelly brandonkelly deleted the feature/twig-environment-factory branch February 17, 2026 14:05
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