You are here

function js_get_callback in JS Callback Handler 7.2

Provides callback information provided by modules.

Parameters

string $module: The module name the callback belongs to.

string $callback: The callback name.

bool $reset: For internal use only: Whether to force the stored list of hook implementations to be regenerated (such as after enabling a new module, before processing hook_enable).

Return value

array|bool If $module or $callback are provided the info array for the specified callback is returned, FALSE if the specified callback is not defined. If $module is provided, all the callbacks for the specified module is returned, FALSE if specified module is not defined. If no parameters are provided, all modules that provide callback information is returned, FALSE if no callbacks are defined.

4 calls to js_get_callback()
js_custom_theme in ./js.module
Implements hook_custom_theme().
js_execute_request in ./js.module
Loads the requested module and executes the requested callback.
js_pre_render_element in ./js.module
Generic #pre_render callback.
js_process_autocomplete in ./js.module
Autocomplete #process callback.

File

./js.module, line 929
JavaScript callback handler module.

Code

function js_get_callback($module = NULL, $callback = NULL, $reset = FALSE) {
  global $_js;

  // Use the advanced drupal_static() pattern, since this has the potential to
  // be called quite often on a single page request.
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['callbacks'] =& drupal_static(__FUNCTION__);
  }
  $callbacks =& $drupal_static_fast['callbacks'];

  // Populate callbacks. Using cache if possible or rebuild if necessary.
  if ($reset || !isset($callbacks)) {
    $cid = 'js:callbacks';
    if (!$reset && ($cache = cache_get($cid)) && $cache->data) {
      $callbacks = $cache->data;
    }
    else {

      // If we get to this point, this is the first time this is being run
      // after a cache clear. This single request may take longer, but Drupal
      // must be fully bootstrapped to detect all hook implementations.
      if ($_js) {
        js_bootstrap(DRUPAL_BOOTSTRAP_FULL);
      }
      foreach (module_implements('js_info', FALSE, $reset) as $_module) {
        $results = module_invoke($_module, 'js_info');

        // Iterate over each module and retrieve the callback info.
        foreach ($results as $_callback => $info) {
          $callbacks[$_module][$_callback] = (array) $info;

          // Provide default if module didn't provide them.
          $callbacks[$_module][$_callback] += array(
            'access arguments' => array(),
            'access callback' => FALSE,
            'bootstrap' => DRUPAL_BOOTSTRAP_DATABASE,
            'cache' => TRUE,
            // Provide a standard function name to use if none is provided.
            'callback function' => $_module . '_js_callback_' . $_callback,
            'callback arguments' => array(),
            'capture' => TRUE,
            'delivery callback' => 'js_deliver_json',
            'dependencies' => array(),
            'includes' => array(),
            'lang' => FALSE,
            'load arguments' => array(),
            'methods' => array(
              'POST',
            ),
            'module' => $_module,
            'process request' => TRUE,
            'skip init' => FALSE,
            'token' => TRUE,
            'xhprof' => FALSE,
            'xss' => TRUE,
          );
        }
      }

      // Invokes hook_js_info_alter(). Allow modules to alter the callback
      // info before it's cached in the database.
      drupal_alter('js_info', $callbacks);
      cache_set($cid, $callbacks);
    }
  }

  // Return a specific callback for a module.
  if (isset($module) && isset($callback)) {
    return !empty($callbacks[$module][$callback]) ? $callbacks[$module][$callback] : FALSE;
  }
  elseif (isset($module)) {
    return !empty($callbacks[$module]) ? $callbacks[$module] : FALSE;
  }

  // Return all callbacks implemented by any module.
  return !empty($callbacks) ? $callbacks : FALSE;
}