Javascript Drupal Extension extends the Drupal JavaScript object by exposing Drupal/PHP functions via AJAX-calls.
Ever needed to call a Drupal function from JavaScript that isn't already available in the Drupal JavaScript object? Javascript Drupal Extension fixes that by extending the Drupal object to expose PHP functions via AJAX-calls.
By default this module includes drupal_get_path() as it was the reason I made the module in the first place. I needed to get the path of a module that was installed, and thus Javascript Drupal Extension was born.
Example:
var path = Drupal.drupal_get_path('module', 'my-awesome-module');
-or-
Drupal.drupal_get_path('module', 'my-awesome-module', 'callback-function-for-path');
Both these queues up the AJAX call, which by default is filtered through a whitelist to ensure safety, and either returns the output of the called function directly, or sends the output to the callback function supplied as the last argument. You can also supply another callback after the first one which will be used in case the AJAX-call fails for some reason. The default action in that case is to throw an error.
Extending:
The module is written in such a way that extending other functions is as easy as adding a few lines of codes.
Let's say you wish to extend the t() function out to JavaScript. Yes I know it is already in the Drupal object, but just for show, let's pretend it isn't.
All you have to do is add the following JavaScript code, somewhere:
Drupal.t = function (text) {
return javascript_drupal_extension_ajax_call('t', { text });
}If you have the whitelisting feature enabled (which it is by default), you would also have to add the 't' function in the admin section.
If you want to throw callbacks in the mix, just extend the code as such:
Drupal.t = function (text, callback_success, callback_failure) {
return javascript_drupal_extension_ajax_call('t', { text }, callback_success, callback_failure);
}Installation:
Installation is pretty straight forward and should require no code alterations by the developer, unless you want to add more functions to call.
The module sets three variables in the Drupal variable-set which are also deleted upon uninstall.
Project information
- Project categories: Developer tools
3 sites report using this module
- Created by PDNagilum on , updated
Stable releases for this project are covered by the security advisory policy.
There are currently no supported stable releases.
