magento2.2 override topmenu.php: _addSubMenu()Override topmenuCould not create an acl object: Invalid XML in fileAbout I/O Usage in magento2.2Create observer for Magento2.2Problem with block override in Magento 2Magento2.2 refused to apply stylesheetUnable to create/visualize productsHow to override tax Block In magento2Cannot add custom topmenu link with pluginGoogleAnalytics Block Override

How to terminate ping <dest> &

Maths symbols and unicode-math input inside siunitx commands

Deletion of copy-ctor & copy-assignment - public, private or protected?

When did antialiasing start being available?

Comment Box for Substitution Method of Integrals

Do US professors/group leaders only get a salary, but no group budget?

What is the term when voters “dishonestly” choose something that they do not want to choose?

Should I be concerned about student access to a test bank?

Do I need to be arrogant to get ahead?

Probably overheated black color SMD pads

Is there a term for accumulated dirt on the outside of your hands and feet?

How does 取材で訪れた integrate into this sentence?

How to define limit operations in general topological spaces? Are nets able to do this?

How is the partial sum of a geometric sequence calculated?

Does .bashrc contain syntax errors?

What can I do if I am asked to learn different programming languages very frequently?

Could Sinn Fein swing any Brexit vote in Parliament?

Is honey really a supersaturated solution? Does heating to un-crystalize redissolve it or melt it?

In Aliens, how many people were on LV-426 before the Marines arrived​?

Asserting that Atheism and Theism are both faith based positions

두음법칙 - When did North and South diverge in pronunciation of initial ㄹ?

Suggestions on how to spend Shaabath (constructively) alone

Why didn't Héctor fade away after this character died in the movie Coco?

How to generate binary array whose elements with values 1 are randomly drawn



magento2.2 override topmenu.php: _addSubMenu()


Override topmenuCould not create an acl object: Invalid XML in fileAbout I/O Usage in magento2.2Create observer for Magento2.2Problem with block override in Magento 2Magento2.2 refused to apply stylesheetUnable to create/visualize productsHow to override tax Block In magento2Cannot add custom topmenu link with pluginGoogleAnalytics Block Override













1















I am trying to override the Topmenu Module Block but I can not understand why it fails.
I am trying to override the following method:




magento/module-theme/Block/Html/Topmenu.php:_addSubMenu(...)




I have created the following folders/files:
app/code/Custom/Theme/Block/Html/Topmenu.php (If it works, "lala" should be appeared at the menu):



Topmenu.php
<?php

namespace CustomThemeBlockHtml;

class Topmenu extends MagentoThemeBlockHtmlTopmenu

protected function _addSubMenu($child, $childLevel, $childrenWrapClass, $limit)

$html = '';
if (!$child->hasChildren())
return $html;


$colStops = null;
if ($childLevel == 0 && $limit)
$colStops = $this->_columnBrake($child->getChildren(), $limit);


$html .= '<ul class="level' . $childLevel . ' ' . $childrenWrapClass . '">';
$html .= $this->_getHtml($child, $childrenWrapClass, $limit, $colStops);
$html .= '<li>lala</li></ul>';

return $html;


protected function _toHtml()

$this->setModuleName($this->extractModuleName('MagentoThemeBlockHtmlTopmenu'));
return parent::_toHtml();





app/code/Custom/Theme/etc/ has two files:



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">
<preference for="MagentoThemeBlockHtmlTopmenu" type="CustomThemeBlockHtmlTopmenu" />
</config>

module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Custom_Theme" setup_version="0.0.1" />
</config>


And the registration.php



<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Custom_Theme',
__DIR__
);


Is this approach correct? What do I miss?










share|improve this question














bumped to the homepage by Community 29 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.










  • 1





    Did you ever get this working?

    – Stephen Dance
    May 18 '18 at 15:43











  • Did you? I'm working on this right now. Would love to know.

    – JustinP
    Nov 8 '18 at 2:01











  • @JustinP Anyone manage to get this working can you share?

    – Juliano Vargas
    Jan 15 at 14:20















1















I am trying to override the Topmenu Module Block but I can not understand why it fails.
I am trying to override the following method:




magento/module-theme/Block/Html/Topmenu.php:_addSubMenu(...)




I have created the following folders/files:
app/code/Custom/Theme/Block/Html/Topmenu.php (If it works, "lala" should be appeared at the menu):



Topmenu.php
<?php

