I am working a Magento2 project and I have installed a third party module magefan/module-blog which is used for manage Blog/post.This module is installed in Magento Vendor folder.
path is magento/vendor/magefun/module-blog .
I have a custom requirement and some changes/updated in block files.Since module is exist in Magento vendor folder so we can't directly changed in this module.Hence we require to override file
/var/www/html/magento2/vendor/magefan/module-blog/Block/Category/view.php
in
/var/www/html/magento2/app/code
folder.I don't have idea how to override particular that file.
if anyone know about it.Please help me.
-
have you create any module for override this file?Rakesh Jesadiya– Rakesh Jesadiya2018年01月19日 06:15:59 +00:00Commented Jan 19, 2018 at 6:15
-
Create a new module and then use preference or Plugin to override it.Khoa Truong– Khoa Truong2018年01月19日 06:16:40 +00:00Commented Jan 19, 2018 at 6:16
-
Follow this inststruction magenticians.com/magento-2-override-blockNavin Bhudiya– Navin Bhudiya2018年01月19日 06:18:11 +00:00Commented Jan 19, 2018 at 6:18
-
@RakeshJesadiya,still I have not created any module.Do we require to create module or can do any other way?akgola– akgola2018年01月19日 06:21:09 +00:00Commented Jan 19, 2018 at 6:21
-
yes you must create moduleRakesh Jesadiya– Rakesh Jesadiya2018年01月19日 06:21:42 +00:00Commented Jan 19, 2018 at 6:21
1 Answer 1
Following step need to follow
create app/code/Vendor/ModuleName/registration.php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Vendor_ModuleName',
__DIR__
);
create app/code/Vendor/ModuleName/etc/module.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_ModuleName" setup_version="1.0.0" />
</config>
create app/code/Vendor/ModuleName/etc/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="ThirdPartyVendor\ThirdpartyModule\Block\File" type="Vendor\ModuleName\Block\File"/>
</config>
create app/code/Vendor/ModuleName/Block/File.php
namespace Vendor\ModuleName\Block;
use ThirdPartyVendor\ThirdpartyModule\Block\File as ThirdPartyFile;
class File extends ThirdPartyFile
{
...........
...........
}
Run Following Command:
bin/magento setup:di:compile
bin/magento c:f
-
The
forattribute inpreferencetab will not accept.php. You should just useThirdPartyVendor\ThirdpartyModule\Block\FileAbsarAkram– AbsarAkram2020年11月17日 10:13:49 +00:00Commented Nov 17, 2020 at 10:13