function libraries_prepare_files in Libraries API 7.3
Same name and namespace in other branches
- 8.3 libraries.module \libraries_prepare_files()
- 7.2 libraries.module \libraries_prepare_files()
Library info callback to make all 'files' properties consistent.
This turns libraries' file information declared as e.g.
$library['files']['js'] = array(
'example_1.js',
'example_2.js',
);
into
$library['files']['js'] = array(
'example_1.js' => array(),
'example_2.js' => array(),
);
It does the same for the 'integration files' property.
Parameters
$library: An associative array of library information or a part of it, passed by reference.
$version: If the library information belongs to a specific version, the version string. NULL otherwise.
$variant: If the library information belongs to a specific variant, the variant name. NULL otherwise.
See also
1 call to libraries_prepare_files()
1 string reference to 'libraries_prepare_files'
- libraries_info_defaults in ./
libraries.module - Applies default properties to a library definition.
File
- ./
libraries.module, line 294 - External library handling for Drupal modules.
Code
function libraries_prepare_files(&$library, $version = NULL, $variant = NULL) {
// Both the 'files' property and the 'integration files' property contain file
// declarations, and we want to make both consistent.
$file_types = array();
if (isset($library['files'])) {
$file_types[] =& $library['files'];
}
if (isset($library['integration files'])) {
// Integration files are additionally keyed by module.
foreach ($library['integration files'] as &$integration_files) {
$file_types[] =& $integration_files;
}
}
foreach ($file_types as &$files) {
// Go through all supported types of files.
foreach (array(
'js',
'css',
'php',
) as $type) {
if (isset($files[$type])) {
foreach ($files[$type] as $key => $value) {
// Unset numeric keys and turn the respective values into keys.
if (is_numeric($key)) {
$files[$type][$value] = array();
unset($files[$type][$key]);
}
}
}
}
}
}