namespace CustomThemeBlockHtml;

class Topmenu extends MagentoThemeBlockHtmlTopmenu

protected function _addSubMenu($child, $childLevel, $childrenWrapClass, $limit)

$html = '';
if (!$child->hasChildren())
return $html;


$colStops = null;
if ($childLevel == 0 && $limit)
$colStops = $this->_columnBrake($child->getChildren(), $limit);


$html .= '<ul class="level' . $childLevel . ' ' . $childrenWrapClass . '">';
$html .= $this->_getHtml($child, $childrenWrapClass, $limit, $colStops);
$html .= '<li>lala</li></ul>';

return $html;


protected function _toHtml()

$this->setModuleName($this->extractModuleName('MagentoThemeBlockHtmlTopmenu'));
return parent::_toHtml();





app/code/Custom/Theme/etc/ has two files:



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">
<preference for="MagentoThemeBlockHtmlTopmenu" type="CustomThemeBlockHtmlTopmenu" />
</config>

module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Custom_Theme" setup_version="0.0.1" />
</config>


And the registration.php



<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Custom_Theme',
__DIR__
);


Is this approach correct? What do I miss?










share|improve this question














bumped to the homepage by Community 29 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.










  • 1





    Did you ever get this working?

    – Stephen Dance
    May 18 '18 at 15:43











  • Did you? I'm working on this right now. Would love to know.

    – JustinP
    Nov 8 '18 at 2:01











  • @JustinP Anyone manage to get this working can you share?

    – Juliano Vargas
    Jan 15 at 14:20













1












1








1








I am trying to override the Topmenu Module Block but I can not understand why it fails.
I am trying to override the following method:




magento/module-theme/Block/Html/Topmenu.php:_addSubMenu(...)




I have created the following folders/files:
app/code/Custom/Theme/Block/Html/Topmenu.php (If it works, "lala" should be appeared at the menu):



Topmenu.php
<?php

namespace CustomThemeBlockHtml;

class Topmenu extends MagentoThemeBlockHtmlTopmenu

protected function _addSubMenu($child, $childLevel, $childrenWrapClass, $limit)

$html = '';
if (!$child->hasChildren())
return $html;


$colStops = null;
if ($childLevel == 0 && $limit)
$colStops = $this->_columnBrake($child->getChildren(), $limit);


$html .= '<ul class="level' . $childLevel . ' ' . $childrenWrapClass . '">';
$html .= $this->_getHtml($child, $childrenWrapClass, $limit, $colStops);
$html .= '<li>lala</li></ul>';

return $html;


protected function _toHtml()

$this->setModuleName($this->extractModuleName('MagentoThemeBlockHtmlTopmenu'));
return parent::_toHtml();





app/code/Custom/Theme/etc/ has two files:



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">
<preference for="MagentoThemeBlockHtmlTopmenu" type="CustomThemeBlockHtmlTopmenu" />
</config>

module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Custom_Theme" setup_version="0.0.1" />
</config>


And the registration.php



<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Custom_Theme',
__DIR__
);


Is this approach correct? What do I miss?










share|improve this question














I am trying to override the Topmenu Module Block but I can not understand why it fails.
I am trying to override the following method:




magento/module-theme/Block/Html/Topmenu.php:_addSubMenu(...)




I have created the following folders/files:
app/code/Custom/Theme/Block/Html/Topmenu.php (If it works, "lala" should be appeared at the menu):



Topmenu.php
<?php

namespace CustomThemeBlockHtml;

class Topmenu extends MagentoThemeBlockHtmlTopmenu

protected function _addSubMenu($child, $childLevel, $childrenWrapClass, $limit)

$html = '';
if (!$child->hasChildren())
return $html;


$colStops = null;
if ($childLevel == 0 && $limit)
$colStops = $this->_columnBrake($child->getChildren(), $limit);


$html .= '<ul class="level' . $childLevel . ' ' . $childrenWrapClass . '">';
$html .= $this->_getHtml($child, $childrenWrapClass, $limit, $colStops);
$html .= '<li>lala</li></ul>';

return $html;


protected function _toHtml()

$this->setModuleName($this->extractModuleName('MagentoThemeBlockHtmlTopmenu'));
return parent::_toHtml();





app/code/Custom/Theme/etc/ has two files:



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">
<preference for="MagentoThemeBlockHtmlTopmenu" type="CustomThemeBlockHtmlTopmenu" />
</config>

