Merged
Conversation
There was a problem hiding this comment.
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+TwigCreatedevent 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.