Skip to main content
Topic: integrate_menu_buttons add to admin item (Read 6539 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

integrate_menu_buttons add to admin item

If I understand this right, should I be able to add sub item to the admin menu by simply doing the following?

Code: [Select]
		$menu->childOf('admin')->add('admin_sub_buttons')->addBulk(
array(
'myadmin' => array(
'title' => 'My Admin',
'href' => $scripturl. '?action=myadmin',
'show' => true,
)
)
);

This is not working for me. And I've tried it multiple ways to see if I'm just not understanding the code. What I did find out somehow though, is that if I have the above code executed twice (right in a row), my item actually shows up at the bottom of the admin menu.  Very weird. Not following this logic at the moment, so I'm calling bug. :D
Success is not the result of spontaneous combustion, you must set yourself on fire!

Re: integrate_menu_buttons add to admin item

Reply #1

Yes, I was playing with it yesterday and I noticed I forgot to add "a bit of code"... O:-)

At what level do you want to add the button? First level?
Bugs creator.
Features destroyer.
Template killer.

Re: integrate_menu_buttons add to admin item

Reply #2

Here it is:
https://github.com/emanuele45/Dialogo/commit/4c1aa6f8ea1dfb6e67219fd1aa89e4ebad322c36

Example of how to add a new item to any menu:
Code: [Select]
// Grab all the menus we have
$allMenus = Standard_Menu::context();

// Find the admin menu
$admin_menu = $allMenus->get('Admin_Menu');

// Find the submenu you want (this get is a shortcut that will find menus at any nesting level and any position,
// if a sort of getElementById in javascript terms.
// Though if you know where your menu is you can do the "extended" version with childOf that should be slightly faster
$submenu = $admin_menu->get('manageboards_sub');

// Add the new menu item
$submenu->add('my_new_menu', array($txt['menu_name'], 'optional_permissions'));

This is the very basic usage.

Then you may want to add for example an entire new menu at the first level, after config, with a droppy with a submenu, then you should do something like:
Code: [Select]
// Grab all the menus we have
$allMenus = Standard_Menu::context();

// Find the admin menu
$admin_menu = $allMenus->get('Admin_Menu');

// Add the "visible" item (i.e.the label)
$admin_menu->after('config')->add('your_main_item', array(
'title' => $txt['main_item_name'],
'permission' => array('admin_forum')
));

// Now create your new sub-menu and add it to the main one:
$my_item = $admin_menu->childOf('forum')->add('your_main_item');

// Finally populate it. addBulk is a shortcut (again) for add that loops through an array of menus and adds them one by one)
$my_item->addBulk(
array(
'index' => array(
'label' => $txt['admin_center'],
'controller' => 'Admin_Controller',
'function' => 'action_home',
'icon' => 'transparent.png',
'class' => 'admin_img_administration',
),
)
);

Now that I look at the code, I think the first two lines could be "merged" into a single call... Will work on that.

There is still a distinction between a "menu" (i.e. a "collection" of entries) and an "entry" (i.e. the "text" visible in the menu/droppy), and the two behave slightly differently (actually quite a bit differently). I think this should be polished up, not sure yet how... :-[

Yes, it's not the same as an array. :P
Bugs creator.
Features destroyer.
Template killer.

Re: integrate_menu_buttons add to admin item

Reply #3

Thinking even more about this: if in 1.1 we are going to add a menu editor (are we, isn't it? O:-)), I'm tempted to just come back to the "old" simple array.
This class (properly finished and functioning) make sense if the entries are not manipulated from the database, but if in the round of a minor version we are anyway changing it it seems pretty useless...

I have no ego problems, so speak now or live with it for 1.0. :P
Bugs creator.
Features destroyer.
Template killer.

Re: integrate_menu_buttons add to admin item

Reply #4

Looks like I picked the wrong week to quit sniffing glue

Looks like I picked the wrong week to quit drinking.

Looks like I picked the wrong week to quit smoking.

Looks like I picked the wrong week to quit amphetamines

http://www.youtube.com/watch?v=lyhaTQseKTQ

Re: integrate_menu_buttons add to admin item

Reply #5

lol...

I'd say whatever makes the most sense that will help with the next evolution. But then again, I'm not the one coding it here. lol
Why doesn't it lend itself well to pulling the menu from the database. Assuming we cached it, or threw it into it's own file after writing to the database. Couldn't this version be used to populate the menu in the same way?
Success is not the result of spontaneous combustion, you must set yourself on fire!

Re: integrate_menu_buttons add to admin item

Reply #6

BTW, I was talking about the main menu admin items here, not the Admin menu in admin. How does one add something as a sub menu item of the main menu Admin button? I can't seem to figure out how to grab the sub items and add something to it.

I should say though, even as complicated as this had made the menu code, this really rocks. Being able to pop and item on or off etc is really easy. I just haven't figured out the sub items part. lol
Success is not the result of spontaneous combustion, you must set yourself on fire!

Re: integrate_menu_buttons add to admin item

Reply #7

Quote from: IchBin – I'd say whatever makes the most sense that will help with the next evolution. But then again, I'm not the one coding it here. lol
Why doesn't it lend itself well to pulling the menu from the database. Assuming we cached it, or threw it into it's own file after writing to the database. Couldn't this version be used to populate the menu in the same way?
It could be used, yes, but it wouldn't make much sense.
I thought this version to be able to target better specific entries in the menu via code, but if we move the beast to the database then it is "just" a grab and populate, nothing more and any addon that want to add a menu item will just add it directly to the database, similarly to an updateSettings, I don't see any reason to use hooks or other similar things just to add a menu.

Okay, tomorrow I'll push the reverts. ;)
Bugs creator.
Features destroyer.
Template killer.