How can I check if a plugin is already available?

a_c_m - December 4, 2008 - 21:29
Project:jQ
Version:6.x-1.2
Component:Documentation
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

I'm porting cluetips to D6 and making it a JQ module.

Cluetips zip comes with all the JS files it needs (hoverIntent and dimensions), currently the module just uses them, however i would love it, if it could work out if a JQ module exists to take over the work and use that file instead (if avilable).

The problem is the jq_plugins() function. We need to call it in the MODULENAME_jq() hook, to assess if the local files for hoverIntent need to be used, but in calling jq_plugins() it triggers its own hook again, causing a loop.

Any nice way around this? or have i missed the point?

#1

kiamlaluno - December 18, 2008 - 12:45

If you are porting the module to Drupal 6, you should know that the dimensions plugin is already included within jQuery 1.2.6 used by Drupal 6 (see the jQuery 1.2.6 release notes on Dimensions Plugin is Now Part of Core).

#2

kiamlaluno - December 18, 2008 - 13:15

If what you want to do is to check if a plugin is available, before to use your own version of the plugin, you can call jq_add() which returns a value useful to understand if the function has been able to load the required plugin (therefore, the plugin is already available).

#3

kiamlaluno - December 18, 2008 - 13:18
Title:How can i check if a module is already installed?» How can i check if a plugin is already available?

I am changing the request title, as it seemed you were asking how to generally check if a module is available (which would lead somebody to reply with call module_exists()).

#4

kiamlaluno - December 18, 2008 - 13:18
Title:How can i check if a plugin is already available?» How can I check if a plugin is already available?

#5

guix - August 28, 2009 - 13:24

Would this work ?

if ( !empty(jq_plugins('your_plugin') ) {
  ...
}

#6

guix - August 28, 2009 - 14:23

Oups that was producing a fatal PHP error. Use

if ( in_array('your_plugin', jq_plugins()) ) {
...
}

#7

ball.in.th - November 16, 2009 - 04:24

I believe the correct syntax for #6 would be:

if (array_key_exists('cycle', jq_plugins())) {
}

Though it doesn't seem to be necessary because you can just check the return value of jq_add('your_plugin'); .

#8

guix - November 16, 2009 - 15:13

@ #7 if I remember well this is not right when the module is unavailable, since it adds a warning in watchdog.

#9

kiamlaluno - November 16, 2009 - 15:41

<?php
 
if (module_exists('jq') && array_key_exists('cycle', jq_plugins())) {
   
// ...
 
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.