My extension makes reports based on the Civisualize extension. I'd like to make dashlets out of the reports, but I only want it to be available when Civisualize is also enabled.

It's easy to see if Civisualize is already enabled when my extension becomes enabled, but I don't see a way to find out when Civisualize becomes enabled or disabled after my extension has become active.

My extension does not depend on Civisualize, it works perfectly without, but it only gives some extra nice reports.

So I would like to use some kind of hook_extension_enabled which will be fired when other extensions become enabled so I can add my dashlets to the system when Civisualize becomes active and remove the dashlets when it gets inactive.

  • What do you mean exactly by "It's easy to see if Civisualize is enabled when my extension is enabled,"? How are you verifying that? – Allen Hutchison Feb 11 '16 at 21:47
  • 1
    I edited my question, think it is more clear now what I want. – Catorghans Feb 11 '16 at 22:08
  • Hi, I think we should be able to flag dependencies between extensions. GSoC project? – Xavier Feb 12 '16 at 10:18

Looking at the Civi API Explorer, you could reference the Extension entity.

The help text for the Key parameter (API explorer uses full_name in the code) says "Fully qualified extension name". If you got the Key parameter full_name="eu.tttp.civisualize", you could load your dashlets conditionally based on whether CiviVisualize is enabled.

| improve this answer | |
  • Yes, I can use that during the install or enabling of my extension and then use "Dashboard - Create" api call to add the dashlet. But when should I check it if Civisualize is not active during install of my extension and I want to make my dashlets available when it becomes active? (Or worse, when Civisualize gets disabled after my dashlets are added to the system). Maybe the answer has to be: I just give a warning when the dashlet is shown and Civisualize is not enabled, but I'd prefer they are not shown in that case. – Catorghans Feb 11 '16 at 22:23

An alternate approach to checking for the enable/disable status is to use function_exists() to check if any of the functions CiviVisualize defines are in PHP's list of defined functions, which implies that CiviVisualize is installed and enabled.

if (function_exists('civisualize_civicrm_config')) {
  // Yay! Provide dashlets.
else {
  // Recommend installing CiviVisualize

If the extension isn't enabled, you can still provide placeholder content that will be replaced when the extension is enabled.

Using function_exists() should have relatively little performance impact and therefore may allow you to check the currently enabled status of that extension, rather than watch for enable/disable "events".

This also has the benefit of not failing when (e.g) the other extension is removed from the filesystem without being disabled first. It also has an issue of being sensitive to function naming within the other extension, but if civisualize_civicrm_config was renamed you'd probably be looking at a whole new version of the extension you integrate with.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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