Reputation: 4205
I want to customize Magento\Theme\Block\Html\Footer 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="Magento\Theme\Block\Html\Footer">
<plugin name="footer-text-override" type="Hello\Test\Plugin\Footer" sortOrder="15" />
</type>
</config>
Footer.php
<?php
namespace Hello\Test\Plugin;
use Magento\Framework\View\Element\Template;
class Footer extends \Magento\Theme\Block\Html\Footer
{
public function getCopyright()
{
echo "Hello World!";
}
}
But it's not working.
Upvotes: 0
Views: 3262
Reputation: 407
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.
Upvotes: 2
Reputation: 201
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="Magento\Theme\Block\Html\Footer" type="Hello\Test\Plugin\Footer" />
</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)
Upvotes: 0