News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

createMenu set active button

Started by Matthias, December 09, 2019, 09:49:12 AM

Previous topic - Next topic

Matthias

Betreff:
createMenu set active button

SMF Version 2.0.15

I've created a custom action with subactions, let's call it MyAction as an example.
There I created a menu like the Profile, Personal Message or Admin.

MyAction.php

// A sidebar to easily access different areas of the section
function MyActionIndexBar()
{
global $context, $txt, $sourcedir, $modSettings, $scripturl, $options;

// Define all the menu structure - see Subs-Menu.php for details!
require_once($sourcedir . '/Subs-Menu.php');

$myaction_areas = array(
'myaction' => array(
'title' => $txt['myaction_menu_index'],
'areas' => array(
'myaction' => array(
'label' => $txt['myaction_menu_index'],
'permission' => ['smfmyaction_view'],
'custom_url' => $scripturl . '?action=myaction',
),
'search' => array(
'label' => $txt['myaction_menu_search'],
'permission' => ['smfmyaction_search'],
'enabled' => !$context['user']['is_guest'],
'custom_url' => $scripturl . '?action=myaction;sa=search',
),
),
),
'item' => array(
'title' => $txt['myaction_menu_item'],
'areas' => array(
'add' => array(
'label' => $txt['myaction_menu_add'],
'permission' => array('smfmyaction_add'),
'custom_url' => $scripturl . '?action=myaction;sa=add,
),
'edit' => array(
'label' => $txt['myaction_menu_edit'],
'permission' => array('smfmyaction_edit'),
'custom_url' => $scripturl . '?action=myaction;sa=edit,
),
),
),

// Determine if it is a subaction
    if (isset($_REQUEST['sa']))
   $sa = $_REQUEST['sa'];
    else
        $sa = '';

if (!empty($subActions[$sa]))
$subActions[$sa]();

// What page is this, again?
$current_page = $scripturl . '?action=myaction' . (!empty($_REQUEST['sa']) ? ';sa=' . $_REQUEST['sa'] : ''),

// Set a few options for the menu.
$menuOptions = array(
'disable_url_session_check' => true,
'toggle_url' => $current_page . ';togglebar',
'toggle_redirect_url' => $current_page,
);

// Actually create the menu!
if ($_REQUEST['action'] == 'myaction')
$myaction_include_data = createMenu($myaction_areas, $menuOptions);
unset($myaction_areas);

// Make a note of the Unique ID for this menu.
$context['myaction_menu_id'] = $context['max_menu_id'];
$context['myaction_menu_name'] = 'menu_data_' . $context['myaction_menu_id'];

// Why on the myaction are we?
$context['myaction_area'] = $myaction_include_data['current_area'];

// Set the selected item.
$context['menu_item_selected'] = $myaction_include_data['current_area'];
}
   

The menu is called in the Main function.

function MyActionMain
{
global $context, $scripturl, $mbname, $txt, $smcFunc, $modSettings, $user_info;

// Show the top menu
MyActionIndexBar();

More stuff....


The most of the code I have taken from PersonalMessage.php beginning at line 290. There are also used custom url's.
Everything works fine, the menu itself, the togglebar.
But what does not work is the active button. The class for the active button should change to <a class="active firstlevel" ...
That does not work.
Can someone help me or have an idea why that is.
Many thanks!
Quality first

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."

Matthias

What do you mean exactly?

The button name is the label

'label' => $txt['myaction_menu_index'],


The action is
'custom_url' => $scripturl . '?action=myaction',

This ist set in $myaction_areas
Quality first

Advertisement: