e107inc / e107

e107 Bootstrap CMS (Content Management System) v2 with PHP, MySQL, HTML5, jQuery and Twitter Bootstrap. Issue Discussion Room: https://gitter.im/e107inc/e107
https://e107.org
GNU General Public License v3.0
322 stars 214 forks source link

[Bug]: Not able to set correct active link in admin menu #5349

Open Jimmi08 opened 1 month ago

Jimmi08 commented 1 month ago

What e107 version are you using?

v2.3.3, Latest Github version (just updated)

Bug description

I am changing admin menu dynamically. Standart way with function init().

Admin UI works normally, if you check getAction() in class xy_ui extends e_admin_ui , it is correct.

Only problem is that not correct menu is marked as active.

After checking some request values and action values, they are not set correctly when admin menu is rendered.

action is always list

How to reproduce

This is classic menu settings:

    protected $adminMenu = array(
        //'main/prefs'      => array('caption' => LAN_PREFS, 'perm' => 'P'),
        'main/list'         => array('caption' => LAN_MANAGE,   'perm' => 'P'),
        'main/create'       => array('caption' => _ADDNEWPANEL, 'perm' => 'P'), 
        'main/div0'      => array('divider' => true),
        //  'main/help'     => array('caption'=> 'Help Page', 'perm' => 'P'),
    );

Then dynamically are menus added:

function init()
    {
        $panelTypes = e107::getEfiction()->getPanelTypes();

        foreach ($panelTypes as $key => $value)
        {
            $mode = "main";
            $action =  $key;

            $menu = $mode . '/' . $action;
            $this->adminMenu[$menu] = array(
                'caption' => $value,
                'perm' => 'P'
            );
        }

        $this->adminMenu['main/div1'] = array('divider' => true);

        $this->adminMenu['main/help'] = array(
            'caption' => 'Help Page',
            'perm' => 'P'
        );
    }

Active works for list, create and help items.

getAction() returns "list" for them (in renderMenu() in admin_ui class) where selected is set

but in class xy_ui extends e_admin_ui getAction() returns the correct action and I am able to manipulate listQry() correctly.

I tried to use __construct() instead init(), but then menu items are not displayed at all.

Thanks for help

Expected behavior

Respect action parameter correctly

What browser(s) are you seeing the problem on?

Firefox

PHP Version

8.1

Jimmi08 commented 1 month ago

If you add Page methods , active works but admin UI Not (of course)

    public function APage()
    {
    }

    public function PPage() {

    }

_preDispatch() in admin_ui() is looking for a method for each action and if it is doesn't exist it sets it as the default

Jimmi08 commented 1 month ago

This fixed it on localhost

$code = " 
$(document).ready(function() {
    var currentUrl = window.location.href;
    $('#admin-ui-nav-menu li').each(function() {
        var link = $(this).find('a').attr('href');
        if (link === currentUrl) {
            $('#admin-ui-nav-menu li').removeClass('active');
            $(this).addClass('active');
        }
    });
});
";

e107::js('footer-inline', $code);