I try to override this file :


I create a module.xml, registration.php and di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
     <preference for="Magento\Framework\View\Element\Html\Link\Current" type="MyNamespace\MagentoFramework\Model\Framework\View\Element\Html\Link\Current" />

My override class :

namespace MyNamespace\MagentoFramework\Model\Framework\View\Element\Html\Link;

    class Current extends \Magento\Framework\View\Element\Html\Link\Current
         * Get href URL
         * @return string
        public function getHref()
            return $this->getUrl($this->getPath());

The module is enable but this file doesn't override the original.

Do you have any suggestions ? Thanks !

  • Why you overwrite the whole class? – Sohel Rana Apr 12 '19 at 12:25
  • I need to override getHref() and _toHtml() method of Current class. this is not the way to go? – Fbr Apr 12 '19 at 12:27

You can refer the link How to Override Framework Class in Magento 2

They are following the same folder structure in custom namespace or module section.

You can try the same logic without introducing additional folders [model/framework]


You can implement plugin to overwrite the function.


<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<type name="Magento\Framework\View\Element\Html\Link\Current">
    <plugin name="customermgmt_index_plugin" type="Devi\Customview\Plugin\Current" sortOrder="10" disabled="false"  />

Current.php ( Plugin File )

namespace Devi\Customview\Plugin;

class Current

  public function afterGetHref()
    echo 'plugin working';


Please check and let me know whether its solving your needs.

|improve this answer|||||
  • Thanks for your answer. I removed the model/framework folders but it still does not work. Do I need to run specific commands ? – Fbr Apr 12 '19 at 12:44
  • you can delete the files inside generated folder and clean your cache and try again – Thamo Apr 12 '19 at 12:46
  • Unfortunately it still does not work... – Fbr Apr 12 '19 at 12:51
  • you can use the plugin to overwrite the specific function. I have updated the answer with code also. – Thamo Apr 12 '19 at 13:31
  • Plugin solution works, but not for protected method like _toHtml() – Fbr Apr 23 '19 at 13:33

In your etc/module sequence you should put the Magento_Framework

To make sure you have the right order of module dependencies.


<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
     <preference for="Magento\Framework\View\Element\Html\Link\Current" type="MyNamespace\MagentoFramework\View\Element\Html\Link\Current" />

Note: Make sure to put the Current.php inside View\Element\Html\Link directory

|improve this answer|||||
  • In the file app/code/MyNamespace/MagentoFramework/etc/module.xml <?xml version="1.0" encoding="UTF-8"?> <config xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="MyNamespace_MagentoFramework" setup_version="0.0.1"> </module> </config> – Fbr Apr 12 '19 at 13:21
  • yes in that file you do sequence – fmsthird Apr 12 '19 at 13:22
  • What do you mean by "sequence" ? Something is missing in this file ? – Fbr Apr 12 '19 at 13:24
  • check updated answer . it should be like that in your module.xml – fmsthird Apr 12 '19 at 13:25
  • 1
    Comments are not for extended discussion; this conversation has been moved to chat. – Amit Bera Apr 13 '19 at 5:08

After following this article How to Override Framework Class in Magento 2, The override works for this file :


but not for this file :


Do you know if this file can not be overridden ?

|improve this answer|||||

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.