function libraries_prepare_files in Libraries API 8.3
Same name and namespace in other branches
- 7.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.
Deprecated
Will be removed before a stable Drupal 8 release. Please use the new library load and managment concepts described at: https://www.drupal.org/node/2170763
See also
1 call to libraries_prepare_files()
- LibrariesUnitTest::testLibrariesPrepareFiles in src/
Tests/ LibrariesUnitTest.php - Tests 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 = [];
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 ([
'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] = [];
unset($files[$type][$key]);
}
}
}
}
}
}