Pregunta

After creating my custom storefront theme, I am now trying to modify the default magento admin logo with custom theme(the logo in the login admin portal and the Magento icon at the top left of the admin menu). Below are the steps followed.

Custom Theme Logo uploaded at

app/design/adminhtml/[VendorName]/[Themename]/web/images/logo.png

app/design/adminhtml/[VendorName]/[Themename]/registration.php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::THEME,
    'adminhtml/[VendorName]/[Themename]',
    __DIR__
);

app/design/adminhtml/[VendorName]/[Themename]/theme.xml

<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
    <title>Custom Theme Title</title>
    <parent>Magento/backend</parent>
</theme>

app/design/adminhtml/[VendorName]/[Themename]/Magento_Backend/layout/admin_login.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-login" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="styles" />
    <body>
        <referenceBlock name="logo">
            <arguments>
                <argument name="logo_image_src" xsi:type="string">images/logo.png</argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

app/design/adminhtml/[VendorName]/[Themename]/Magento_Backend/layout/default.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="header">
            <referenceBlock name="logo">
                <arguments>
                    <argument name="logo_image_src" xsi:type="string">images/logo.png</argument>
                    <argument name="logo_img_width" xsi:type="string">auto</argument>
                    <argument name="logo_img_height" xsi:type="string">auto</argument>
                    <argument name="show_part" xsi:type="string">logo</argument>
                    <argument name="edition" translate="true" xsi:type="string">Community Edition</argument>
                </arguments>
            </referenceBlock>
        </referenceContainer>
    </body>
</page>

Create new custom module to apply Admin Theme

app/code/[VendorName]/[ModuleName]/registration.php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    '[VendorName]_[ModuleName]',
    __DIR__
);

app/code/[VendorName]/[ModuleName]/etc/module.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="[VendorName]_[ModuleName]" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Theme"/>
        </sequence>
    </module>
</config>

app/code/[VendorName]/[ModuleName]/etc/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Theme\Model\View\Design">
        <arguments>
            <argument name="themes" xsi:type="array">
                <item name="adminhtml" xsi:type="string">[VendorName]/[Themename]</item>
            </argument>
        </arguments>
    </type>
</config>

CLI Commands executed

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:flush

New DB entry for backend theme and custom module is also seen in theme and setup_module table respectively.

How do I reflect admin theme changes ? Magento ver - 2.2.2

¿Fue útil?

Solución

Create new module to apply an admin theme:

  1. app/code/[VendorName]/[ModuleName]/registration.php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    '[VendorName]_[ModuleName]',
    __DIR__
);
  1. app/code/[VendorName]/[ModuleName]/etc/module.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="[VendorName]_[ModuleName]" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Theme"/>
        </sequence>
    </module>
</config>
  1. app/code/[VendorName]/[ModuleName]/etc/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Theme\Model\View\Design">
        <arguments>
            <argument name="themes" xsi:type="array">
                <item name="adminhtml" xsi:type="string">[VendorName]/[themename]</item>
            </argument>
        </arguments>
    </type>
</config>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top