7

I'm currently trying to check if a specific module is enabled by using Joomla's JModuleHelper::isEnabled(), however the problem being is that it is always returning false, despite whether it is actually enabled or not.

Having looked at the Docs, I've written the following:

jimport('joomla.application.module.helper');        
$freichat = JModuleHelper::isEnabled('FreiChat-I');

if($freichat) {
    $message = 'Enabled';
}
else {
    $message = 'Disabled';
}

$application = JFactory::getApplication();
$application->enqueueMessage( $message, 'warning');

I've tried changing FreiChat-I to login, which then always returns true, despite being enabled or disabled.

Is there a known bug that I'm unaware of or am I simply doing something stupid here?

1
  • 1
    IMO the Joomla team should rename this function to isAvailable as the example in the link you provided says that "Login module is available". The returned value of this function has 3 criterias which "is enabled" is only one of them.
    – Farahmand
    Aug 25, 2014 at 11:59

4 Answers 4

4

JModuleHelper::isEnabled() does not seem to account for any type of case sensitivity. So for example, using @Bakual's answer, your options are actually either mod_breadcrumbs or breadcrumbs (not Breadcrumbs)

Likewise, in your case, you would want to do JModuleHelper::isEnabled('freichat'). From looking at the table, everything will always be lowercase, so if you pass in a capital letter, you will get false.

Also, note that the extension not only has to be installed and enabled, but there much be an instance of the module published on the site.

1
  • I've tried mod_* along with making it lower case too. My answer below explains a little
    – Lodder
    Aug 25, 2014 at 19:15
4

The API page is here: http://api.joomla.org/cms-3/classes/JModuleHelper.html#method_isEnabled

You need to either pass the name of the module or the folder of it. So for the breadcrumbs module it would be either 'Breadcrumbs' or 'mod_breadcrumbs'. You can't use the title of the module.

Without knowing the name or folder of your module, I can't tell you more.

1
  • What I have provided is already the name of the module and I've also tried using the folder (mod_freichatx). the odd thing being is if I change it to Breadcrumbs, it still doesn't work and always returns false
    – Lodder
    Aug 25, 2014 at 10:45
2

public static function isEnabled($module);

Checks if a module is enabled. A given module will only be returned if it meets the following criteria: it is enabled, it is assigned to the current menu item or all items, and the user meets the access level requirements.

Update

You can use a db query instead:

$db = JFactory::getDbo();
$db->setQuery("SELECT `published` FROM `#__modules` WHERE `title` = 'Breadcrumbs'");
$is_enabled = $db->loadResult();
1

Thanks to everyone for taking them time to answer.

Having looked at the #__extensions table, I noticed that the enabled column was not being updated, even when I had, disabled a module, removed its position and unassigned it from all pages.

In the end, I decided to run a database query to check the existence of mod_freichatx in the table and display the enqueueMessage accordingly.

2
  • 1
    Were you disabling the modules from the extension manager or the module manager? The module manager affects the #__modules table, and specifically the published column, not the #__extensions table. Aug 25, 2014 at 20:11
  • @DavidFritsch - Just noticed that I have to disable it via the Extension Manager but still nothing. It does work with mod_login but returns false for mod_breadcrumbs. I think I might test this on a new installation of Joomla tomorrow. Thanks for your input.
    – Lodder
    Aug 25, 2014 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.