function _webform_library_info_alter_recursive in Webform 8.5
Same name and namespace in other branches
- 6.x includes/webform.libraries.inc \_webform_library_info_alter_recursive()
Recursive through a webform library.
Parameters
array $library: A webform library defined in webform.libraries.yml.
array $cdn: A associative array of library paths mapped to CDN URL.
1 call to _webform_library_info_alter_recursive()
- webform_library_info_alter in includes/
webform.libraries.inc - Implements hook_library_info_alter().
File
- includes/
webform.libraries.inc, line 135 - Webform libraries.
Code
function _webform_library_info_alter_recursive(array &$library, array $cdn) {
foreach ($library as $key => &$value) {
// CSS and JS files and listed in associative arrays keyed via string.
if (!is_string($key) || !is_array($value)) {
continue;
}
// Ignore the CDN's associative array.
if ($key === 'cdn') {
continue;
}
// Replace the CDN sources (i.e. /library/*) with the CDN URL destination
// (https://cdnjs.cloudflare.com/ajax/libs/*).
foreach ($cdn as $source => $destination) {
if (strpos($key, $source) === 0) {
$uri = str_replace($source, $destination, $key);
$library[$uri] = $value;
$library[$uri]['type'] = 'external';
unset($library[$key]);
break;
}
}
// Recurse downward to find nested libraries.
_webform_library_info_alter_recursive($value, $cdn);
}
}