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

            Disable / Remove link to Product Items in Cart Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?How can I limit products that can be bought / added to cart?Remove item from cartHide “Add to Cart” button if specific products are already in cart“Prettifying” the custom options in cart pageCreate link in cart sidebar to view all added items After limit reachedLink products together in checkout/cartHow to Get product from cart and add it againHide action-edit on cart page if simple productRemoving Cart items - ObserverRemove wishlist items when added to cart

            Helsingin valtaus Sisällysluettelo Taustaa | Yleistä sotatoimista | Osapuolet | Taistelut Helsingin ympäristössä | Punaisten antautumissuunnitelma | Taistelujen kulku Helsingissä | Valtauksen jälkeen | Tappiot | Muistaminen | Kirjallisuutta | Lähteet | Aiheesta muualla | NavigointivalikkoTeoksen verkkoversioTeoksen verkkoversioGoogle BooksSisällissota Helsingissä päättyi tasan 95 vuotta sittenSaksalaisten ylivoima jyräsi punaisen HelsinginSuomalaiset kuvaavat sotien jälkiä kaupungeissa – katso kuvat ja tarinat tutuilta kulmiltaHelsingin valtaus 90 vuotta sittenSaksalaiset valtasivat HelsinginHyökkäys HelsinkiinHelsingin valtaus 12.–13.4. 1918Saksalaiset käyttivät ihmiskilpiä Helsingin valtauksessa 1918Teoksen verkkoversioTeoksen verkkoversioSaksalaiset hyökkäävät Etelä-SuomeenTaistelut LeppävaarassaSotilaat ja taistelutLeppävaara 1918 huhtikuussa. KapinatarinaHelsingin taistelut 1918Saksalaisten voitonparaati HelsingissäHelsingin valtausta juhlittiinSaksalaisten Helsinki vuonna 1918Helsingin taistelussa kaatuneet valkokaartilaisetHelsinkiin haudatut taisteluissa kaatuneet punaiset12.4.1918 Helsingin valtauksessa saksalaiset apujoukot vapauttavat kaupunginVapaussodan muistomerkkejä Helsingissä ja pääkaupunkiseudullaCrescendo / Vuoden 1918 Kansalaissodan uhrien muistomerkkim

            Adjektiivitarina Tarinan tekeminen | Esimerkki: ennen | Esimerkki: jälkeen | Navigointivalikko