module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Custom_Theme" setup_version="0.0.1" />
</config>


And the registration.php



<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Custom_Theme',
__DIR__
);


Is this approach correct? What do I miss?







magento2.2 topmenu override-block






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 21 '17 at 23:01









user2447482user2447482

61




61





bumped to the homepage by Community 29 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 29 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.









  • 1





    Did you ever get this working?

    – Stephen Dance
    May 18 '18 at 15:43











  • Did you? I'm working on this right now. Would love to know.

    – JustinP
    Nov 8 '18 at 2:01











  • @JustinP Anyone manage to get this working can you share?

    – Juliano Vargas
    Jan 15 at 14:20












  • 1





    Did you ever get this working?

    – Stephen Dance
    May 18 '18 at 15:43











  • Did you? I'm working on this right now. Would love to know.

    – JustinP
    Nov 8 '18 at 2:01











  • @JustinP Anyone manage to get this working can you share?

    – Juliano Vargas
    Jan 15 at 14:20







1




1





Did you ever get this working?

– Stephen Dance
May 18 '18 at 15:43





Did you ever get this working?

– Stephen Dance
May 18 '18 at 15:43













Did you? I'm working on this right now. Would love to know.

– JustinP
Nov 8 '18 at 2:01





Did you? I'm working on this right now. Would love to know.

– JustinP
Nov 8 '18 at 2:01













@JustinP Anyone manage to get this working can you share?

– Juliano Vargas
Jan 15 at 14:20





@JustinP Anyone manage to get this working can you share?

– Juliano Vargas
Jan 15 at 14:20










1 Answer
1






active

oldest

votes


















0














You need to specify the usage of the new block via XML. Add the following to your theme's default_head_blocks.xml



<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="page.top">
<block class=“VendorModuleBlockHtmlTopmenu" name="catalog.topnav" template="Magento_Theme::html/topmenu.phtml" ttl="3600" before="-"/>
</referenceContainer>
</body>
</page>





share|improve this answer






















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f206826%2fmagento2-2-override-topmenu-php-addsubmenu%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You need to specify the usage of the new block via XML. Add the following to your theme's default_head_blocks.xml



    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
    <referenceContainer name="page.top">
    <block class=“VendorModuleBlockHtmlTopmenu" name="catalog.topnav" template="Magento_Theme::html/topmenu.phtml" ttl="3600" before="-"/>
    </referenceContainer>
    </body>
    </page>





    share|improve this answer



























      0














      You need to specify the usage of the new block via XML. Add the following to your theme's default_head_blocks.xml



      <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
      <body>
      <referenceContainer name="page.top">
      <block class=“VendorModuleBlockHtmlTopmenu" name="catalog.topnav" template="Magento_Theme::html/topmenu.phtml" ttl="3600" before="-"/>
      </referenceContainer>
      </body>
      </page>





      share|improve this answer

























        0












        0








        0







        You need to specify the usage of the new block via XML. Add the following to your theme's default_head_blocks.xml



        <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <body>
        <referenceContainer name="page.top">
        <block class=“VendorModuleBlockHtmlTopmenu" name="catalog.topnav" template="Magento_Theme::html/topmenu.phtml" ttl="3600" before="-"/>
        </referenceContainer>
        </body>
        </page>





        share|improve this answer













        You need to specify the usage of the new block via XML. Add the following to your theme's default_head_blocks.xml



        <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <body>
        <referenceContainer name="page.top">
        <block class=“VendorModuleBlockHtmlTopmenu" name="catalog.topnav" template="Magento_Theme::html/topmenu.phtml" ttl="3600" before="-"/>
        </referenceContainer>
        </body>
        </page>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 23 at 14:25









        mluntmlunt

        769




        769



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f206826%2fmagento2-2-override-topmenu-php-addsubmenu%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

            Magento 2 disable Secret Key on URL's from terminal The Next CEO of Stack OverflowMagento 2 Shortcut/GUI tool to perform commandline tasks for windowsIn menu add configuration linkMagento oAuth : Generating access token and access secretMagento 2 security key issue in Third-Party API redirect URIPublic actions in admin controllersHow to Disable Cache in Custom WidgetURL Key not changing in Magento 2Product URL Key gets deleted when importing custom options - Magento 2Problem with reindex terminalMagento 2 - bin/magento Commands not working in Cpanel Terminal

            Aasi (pallopeli) Navigointivalikko