background

September 29, 2023

A Magento 2 ThemeOverrideChecker

Yireo Blog Post

Upgrading Magento themes can be horrible at times, especially when overrides were added too easily in the past. To lighten the workload, I have created a Yireo_ThemeOverrideChecker CLI that helps you judge the nature of those overrides.

Detecting overrides

There are already other tools out there, like the ampersand-magento2-upgrade-patch-helper, that allow you to analyse the health of your Magento instance, by detecting the number of overrides. This is helpful, but it still requires you to do the analysis. For instance, in the Ampersand helper, PHTML template overrides are reported. But there is no analysis whether that's being good or bad.

Say that a PHTML template is copied from the parent to the child, but nothing is modified - it's just a stupid file copy. This should trigger an error - the override is not needed. Or when the number of lines in the PHTML template being different is minimal? This should trigger a warning - somebody needs to inspect the file and try to get rid of the override.

Analysing the impact of those overrides

This is where the Yireo_ThemeOverrideChecker comes in. It offers a command yireo:theme-overrides:check that lists all files in a given theme and then shows additional advice for them: Is it just a file that needs to be there (like a license, theme.xml or composer.json)? Or is it an override (XML, PHTML, JS, CSS, image) that requires further inspection?

To judge whether an existing override makes sense, the module adds logic that is still kind of hard to battle with: It compares the number of lines to see if there is anything up. It also compares the number of lines that are actually different. And it tries to work with diff-based logic. It still feels a bit fuzzy all-in-all, but the main point is that the report already makes an analysis, so that you - as a developer tasked to upgrade a theme - have less to do.

Additional command bin/magento yireo:theme-overrides:show and bin/magento yireo:theme-overrides:diff allow you to zoom into a specific file to check upon its details.

Try it out: yireo/Yireo_ThemeOverrideChecker

Posted on September 29, 2023

About the author

Author Jisse Reitsma

Jisse Reitsma is the founder of Yireo, extension developer, developer trainer and 3x Magento Master. His passion is for technology and open source. And he loves talking as well.

Sponsor Yireo

Looking for a training in-house?

Let's get to it!

We don't write too commercial stuff, we focus on the technology (which we love) and we regularly come up with innovative solutions. Via our newsletter, you can keep yourself up to date on all of this coolness. Subscribing only takes seconds.

Do not miss out on what we say

This will be the most interesting spam you have ever read

We don't write too commercial stuff, we focus on the technology (which we love) and we regularly come up with innovative solutions. Via our newsletter, you can keep yourself up to date on all of this coolness. Subscribing only takes seconds.