1
dejadingo
Calling XoopsModule->getAdminMenu() from multiple files
  • 2009/1/2 0:17

  • dejadingo

  • Just popping in

  • Posts: 71

  • Since: 2004/10/22


I've been working on CPanel themes over the holidays, and here is an issue that's caused me a lot of headaches and for which I finally isolated the source.

If you create module instances with code from different files while you are building a CPanel theme, the first call to getAdminMenu() for a module will return the menu, but subsequent calls *from different files* will always get an empty menu.

This is happening because the second time you call the method, PHP knows you have already loaded the module's adminmenu file and does not load it again. However, when a module instance is being created and initialized in a different file we need to load the adminmenu file in order to get the $adminmenu array with which to initialize the adminmenu property of the module.

I noticed that MusS seems to have tripped on this issue in his lovely ThAdmin module, but the patch at the end of xoops_thadmin_cp_header() was not sufficient to fix my problems. I really think this is a bug in the XoopsModule class, and it makes incremental development of CPanel themes very difficult. Here's the hack I am currently using on my systems. It's a simple change, and I'd like to hear if anyone thinks this should *not* be generally adopted for the XOOPS core.

/**
     * Load the admin menu for the module
     */
    
function loadAdminMenu()
    {
        if (
$this->getInfo('adminmenu') && $this->getInfo('adminmenu') != '' && file_exists(XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/'.$this->getInfo('adminmenu'))) {
// -DJD-
//
//        Make sure we actually load the module's menu (if there is one).
//
//        Using 'include_once' prevents menu initialization when subsequent
//            calls to getAdminMenu() are made from within independent files
//            during the same execution.  A good example is when CPanel menu
//            construction is shared between methods in the XoopsSystemGui
//            subclass and functions in an included cp_functions.php file.
//        PHP loads the file in the context of the first call, but since new
//            instances of XoopsModule are created for use in each independent
//            file's functionality, all subsequently instantiated XoopsModule
//            instances do not have an adminmenu.
//
//            include_once XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/'.$this->getInfo('adminmenu');
            
include XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/'.$this->getInfo('adminmenu');
//
// -DJD-
            
$this->adminmenu =& $adminmenu;
        }
    }

Login

Who's Online

147 user(s) are online (68 user(s) are browsing Support Forums)


Members: 0


Guests: 147


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits