Adding tabs to ACP?
#1
How would I go about adding a tab to the top of the ACP? With a link to a URL?

I assume it has something to do with the hook:
"admin_page_output_nav_tabs_start"

But how do I add another one?

Thanks
Reply
#2
This user has been denied support. This user has been denied support.
My Patches/Hooks plugins add a nav tab to the plugin section. It's not really a straightforward process, though. The other tabs (already present) have to be duplicated in the plugin code because the original config module hides them away in actions (also duplicated).

So for example the original modules/config/plugins.php code looks like this:

if($mybb->input['action'] == "browse")
{
...
	$sub_tabs['plugins'] = array(
		'title' => $lang->plugins,
		'link' => "index.php?module=config-plugins",
		'description' => $lang->plugins_desc
	);
	$sub_tabs['update_plugins'] = array(
		'title' => $lang->plugin_updates,
		'link' => "index.php?module=config-plugins&action=check",
		'description' => $lang->plugin_updates_desc
	);
...
}
if($mybb->input['action'] == "check")
{
...	
	$sub_tabs['plugins'] = array(
		'title' => $lang->plugins,
		'link' => "index.php?module=config-plugins",
	);
	
	$sub_tabs['update_plugins'] = array(
		'title' => $lang->plugin_updates,
		'link' => "index.php?module=config-plugins&action=check",
		'description' => $lang->plugin_updates_desc
	);
...
}

So it duplicates the tabs, description, etc. for each action resp. and unless I want my own plugin tab to go down one of those original action trees I have no choice but to make another copy of those tabs in my own plugin code. It's horrible style, of course...

Plugin code looks like this:

$plugins->add_hook('admin_page_output_nav_tabs_start', 'hooks_tabs_start');
$plugins->add_hook('admin_config_plugins_begin', 'hooks_plugins_begin');

/**
 * Add Hooks tab on the plugins page.
 */
function hooks_tabs_start(&$arguments)
{
    global $mybb, $lang;

    $lang->load('hooks');

    if($mybb->input['module'] == 'config-plugins')
    {
        $arguments['hooks'] = array('title' => $lang->hooks,
                                    'description' => $lang->hooks_tab_desc,
                                    'link' => HOOKS_URL);
    }
}

/**
 * Output tabs with Hooks as active.
 */
function hooks_output_tabs()
{
    global $page, $lang;

    $sub_tabs['plugins'] = array(
        'title' => $lang->plugins,
        'link' => 'index.php?module=config-plugins',
        'description' => $lang->plugins_desc
        );

    $sub_tabs['update_plugins'] = array(
        'title' => $lang->plugin_updates,
        'link' => 'index.php?module=config-plugins&action=check',
        'description' => $lang->plugin_updates_desc
        );

    $sub_tabs['browse_plugins'] = array(
        'title' => $lang->browse_plugins,
        'link' => "index.php?module=config-plugins&action=browse",
        'description' => $lang->browse_plugins_desc
        );

    // The missing Hooks tab will be added in the tab_start hook.
    $page->output_nav_tabs($sub_tabs, 'hooks');
}

The nav tab start hook makes sure your tab will show up on all other tabs as well, and the output_tabs function (which has to be called by you at the appropriate place, i.e. when the user clicks on your own tab) adds the original tabs back to the list...

Ideally the sub_tabs variable should be initialized early at one point only so you could just re use it in the plugin but oh well...
PS: If you meant the menu at the very top and not the nav tabs below that, that's add_menu_item() in admin/inc/class_page.php
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)