Friday, May 25, 2018

Name means ID, ID means name

Let's take a break from TFS.

This time, it's Joomla!, a popular Web CMS, which has an expansive, if sorely underdocumented, extension interface. Once again, I've discovered a little undocumented something, and would like to share.

Joomla has several types of extensions - plugins, modules, components, templates. I was fooling around with components, and discovered a rather unpleasant shortcoming. Components have a manifest with a <name> element in it. By default, the value of the name serves as both the the element (the internal name), for URLs and such, and as the display name. So, if you have a component that you want listed as "Widget Frobulator by Acme Software", Joomla will internally call it com_widgetfrobulatorbyacmesoftware. Meanwhile, I'd rather call mine com_frob.

Undocumented parameters to the rescue. In the component manifest, under <extension>, there can be an element called <element>. If it's present, its value explicitly provides the internal name. It may or may not be prefixed with com_; if it's not, Joomla will add that. So my component is known to Joomla as com_frob, and life is good again.

When it comes to locating the component's main script, Joomla goes by element and not by name, removing the initial com_ from it. So, in our example, the startup file of the component would have to be frob.php.

The built-in components of Joomla use a different technique to make sure the display name doesn't match the element. They don't have an <element> in their manifests, their <name> is the element (e. g. com_content for the Articles component), and the language file includes a translation from com_content to Articles. My component didn't have any translations.

With plugins, the logic for assigning the element is different. Unless <element> is there, Joomla goes over the <files>, takes the first <filename> with the attribute "plugin", and uses the value of that attribute as the element. So, if the <files> portion of the manifest goes:

<files>
    <filename>index.html</filename>
    <filename plugin="foo">foo.php</plugin>
</files>


Then "foo" will be the plugin's internal name. There's little point in providing <element> explicitly.

Haven't tried it with modules or templates.

This holds as of Joomla 3.8.8.

No comments:

Post a Comment