Skip to content

feat(template): copy whole template directory with template:override - #275

Open
dermatz wants to merge 5 commits into
mainfrom
feature/245-override-whole-template-directory
Open

dermatz wants to merge 5 commits into
mainfrom
feature/245-override-whole-template-directory

Conversation

@dermatz

@dermatz dermatz commented Nov 6, 2026

Copy link
Copy Markdown
Member

Summary

mageforge:template:override now accepts a directory path and copies all files inside it (including subdirectories) into the theme.

bin/magento mageforge:template:override vendor/magepal/magento2-google-analytics4/view/frontend/templates -t Vendor/theme

Closes #245

Behaviour

  • Directory paths into a module's view/<area>/templates|email|web|layout (or a subdirectory), a Hyvä compat module or another theme's override directory are supported.
  • Each file is resolved through Magento's fallback chain (first match wins), so the copied files are the ones currently in use. Hyvä overrides still land in the original module's directory.
  • Already overridden files are skipped; --force replaces them with the next file in the chain.
  • --dry-run lists source → target for every file without copying.
  • After copying, every file is verified to resolve to the new override and the caches are cleaned.

Changes

  • TemplateReference: new isDirectory flag
  • TemplatePathParser: accepts directories
  • TemplateFallbackResolver::findDirectoryFiles(): merges files across fallback directories
  • OverrideCommand: directory flow
  • Docs and unit tests updated

Testing

  • phpunit tests/Unit: 751 tests pass
  • phpcs clean on changed files
  • Not yet tried manually against a Magento install (ddev magento m:t:o <dir> -t <theme>)

Closes #245

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 6, 2026 13:51
@github-actions github-actions Bot added documentation Improvements or additions to documentation Feature Command labels Nov 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Active issues cause incorrect discovery and skipped counts for theme-owned files without --force, and TypeErrors for numeric extensionless filenames at both resolver calls.

2 open issues
What changed in this PR

Extends mageforge:template:override to copy directories recursively into a theme, addressing #245 while using the existing Magento fallback and Hyvä compatibility handling.

Changes:

  • Adds directory references and parsing for module and theme view paths.
  • Merges files across fallback locations and adds bulk copying with skip, force, dry-run, verification and cache-cleaning behaviour.
  • Updates command documentation and unit tests.
File Description
tests/​Unit/​Service/​TemplateOverride/​TemplatePathParserTest.php Tests directory parsing and invalid paths.
tests/​Unit/​Service/​TemplateOverride/​TemplateFallbackResolverTest.php Tests recursive merging and fallback precedence.
tests/​Unit/​Console/​Command/​Template/​OverrideCommandTest.php Tests directory copying, skipping and dry runs.
src/​Service/​TemplateOverride/​TemplatePathParser.php Parses module and theme directories, including compat mappings.
src/​Service/​TemplateOverride/​TemplateFallbackResolver.php Collects files recursively across fallback directories.
src/​Model/​TemplateReference.php Adds a directory flag to template references.
src/​Console/​Command/​Template/​OverrideCommand.php Implements the directory override flow and usage help.
docs/​commands_reference.md Documents directory inputs and replacement behaviour.

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 6, 2026 14:10
@dermatz dermatz changed the title ✨ feat(template): copy whole template directory with template:override feat(template): copy whole template directory with template:override Nov 6, 2026
…ric file names

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Non-forced directory overrides incorrectly fail when templates exist only in the target theme because discovery excludes that directory instead of successfully skipping existing overrides.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 6, 2026 14:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because the new directory-mode tests do not exercise --force, leaving overwrite source selection, theme-only file preservation, and cache cleaning unverified on that path.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 6, 2026 14:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The directory-mode --force path lacks regression coverage for fallback-source replacement, preservation of theme-only files, and cache cleaning after replacements.

1 open issue

Review effort: Balanced

foreach ($sources as $relativePath => $sourceFile) {
// Numeric file names become integer array keys
$relativePath = (string) $relativePath;
if (isset($overridden[$relativePath]) && !$isForce) {
…asts

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 6, 2026 14:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because a copy failure can leave a directory override partially applied with stale caches and no clear report of which files changed.

1 open issue

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Command documentation Improvements or additions to documentation Feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature-Request: Copy whole Template-Folder to theme

2 participants