Feature Requests
Share ideas, discuss and vote on requests from other users in community
 
This object is in archive! 

Module hooks should be able to access module params

thoraxe shared this idea 5 years ago
Under Consideration

Currently, it is possible to create a hook as part of a module. For example, adding hooks.php to the modules/servers/foo/ folder would enable the hooks to be used by the Foo module.

Unfortunately, as opposed to when you are using the various module functions (ex: CreateAccount), you cannot access $params from the module within the module's hooks.

This makes it very difficult to make calls to external APIs as part of hooks, which would be extremely logical.

If you want to use aspects of the module's params in a hook, you either have to:

1) hard-code that information into the hook script

2) make mysql calls into the database to pull information from the module, which either involves

-- hard-coding ids into the hook script

-- requiring special words/tags/terms to be used in the module configuration so that you can search for them via mysql to get the right result

Since the hooks are already associated with the module, it would be logical for the module's information to be available within the module-specific hooks.

Let's say you have a provisioning module that creates a forum account. The "server" for that provisioning module is the place where the forum software lives. When a user comes to WHMCS to purchase their account, they fill out a desired username, and you would want to make an API call to the forum to check if that username is available.

Right now you either have to hard-code the url of the forum software into your hook (ShoppingCartValidateProductUpdate), or do some crazy mysql calls to determine the url of the forum. If you don't specifically code the IDs of this information into the hook script, then you have to use special strings and search for them.

All of this is really bad coding practice, and is really easy to break. Having a module's hooks have access to the module's configuration info would fix everything.

Comments (1)

photo
2

its not really that hard, and theres nothing bad practice about performing a simple mysql query:

  1. $moduleoptions = select_query('tbladdonmodules', 'setting,value', array('module' => 'modulename'));
  2. $opts = array();
  3. while($m = mysql_fetch_assoc($moduleoptions)){
  4. $opts[$m['key']] = $m['value'];
  5. }

then all the settings for that module are in the opts array, or just use get query val for specific options.

but i do agree with the original request, these should be made available in the vars passed to the hooked function, just to save us al a bit of coding.