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
    Commented Apr 12, 2019 at 12:25
  • I need to override getHref() and _toHtml() method of Current class. this is not the way to go?
    – Fbr
    Commented Apr 12, 2019 at 12:27

4 Answers 4


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.

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

  • 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
    Commented Apr 12, 2019 at 13:21
  • yes in that file you do sequence
    – fmsthird
    Commented Apr 12, 2019 at 13:22
  • What do you mean by "sequence" ? Something is missing in this file ?
    – Fbr
    Commented Apr 12, 2019 at 13:24
  • check updated answer . it should be like that in your module.xml
    – fmsthird
    Commented Apr 12, 2019 at 13:25
  • 1
    Comments are not for extended discussion; this conversation has been moved to chat.
    – Amit Bera
    Commented Apr 13, 2019 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 ?


We can override using preference.

  • Create di.xml

  • Create class php file

     <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     <preference for="vendor\magento\framework\File\Uploader" type="NameSpace\Customer\Framework\File\Uploader" />
  • In the given path put your fle NameSpace\Customer\Framework\File\Uploader

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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