News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

How can a button be added to the main menu?

Started by captcha, April 15, 2020, 09:16:26 PM

Previous topic - Next topic

captcha

I am making a modification for my SMF website.
I have done to add the code into $hooks array and $buttons.
Something like these:
.......
'integrate_menu_buttons' => 'add_menu_buttons',....
function  add_menu_buttons(&$buttons)......
.......
It seems only add a hook can not change the menu, must I write a xml to modify the index.php's code to chang CDATA[] array?

Sir Osis of Liver

/Sources/Subs.php  Look for "all the buttons", that's the buttons array.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

vbgamer45

You can do it with hooks for 2.0+
I have a mod you can see it in use at https://custom.simplemachines.org/mods/index.php?mod=1354
Two parts dohooks.php installs the code needed to be done this way for 2.0    2.1.x you can do in package-info.xml
Then ArticlesHooks.php inserts the main menu in function articles_menu_buttons(&$menu_buttons)
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

captcha

#4
Quote from: vbgamer45 on April 16, 2020, 12:54:45 AM
You can do it with hooks for 2.0+
I have a mod you can see it in use at https://custom.simplemachines.org/mods/index.php?mod=1354
Two parts dohooks.php installs the code needed to be done this way for 2.0    2.1.x you can do in package-info.xml
Then ArticlesHooks.php inserts the main menu in function articles_menu_buttons(&$menu_buttons)
Thank you, Sir Osis of Liver, Kindred. I had read yours code , TinyPortal, adk blog, dream Portal, simple portal and guides to modify menu buttons( or tabs) before I posted this question. What confuse me is that it seems both integrating hooks and modification to index.php should take.
In yours Mod's article2.xml:  <file name="$sourcedir/subs.php">
      <operation>
      <search position="after"><![CDATA['mlist' => array(]]></search>
      <add><![CDATA[         
      // [Articles] button
         'articles' => array(
            'title' => $txt['smfarticles_menu'],
            'href' => $scripturl . '?action=articles',
            'show' => $context['allow_view_smfarticles'],
            'icon' => '',
         ),
]]></add>
   </operation>
</file>
The original code was modified. According to my coding experience, if the  hook was called, the original code should not be changed. I thought the code must be modified because the SMF version 1.x.x did not support hooks. Now it seems version 2.0.x still need to change the code even if the hooks are integrated and called .
I have tested your code, if the subs.php is not changed, the new button "Articles" won't show.
That means the function articles_menu_buttons(&$menu_buttons) and 'integrate_menu_buttons' => 'articles_menu_buttons', must work with help of code modification of subs.php.

vbgamer45

2.0 has hooks for certain areas.
2.1 has hooks for nearly all tasks.

2.0 I believe has the action hook.  Check out some other mods. ezPortal I know does for 2.1
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Doug Heffernan

Quote from: vbgamer45 on April 17, 2020, 02:10:20 PM
2.1 has hooks for nearly all tasks.

I have not had a chance to check out 2.1. properly yet, but this is good news. It will simplify the developing process for mods a lot.


captcha

Quote from: vbgamer45 on April 17, 2020, 02:10:20 PM
2.0 has hooks for certain areas.
2.1 has hooks for nearly all tasks.

2.0 I believe has the action hook.  Check out some other mods. ezPortal I know does for 2.1
I will read codes of ezPortal. It should be much better that the hook alone can solve the problem.
Thank you!

AmadeuszWiecz

Quote from: vbgamer45 on April 16, 2020, 12:54:45 AM
You can do it with hooks for 2.0+
I have a mod you can see it in use at https://custom.simplemachines.org/mods/index.php?mod=1354
Two parts dohooks.php installs the code needed to be done this way for 2.0    2.1.x you can do in package-info.xml
Then ArticlesHooks.php inserts the main menu in function articles_menu_buttons(&$menu_buttons)

I was just looking for how to make an additional button on the main page of the site. Thanks, helped.

vbgamer45

Yeah I think there is a menu editor mod out there as well. If it is just one button for yourself you can edit the files directly.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Advertisement: