skip to Main Content

I want to customize MagentoThemeBlockHtmlFooter class using custom module.

Output: Hello World!

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">
    <type name="MagentoThemeBlockHtmlFooter">
        <plugin name="footer-text-override" type="HelloTestPluginFooter" sortOrder="15" />
    </type>
</config>

Footer.php

<?php

namespace HelloTestPlugin;

use MagentoFrameworkViewElementTemplate;

class Footer extends MagentoThemeBlockHtmlFooter
{
    public function getCopyright()
    {
        echo "Hello World!";
    }
}

But it’s not working.

2

Answers


  1. To override footer copyright text in magento2, you can use preference instead of plugin.

    So your di.xml is looks like following.

    <?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="MagentoThemeBlockHtmlFooter" type="HelloTestPluginFooter" />
    </config>
    

    Preference is used for overriding class. It is similar to class rewrites in magento1.

    Plugin allow us to execute our code before, after and around any public methods from the class. (http://devdocs.magento.com/guides/v2.0/extension-dev-guide/plugins.html)

    Login or Signup to reply.
  2. Why do you want to override a class just to change the text? Magento provides a feature to change the text of footer.

    Go to: Admin > Content > Design > Configuration

    Click on edit action of the store view. Now, scroll down the page and there is footer section, expand it and enter the text of you with in Copyright field.

    Save it and flush the cache.

    enter image description here

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search