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
To override footer copyright text in magento2, you can use preference instead of plugin.
So your di.xml is looks like following.
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)
Why do you want to override a class just to change the text? Magento provides a feature to change the text of footer.
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.