I want to adjust the header menu. It works a bit by editing topmenu.phtml, at least for the $outermostClass to add some classes but I think $childrenWrapClass has an error since in function _addSubMenu in topmenu.php it does not use the var.
Though anyway, I would need more than adding a class to submenus. I would need to make the links look like
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
So I would need to edit topmenu.php in any way.
How to edit the topmenu.php? It is located originally in module-theme/Block/Html/Topmenu.php
Can I place it in my theme directory somewhere simply?
Someone mentioned I would need to create a module for it. Does that mean creating a directory on the same level of Magento_Theme in my theme directory? If so then how to name that directory and where to place my topmenu.php in order to use this instead the original one?
Thank you!
Best Answer
You have to create module for changes in Topmenu.php file,
File path is :
app/code
Create module name
Package/Topmenu/registration.php
,Package/Topmenu/etc/module.xml
,Create
di.xml
file for override topmenu file,filepath is
Package/Topmenu/etc/di.xml
,Create block for override topmenu file function,
Package/Topmenu/Block/Topmenu.php
,Run command ,
php bin/magento setup:upgrade
Clear cache and check now its overrider core block.