function js_callback_bootstrap in JS Callback Handler 7.2
Bootstraps Drupal to the correct level based on callback info.
Parameters
array $info: The callback info array, passed by reference.
Throws
Exception
See also
1 call to js_callback_bootstrap()
- js_callback_execute in includes/
callback.inc - Execute a callback.
File
- includes/
callback.inc, line 71 - callback.inc
Code
function js_callback_bootstrap(array &$info) {
global $_js;
// Replace integer based arguments with corresponding value from path.
foreach (array(
'access',
'callback',
) as $type) {
foreach ($info["{$type} arguments"] as $key => $value) {
// Numeric argument exists, replace it.
if (is_int($value) && !empty($_js['args'][$value])) {
$info["{$type} arguments"][$key] = check_plain($_js['args'][$value]);
}
elseif (is_int($value)) {
unset($info["{$type} arguments"][$key]);
}
}
}
// Load a MODULE.js.inc file, if it exists.
module_load_include('inc', $info['module'], $info['module'] . '.js');
// If the callback function is located in another file, load that file.
$path = !empty($info['path']) ? $info['path'] : drupal_get_path('module', $info['module']);
if (isset($info['file']) && ($filepath = $path . '/' . $info['file']) && file_exists($filepath)) {
require_once $filepath;
}
// The following mimics the behavior of _drupal_bootstrap_full().
// The difference is that not all modules and includes are loaded.
if (js_bootstrap($info['bootstrap']) < DRUPAL_BOOTSTRAP_FULL) {
// If "access callback" isn't passed, but "access arguments" is,
// default to using "user_access" and bootstrap Drupal to at least
// DRUPAL_BOOTSTRAP_SESSION and ensure the user module has loaded.
if (empty($info['access callback']) && !empty($info['access arguments'])) {
js_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
if (!in_array('user', $info['dependencies'])) {
$info['dependencies'][] = 'user';
}
$info['access callback'] = 'user_access';
}
// If language is enabled or a language prefix was detected and site is
// multilingual, bootstrap at least to DRUPAL_BOOTSTRAP_LANGUAGE and ensure
// the required modules are enabled.
if (!empty($info['lang']) || $_js['lang']) {
if (!in_array('user', $info['dependencies'])) {
$info['dependencies'][] = 'user';
}
if (!in_array('path', $info['includes'])) {
$info['includes'][] = 'path';
}
// Boot at least DRUPAL_BOOTSTRAP_VARIABLES to ensure
// drupal_multilingual() works.
js_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);
if (drupal_multilingual()) {
js_bootstrap(DRUPAL_BOOTSTRAP_LANGUAGE);
}
}
// Load required include files based on the callback.
if (isset($info['includes']) && is_array($info['includes'])) {
foreach ($info['includes'] as $include) {
$file = "./includes/{$include}.inc";
// Check if base includes are overwritten.
if (isset($GLOBALS['conf'][$include . '_inc'])) {
$file = $GLOBALS['conf'][$include . '_inc'];
}
if (file_exists($file)) {
require_once $file;
}
}
}
// Detect string handling method.
unicode_check();
// Undo magic quotes.
fix_gpc_magic();
// Create an associative array with weights as values.
$module_info = array(
'filename' => NULL,
);
$modules = array(
$info['module'] => $module_info,
);
foreach ($info['dependencies'] as $dependency) {
$modules[$dependency] = $module_info;
}
// Reset module list and load them.
$module_list = module_list(FALSE, TRUE, FALSE, $modules);
foreach ($module_list as $module) {
drupal_load('module', $module);
}
// Make sure all stream wrappers are registered.
file_get_stream_wrappers();
// Ensure the language variable is set, if not it might cause problems
// (e.g. entity info).
global $language;
if (!isset($language)) {
$language = language_default();
$types = language_types();
foreach ($types as $type) {
$GLOBALS[$type] = $language;
}
}
// Invoke implementations of hook_init() if the callback doesn't indicate it
// should be skipped.
if (empty($info['skip init'])) {
// Do not use module_invoke_all() because it will load DB cached data for
// modules that implement the hook.
foreach ($module_list as $module) {
module_invoke($module, 'init');
}
}
// At this point in the execution flow it is safe to allow our cache handler
// to perform a full bootstrap in case of cache misses.
if ($info['cache']) {
JsProxyCache::setFullBootstrapAllowed(TRUE);
}
}
}