Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Introduces a new Twig TemplateResolver/TemplateLoader implementation and migrates legacy Yii2-adapter and CMS code to use it, aiming to centralize template path resolution and loader behavior in 6.x.
Changes:
- Added
CraftCms\Cms\Twig\TemplateResolver,TemplateLoader, andTemplateLoaderException, plus unit tests for both resolver and loader behavior. - Updated multiple legacy Yii2-adapter call sites to use
TemplateResolver(instead ofView::resolveTemplate()/doesTemplateExist()) and updated exception references. - Renamed/moved the Twig view engine integration (
TwigEngine) and updated service providers and exception mapping (TwigExceptionMapper).
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| yii2-adapter/tests/unit/helpers/CpHelperTest.php | Updates exception import to new TemplateLoaderException namespace. |
| yii2-adapter/legacy/web/twig/variables/Cp.php | Updates throws docblocks / imports for new Twig exception and event class usage. |
| yii2-adapter/legacy/web/twig/TemplateLoaderException.php | Deprecates legacy exception class via alias to new exception. |
| yii2-adapter/legacy/web/twig/TemplateLoader.php | Deprecates legacy loader class via alias (intended). |
| yii2-adapter/legacy/web/View.php | Switches template resolution/existence to TemplateResolver and updates Twig loader import. |
| yii2-adapter/legacy/web/UrlManager.php | Uses TemplateResolver to detect public template paths. |
| yii2-adapter/legacy/web/TemplateResponseFormatter.php | Uses TemplateResolver to resolve template path for MIME type detection. |
| yii2-adapter/legacy/validators/TemplateValidator.php | Uses TemplateResolver to validate template existence. |
| yii2-adapter/legacy/services/Categories.php | Uses TemplateResolver for category group template validation. |
| yii2-adapter/legacy/helpers/Template.php | Renames mapper reference to TwigExceptionMapper. |
| yii2-adapter/legacy/helpers/Cp.php | Updates exception type references to new TemplateLoaderException. |
| yii2-adapter/legacy/controllers/TemplatesController.php | Uses TemplateResolver for template existence checks (render/offline/error). |
| tests/Unit/Twig/TemplateResolverTest.php | Adds coverage for resolver normalization, roots, modes, caching, and security checks. |
| tests/Unit/Twig/TemplateLoaderTest.php | Adds coverage for loader interface methods, error cases, and freshness logic. |
| src/View/ViewServiceProvider.php | Registers Twig view engine via TwigEngine. |
| src/View/TwigEngine.php | Moves/renames Twig engine integration class into CraftCms\Cms\View. |
| src/Twig/TwigServiceProvider.php | Updates exception handler mapping to TwigExceptionMapper. |
| src/Twig/TwigExceptionMapper.php | Renames TwigMapper to TwigExceptionMapper. |
| src/Twig/TemplateResolver.php | Adds new request-scoped template resolution service. |
| src/Twig/TemplateLoader.php | Adds new Twig loader implementation backed by TemplateResolver. |
| src/Twig/Exceptions/TemplateLoaderException.php | Adds new exception type that carries a template name. |
| src/Http/Controllers/Users/PhotoController.php | Uses TemplateResolver for template existence check. |
| src/Element/Concerns/Renderable.php | Uses TemplateResolver for site template existence checks. |
| src/Deprecator/Deprecator.php | Uses TemplateResolver to resolve Twig template names to paths. |
| src/Console/Commands/Twig/TwigCacheCommand.php | Updates exception import to new TemplateLoaderException. |
Comments suppressed due to low confidence (1)
yii2-adapter/legacy/web/twig/TemplateLoader.php:20
class_alias()is aliasing\CraftCms\Cms\Twig\Exceptions\TemplateLoaderExceptiontoTemplateLoader, which will makecraft\web\twig\TemplateLoaderpoint to an exception class at runtime. This should alias the new loader class (e.g.\CraftCms\Cms\Twig\TemplateLoader) instead; otherwise any code referencing/instantiatingTemplateLoaderwill break immediately.
class_alias(\CraftCms\Cms\Twig\Exceptions\TemplateLoaderException::class, TemplateLoader::class);
💡 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.