6

Does anyone know how to override the below template?

vendor\magento\module-backend\view\adminhtml\templates\media\uploader.phtml.

1 Answer 1

10

[EDIT] Override block - recommended way.

Override Block:

Create a new module.

app/code/Vendor/Backend/etc/adminhtml/di.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Backend\Block\Media\Uploader" type="Vendor\Backend\Block\Media\Uploader" />
</config>

app/code/Vendor/Backend/Block/Media/Uploader.php

<?php

namespace Vendor\Backend\Block\Media;

class Uploader extends \Magento\Backend\Block\Media\Uploader
{
    protected $_template = 'Vendor_Backend::media/uploader.phtml';
}

Create a new Admin theme:

In this case, may we need to create new Admin theme:

Remember to specify the custom Admin theme in di.xml.

For example:

enter image description here

a) Create an admin theme first:

app/design/adminhtml/Vendor/CustomTheme/registration.php

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::THEME,
    'adminhtml/Vendor/CustomTheme',
    __DIR__
);

app/design/adminhtml/Vendor/CustomTheme/theme.xml

<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
    <title>My custom Admin theme</title> <!-- your theme's name -->
    <parent>Magento/backend</parent> <!-- the parent theme. Example: Magento/backend -->
</theme>

b) Apply theme admin:

app/code/Vendor/Theme/etc/module.xml

<?xml version="1.0"?>

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

app/code/Vendor/Theme/registration.php

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Vendor_Theme',
    __DIR__
);

app/code/Vendor/Theme/etc/adminhtml/di.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <!-- Admin theme. Start -->
    <type name="Magento\Theme\Model\View\Design">
        <arguments>
            <argument name="themes" xsi:type="array">
                <item name="adminhtml" xsi:type="string">Vendor/CustomTheme</item>
            </argument>
        </arguments>
    </type>
    <!-- Admin theme. End -->
</config>
11
  • @Magento2Devloper The doc said that. Jul 11, 2017 at 15:24
  • ok. got it ..removed comment. thanx.any idea about it magento.stackexchange.com/questions/183137/… Jul 11, 2017 at 15:27
  • there it not another option much easyer? Jul 12, 2017 at 7:21
  • We should try to override the block class: Magento\Backend\Block\Media\Uploader. Set the new template. Jul 12, 2017 at 7:26
  • Hi. after i change my backned theme like you said, i don't have any css or sj on my backend. i checked for in pub for the theme folder, but it's not there. Even i run the deploy commands, the file in pub for my new theme is not created Jul 12, 2017 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.