Terryburg’s Tales of Things You Might Not Know

Things you might not know about Joomla modules

Things you might not know about Joomla modules

Maybe you do know, maybe you don’t, but here are a couple interesting Joomla module plugins to make life easier.

First, just this past year I hit upon a possible solution to the problem of “the trouble with modules”, wherein like Tribbles they multiply uncontrollably. I ran into this big time while implementing a Docman site. These documents were organized hierarchically by a broad category (events), and then by event/year, then by subcategory.

Docman has a module named Docman Documents you can use to display a slice of documents by their category. So you can define a new module xyz to display documents of category abc and plunk that in some article or sidebar somewhere and voila! nice little linked list of the documents in that category.

That was great, except that I needed about 50 of these things to display specific little groups of documents on various pages, by the specific lowest level subcategory. Being a programmer at heart I did not want to create 50 modules, did not see any reason I should have to do so, and did not want to slog through them every time I opened up Module Manager in the future. Surely there had to be a way of creating parameterized modules, no?

And there was a solution (and are probably numerous solutions). The one I went with is a plugin named Module Plant, from J-Plant Team. This little guy lets you create one module of the type, in this case a Docman Documents module, and then use it in many places just overriding parameters to create a “virtual module” to show different sets of documents. So, to embed a module in an article or sidebar using the plugin’s shortcode, you could do like
[moduleplant id=”101″ category=”2″], or
[moduleplant id=”101″ category=”3″]
where the id is your module ID and category is the Docman category number, and the same module displays a different set of documents depending on that category ID. And of course, this kind of override would work for any kind of module. (A note right here: Supposedly you can override parameters with a string, but I didn’t have any luck with that, so had to do it by Docman category ID. That might be an issue if you can’t figure out how to pass strings. One of these days I will put this to use with something besides Docman, and see what happens.)

One caveat, in order to display more than one category of Docman documents in the same article, you (or at least I) can’t use the same dummy module. Don’t know if that’s a plugin issue or a Docman issue, but you can’t – only one category would show up, numerous times. So I ended up creating several dummy modules, and on a page where I wanted to show more than one different category of Docman documents, would enter  [moduleplant id=”101″ category=”2″] [moduleplant id=”102″ category=”3″]  etc. It’s not a one dummy module fits all solution, but it’s a two or three dummy modules fit versus 50 separate modules solution. In some other article I could re-use those same modules, but with different categories.

You can find the different parameters you can override for a module in the XML file for that module. NOTE: Moduleplant did not offer an option to pass in an array of values for modules that require that for some parameters. At least not that I could find documented. So I had to do some hacking in moduleplant.php after line 64 that reads
foreach ($moduleParams as $modParamKey => $modParamValue) {
to look for some special text that I had wrapped around array values, and then create an array to assign to $modParamValue. Kinda hokey but it worked.

The Module Plant plugin by J-Plant can be found here:
Module Plant plugin

Update: November, 2018

Joomla 3.9 broke the Moduleplant plugin, because Joomla introduced a function in its /libraries/src/Helper/Modulehelper.php with the same name as one defined in the plugin. And what do you know, even though the module is still listed in the JED this plugin is apparently no longer supported. Developer home page is dead.

But it’s easy to fix. There’s probably a more elegant way, but what was simplest was just to rename the function defined in the plugin.

So in file /plugins/system/moduleplant/core/joomla/application/modules/_jadapters/_j16/helper.php on approx. line 25 you want to change

public static function &getModuleById($id)
to something like
public static function &getMPModuleById($id)

and in file /plugins/system/moduleplant/moduleplant.php on approx. line 33 change

$module = JPlantModuleHelper::getModuleById(intval($params[‘id’], 10));
to your new function name
$module = JPlantModuleHelper::getMPModuleById(intval($params[‘id’], 10));

and the plugin is good to go again.

Second, I want to mention the excellent Advanced Module Manager by Nonumber. There are probably other plugins out there that do similar things, but the most valuable feature of the plugin to me personally is the ability to assign modules by component, instead of being stuck with just menu items to choose from like Joomla core. This is especially valuable for components like ecommerce packages that have no specified menu paths to the various interior pages. Assign your module to some region in your template and specify a component, and once again voila! it shows up on every page associated with that component.

The Advanced Module Manager from Nonumber can be found here:
Advanced Module Manager plugin

Thanks to both of the above mentioned developers for making my life a lot easier!

And of course, before downloading and installing any extension, check the Joomla Vulnerable Extensions List. For instance, the Nonumber framework was on it a couple years back. 🙁
Joomla Vulnerable Extensions List