Check if separate module is installed and activated

Hello,

What kind of code would I need to check if a separate module is installed and activated from within a theme? Having a hard time figuring this out. Thanks!

Within my show.phtml is use this code:

$hasMyModule = $this->getHelperPluginManager()->has('myModule');
if ($hasMyModule) {
                        ....
                    } else {
                        ....
                    }

Is this helpful?

Thanks Dan. I tried this but this is only seems to show what ‘helpers’ are available, not actual modules. But maybe I’m using it wrong. I did separately realize that I can do an API search to list all the modules, and then loop through them.

$this->api()->search('modules')

Get the module using $this->getServiceLocator()->get('Omeka\ModuleManager')->getModule($id) where $id is the module’s directory name. Then you can get the module’s state using $module->getState().

I’m not able to get the service from a view though, or am I doing it incorrectly?

Basically, within my theme, I want my search to display one way or the other if the Solr module is installed. I suppose I could handle that by modifying the Solr Module, but I’m trying to avoid having too many modified modules in our installation.

Out of the box there’s no way to get the module manager (or the service locator for that matter) from the view. You could create a module that adds a view helper that provides it.

Thanks Jim. I actually found that Dan’s suggestion inadvertently works best for me in a sort of backdoor way. I can just check if one of the specific helpers from the module is available, which would also verify that the module is in fact active.

1 Like

This topic was automatically closed 250 days after the last reply. New replies are no longer allowed.