Problem: What is this about?
This quick article comes from the series “Burn hours and hours of work just to find out the simple solution to all your suffering. And of course it’s not documented anywhere.” But first things first:
In Magento, it is common practice to customize a store’s appearance by implementing a theme. This involves modifying the structure of Magento’s core and third-party modules, such as altering templates, adjusting JavaScript logic, and more. This approach allows modifications to both the frontend
and adminhtml
areas of the store without directly altering the core files, ensuring compatibility with updates and version changes.
However, you might encounter a situation where your changes don’t take effect – no matter what you do. Such a environment may look like this:
app
└── design
└── adminhtml
└── <VENDOR>
└── <THEMENAME>
├── Magento_Backend
│ └── layout
│ └── default.xml
├── web
│ └── css
│ └── style.css
├── registration.php
└── theme.xml
With such files like these:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="css/style.css" type="text/css"/>
</head>
</page>
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::THEME,
"adminhtml/<VENDOR>/<THEMENAME>",
__DIR__
);
<?xml version="1.0"?>
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
<title>Your Theme Title</title>
<parent>Magento/backend</parent>
</theme>
One would now expect that the css/style.css
path would resolve to app/design/adminhtml/<VENDOR>/<THEMENAME>/web/css/style.css
but instead it directs to the magento2-base
directory as a failback. What gives?
Solution: Check your Theme Type
As for weird reasons, it may very well happen that your theme is of so called virtual type
which is by nature prohibited to override other modules. You can check your themes type in the database’s theme
table only and not in the adminhtml
area.
If this situation applies to you, take out the 1
flag and run these commands before testing again:
php bin/magento cache:clean
php bin/magento setup:upgrade
php bin/magento setup:di:compile
For further infomation about theme types refer to this StackExchange thread.