function _fullcalendar_view_use_cdn in Fullcalendar View 5.x
Same name and namespace in other branches
- 6.x fullcalendar_view.module \_fullcalendar_view_use_cdn()
Replace local library with CDN.
Parameters
array $libraries: The libraries array.
string $library_name: The library name.
string $type: The library type.
bool $replace_local: Force to replace local libraries with CDN.
Return value
array The new library array (CDN)
1 call to _fullcalendar_view_use_cdn()
- fullcalendar_view_library_info_alter in ./
fullcalendar_view.module - Implements hook_library_info_alter().
File
- ./
fullcalendar_view.module, line 97 - Full Canlendar Views module help and theme functions.
Code
function _fullcalendar_view_use_cdn(array $libraries, $library_name, $type, $replace_local = FALSE) {
if (isset($libraries[$library_name])) {
if (isset($libraries[$library_name][$type]) && isset($libraries[$library_name]['cdn'])) {
$library_array = [];
$updated = FALSE;
// CSS library has a sub-array called component.
if ($type === 'css') {
if (isset($libraries[$library_name][$type]['component'])) {
$local_library = $libraries[$library_name][$type]['component'];
}
else {
return FALSE;
}
}
else {
// Local js library.
$local_library = $libraries[$library_name][$type];
}
foreach ($local_library as $key => $value) {
if (!file_exists(DRUPAL_ROOT . $key) || $replace_local) {
// The js file doesn't exist.
// Replace it with remote cdn.
$path = explode('/', $key);
$end = count($path);
$plugin_url = $path[$end - 2] . '@' . $libraries[$library_name]['version'] . '/' . $path[$end - 1];
$library_array[$libraries[$library_name]['cdn'] . $plugin_url] = $value;
$updated = TRUE;
}
else {
$library_array[$key] = $value;
}
}
}
}
return empty($updated) ? FALSE : $library_array;
}