Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating admin menu items dynamically in joomla
    text
    copied!<p>Another day playing around with joomla, and another shortcoming to fix :)</p> <p>This time it comes in the form of the administration(backend) menu. To add items/subitems to this menu, people have to write the menu items in an xml file accompanying their components/extension/plugin/whatever. When the extension is installed, joomla "generates" the menu items and "stores" them in the DB. Effectively, the real/tangible menu is rendered by reading the DB.</p> <p>This has several implications:</p> <ul> <li>The menu is not scriptable</li> <li>The menu is not dynamic; changing the XML file <em>after</em> installation, won't update the menu</li> <li>Removal of items is not scriptable; joomla takes care of removing any items when you uninstall the extension.</li> </ul> <p>I've got this system which relies on the ability to modify menu items on the fly, but through code. Simply put, I need to have functionality where I can create a volatile menu item (ie, it gets removed at the end of session).</p> <p>To do so, I've got a couple of prospective hacks:</p> <ol> <li>Override the joomla global database instance so that I can make it return fake menu items. This is possible since the database object is stored in a public property of JFactory class: <code>JFactory::$database=new MyFakeJDatabase(JFactory::$database);</code></li> <li>Intercept the menu code (html) before being output and mess it up according to my needs. This is not template-friendly in that the end result would be injecting html, which might not be what the template was designed for.</li> <li>Create menu items through javascript. This suffers issues with the template AND the javascript that toggles submenus.</li> <li>Create menu items in the DB whenever I need them and somehow "tag" my items so that I remove them the next time (or end of session). This sounds like it would work like a charm. Since I can buffer menu items, I could possibly create my menu items in one whole SQL statement. Than I could use another SQL to remove the tagged menu items. 2 SQL statements might not be much of a load on the server.</li> </ol> <p>What do you think?</p> <p><strong>Edit:</strong> I've checked <code>joomla/administrator/modules/mod_menu/helper.php</code> to see if I could find a way to inject my stuff, wishing that maybe joomla used a global variable or something, but to no use - the menu items are creating directly by reading the db and rendering as well. FYI I've searched a while on Google, to no use.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload