diff --git a/libraries.api.php b/libraries.api.php index 859e6023eb4529bcdb3731fefc7a44971744aabe..7e127ae6514284cd7f777647c31ebe9d1e411d02 100644 --- a/libraries.api.php +++ b/libraries.api.php @@ -341,7 +341,7 @@ function hook_libraries_info() { // This array key lets Libraries API search for 'sites/all/libraries/example' // directory, which should contain the entire, original extracted library. - $libraries['example'] = array( + $libraries['example'] = [ // Only used in administrative UI of Libraries API. 'name' => 'Example library', 'vendor url' => 'http://example.com', @@ -353,53 +353,53 @@ function hook_libraries_info() { 'version callback' => 'mymodule_get_version', // Specify arguments for the version callback. By default, // libraries_get_version() takes a named argument array: - 'version arguments' => array( + 'version arguments' => [ 'file' => 'docs/CHANGELOG.txt', 'pattern' => '@version\s+([0-9a-zA-Z\.-]+)@', 'lines' => 5, 'cols' => 20, - ), + ], // Default list of files of the library to load. Important: Only specify // third-party files belonging to the library here, not integration files of // your module. - 'files' => array( + 'files' => [ // 'js' and 'css' follow the syntax of hook_library(), but file paths are // relative to the library path. - 'js' => array( + 'js' => [ 'exlib.js', 'gadgets/foo.js', - ), - 'css' => array( + ], + 'css' => [ 'lib_style.css', 'skin/example.css', - ), + ], // For PHP libraries, specify include files here, still relative to the // library path. - 'php' => array( + 'php' => [ 'exlib.php', 'exlib.inc', - ), - ), + ], + ], // Optional: Specify alternative variants of the library, if available. - 'variants' => array( + 'variants' => [ // All properties defined for 'minified' override top-level properties. - 'minified' => array( - 'files' => array( - 'js' => array( + 'minified' => [ + 'files' => [ + 'js' => [ 'exlib.min.js', 'gadgets/foo.min.js', - ), - 'css' => array( + ], + 'css' => [ 'lib_style.css', 'skin/example.css', - ), - ), + ], + ], 'variant callback' => 'mymodule_check_variant', - 'variant arguments' => array( + 'variant arguments' => [ 'variant' => 'minified', - ), - ), - ), + ], + ], + ], // Optional, but usually required: Override top-level properties for later // versions of the library. The properties of the minimum version that is // matched override the top-level properties. Note: @@ -409,85 +409,85 @@ function hook_libraries_info() { // defaults. // - The array keys have to be strings, as PHP does not support floats for // array keys. - 'versions' => array( - '2' => array( - 'files' => array( - 'js' => array('exlib.js'), - 'css' => array('exlib_style.css'), - ), - ), - '3.0' => array( - 'files' => array( - 'js' => array('exlib.js'), - 'css' => array('lib_style.css'), - ), - ), - '3.2' => array( - 'files' => array( - 'js' => array( + 'versions' => [ + '2' => [ + 'files' => [ + 'js' => ['exlib.js'], + 'css' => ['exlib_style.css'], + ], + ], + '3.0' => [ + 'files' => [ + 'js' => ['exlib.js'], + 'css' => ['lib_style.css'], + ], + ], + '3.2' => [ + 'files' => [ + 'js' => [ 'exlib.js', 'gadgets/foo.js', - ), - 'css' => array( + ], + 'css' => [ 'lib_style.css', 'skin/example.css', - ), - ), - ), - ), + ], + ], + ], + ], // Optional: Register files to auto-load for your module. All files must be // keyed by module, and follow the syntax of the 'files' property. - 'integration files' => array( - 'mymodule' => array( - 'js' => array('ex_lib.inc'), - ), - ), + 'integration files' => [ + 'mymodule' => [ + 'js' => ['ex_lib.inc'], + ], + ], // Optionally register callbacks to apply to the library during different // stages of its lifetime ('callback groups'). - 'callbacks' => array( + 'callbacks' => [ // Used to alter the info associated with the library. - 'info' => array( + 'info' => [ 'mymodule_example_libraries_info_callback', - ), + ], // Called before detecting the given library. - 'pre-detect' => array( + 'pre-detect' => [ 'mymodule_example_libraries_predetect_callback', - ), + ], // Called after detecting the library. - 'post-detect' => array( + 'post-detect' => [ 'mymodule_example_libraries_postdetect_callback', - ), + ], // Called before the library is loaded. - 'pre-load' => array( + 'pre-load' => [ 'mymodule_example_libraries_preload_callback', - ), + ], // Called after the library is loaded. - 'post-load' => array( + 'post-load' => [ 'mymodule_example_libraries_postload_callback', - ), - ), - ); + ], + ], + ]; // A very simple library. No changing APIs (hence, no versions), no variants. // Expected to be extracted into 'sites/all/libraries/simple'. - $libraries['simple'] = array( + $libraries['simple'] = [ 'name' => 'Simple library', 'vendor url' => 'http://example.com/simple', 'download url' => 'http://example.com/simple', - 'version arguments' => array( + 'version arguments' => [ 'file' => 'readme.txt', // Best practice: Document the actual version strings for later reference. // 1.x: Version 1.0 'pattern' => '/Version (\d+)/', 'lines' => 5, - ), - 'files' => array( - 'js' => array('simple.js'), - ), - ); + ], + 'files' => [ + 'js' => ['simple.js'], + ], + ]; // A library that (naturally) evolves over time with API changes. - $libraries['tinymce'] = array( + $libraries['tinymce'] = [ 'name' => 'TinyMCE', 'vendor url' => 'http://tinymce.moxiecode.com', 'download url' => 'http://tinymce.moxiecode.com/download.php', @@ -495,7 +495,7 @@ function hook_libraries_info() { // The regular expression catches two parts (the major and the minor // version), which libraries_get_version() doesn't allow. 'version callback' => 'tinymce_get_version', - 'version arguments' => array( + 'version arguments' => [ // It can be easier to parse the first characters of a minified file // instead of doing a multi-line pattern matching in a source file. See // 'lines' and 'cols' below. @@ -506,61 +506,61 @@ function hook_libraries_info() { 'pattern' => '@majorVersion[=:]["\'](\d).+?minorVersion[=:]["\']([\d\.]+)@', 'lines' => 1, 'cols' => 100, - ), - 'versions' => array( - '2.1' => array( - 'files' => array( - 'js' => array('tiny_mce.js'), - ), - 'variants' => array( - 'source' => array( - 'files' => array( - 'js' => array('tiny_mce_src.js'), - ), - ), - ), - 'integration files' => array( - 'wysiwyg' => array( - 'js' => array('editors/js/tinymce-2.js'), - 'css' => array('editors/js/tinymce-2.css'), - ), - ), - ), + ], + 'versions' => [ + '2.1' => [ + 'files' => [ + 'js' => ['tiny_mce.js'], + ], + 'variants' => [ + 'source' => [ + 'files' => [ + 'js' => ['tiny_mce_src.js'], + ], + ], + ], + 'integration files' => [ + 'wysiwyg' => [ + 'js' => ['editors/js/tinymce-2.js'], + 'css' => ['editors/js/tinymce-2.css'], + ], + ], + ], // Definition used if 3.1 or above is detected. - '3.1' => array( + '3.1' => [ // Does not support JS aggregation. - 'files' => array( - 'js' => array( - 'tiny_mce.js' => array('preprocess' => FALSE), - ), - ), - 'variants' => array( + 'files' => [ + 'js' => [ + 'tiny_mce.js' => ['preprocess' => FALSE], + ], + ], + 'variants' => [ // New variant leveraging jQuery. Not stable yet; therefore not the // default variant. - 'jquery' => array( - 'files' => array( - 'js' => array( - 'tiny_mce_jquery.js' => array('preprocess' => FALSE), - ), - ), - ), - 'source' => array( - 'files' => array( - 'js' => array( - 'tiny_mce_src.js' => array('preprocess' => FALSE), - ), - ), - ), - ), - 'integration files' => array( - 'wysiwyg' => array( - 'js' => array('editors/js/tinymce-3.js'), - 'css' => array('editors/js/tinymce-3.css'), - ), - ), - ), - ), - ); + 'jquery' => [ + 'files' => [ + 'js' => [ + 'tiny_mce_jquery.js' => ['preprocess' => FALSE], + ], + ], + ], + 'source' => [ + 'files' => [ + 'js' => [ + 'tiny_mce_src.js' => ['preprocess' => FALSE], + ], + ], + ], + ], + 'integration files' => [ + 'wysiwyg' => [ + 'js' => ['editors/js/tinymce-3.js'], + 'css' => ['editors/js/tinymce-3.css'], + ], + ], + ], + ], + ]; return $libraries; } @@ -577,9 +577,9 @@ function hook_libraries_info() { * @deprecated Will be removed before a stable Drupal 8 release. */ function hook_libraries_info_alter(&$libraries) { - $files = array( - 'php' => array('example_module.php_spellchecker.inc'), - ); + $files = [ + 'php' => ['example_module.php_spellchecker.inc'], + ]; $libraries['php_spellchecker']['integration files']['example_module'] = $files; } @@ -605,5 +605,5 @@ function hook_libraries_info_alter(&$libraries) { function hook_libraries_info_file_paths() { // Taken from the Libraries test module, which needs to specify the path to // the test library. - return array(drupal_get_path('module', 'libraries_test') . '/example'); + return [drupal_get_path('module', 'libraries_test') . '/example']; } diff --git a/libraries.drush.inc b/libraries.drush.inc index 3d9f7cd429584aee94f5843f5311fa9408ca87c7..fe9003b7aed420cee5b2b2f6e23c3aa98a7ad2ca 100644 --- a/libraries.drush.inc +++ b/libraries.drush.inc @@ -11,18 +11,20 @@ use Drupal\Component\Utility\Unicode; * Implements hook_drush_command(). */ function libraries_drush_command() { - $items['libraries-list'] = array( + $items['libraries-list'] = [ 'callback' => 'libraries_drush_list', 'description' => dt('Lists registered library information.'), 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL, - ); - /**$items['libraries-download'] = array( - 'callback' => 'libraries_drush_download', - 'description' => dt('Downloads a registered library into the libraries directory for the active site.'), - 'arguments' => array( - 'name' => dt('The internal name of the registered library.'), - ), - );*/ + ]; + /* + $items['libraries-download'] = array[ + 'callback' => 'libraries_drush_download', + 'description' => dt('Downloads a registered library into the libraries directory for the active site.'), + 'arguments' => [ + 'name' => dt('The internal name of the registered library.'), + ], + ]; + */ return $items; } @@ -61,7 +63,7 @@ function libraries_drush_invalidate_cache() { * Lists registered library information. */ function libraries_drush_list() { - $libraries = array(); + $libraries = []; foreach (\Drupal::service('libraries.manager')->info() as $name => $info) { $libraries[$name] = \Drupal::service('libraries.manager')->getLibrary($name); } @@ -72,16 +74,22 @@ function libraries_drush_list() { } else { - $rows = array(); + $rows = []; // drush_print_table() automatically treats the first row as the header, if // $header is TRUE. - $rows[] = array(dt('Name'), dt('Status'), dt('Version'), dt('Variants'), dt('Dependencies')); + $rows[] = [ + dt('Name'), + dt('Status'), + dt('Version'), + dt('Variants'), + dt('Dependencies'), + ]; foreach ($libraries as $name => $library) { $status = ($library['installed'] ? dt('OK') : Unicode::ucfirst($library['error'])); $version = (($library['installed'] && !empty($library['version'])) ? $library['version'] : '-'); // Only list installed variants. - $variants = array(); + $variants = []; foreach ($library['variants'] as $variant_name => $variant) { if ($variant['installed']) { $variants[] = $variant_name; @@ -91,11 +99,11 @@ function libraries_drush_list() { $dependencies = (!empty($library['dependencies']) ? implode(', ', $library['dependencies']) : '-'); - $rows[] = array($name, $status, $version, $variants, $dependencies); + $rows[] = [$name, $status, $version, $variants, $dependencies]; } // Make the possible values for the 'Status' column and the 'Version' header // wrap nicely. - $widths = array(0, 12, 7, 0, 0); + $widths = [0, 12, 7, 0, 0]; drush_print_table($rows, TRUE, $widths); } } @@ -103,7 +111,7 @@ function libraries_drush_list() { /** * Downloads a library. * - * @param $name + * @param string $name * The internal name of the library to download. */ function libraries_drush_download($name) { @@ -126,7 +134,7 @@ function libraries_drush_download($name) { // Create the path if it does not exist. if (!is_dir($path)) { drush_op('mkdir', $path); - drush_log(dt('Directory @path was created', array('@path' => $path)), 'notice'); + drush_log(dt('Directory @path was created', ['@path' => $path]), 'notice'); } // Set the directory to the download location. @@ -136,34 +144,34 @@ function libraries_drush_download($name) { $filename = basename(COLORBOX_DOWNLOAD_URI); $dirname = basename(COLORBOX_DOWNLOAD_URI, '.zip'); - // Remove any existing Colorbox plugin directory + // Remove any existing Colorbox plugin directory. if (is_dir($dirname)) { - drush_log(dt('A existing Colorbox plugin was overwritten at @path', array('@path' => $path)), 'notice'); + drush_log(dt('A existing Colorbox plugin was overwritten at @path', ['@path' => $path]), 'notice'); } - // Remove any existing Colorbox plugin zip archive + // Remove any existing Colorbox plugin zip archive. if (is_file($filename)) { drush_op('unlink', $filename); } - // Download the zip archive - if (!drush_shell_exec('wget '. COLORBOX_DOWNLOAD_URI)) { - drush_shell_exec('curl -O '. COLORBOX_DOWNLOAD_URI); + // Download the zip archive. + if (!drush_shell_exec('wget ' . COLORBOX_DOWNLOAD_URI)) { + drush_shell_exec('curl -O ' . COLORBOX_DOWNLOAD_URI); } if (is_file($filename)) { - // Decompress the zip archive - drush_shell_exec('unzip -qq -o '. $filename); - // Remove the zip archive + // Decompress the zip archive. + drush_shell_exec('unzip -qq -o ' . $filename); + // Remove the zip archive. drush_op('unlink', $filename); } // Set working directory back to the previous working directory. chdir($olddir); - if (is_dir($path .'/'. $dirname)) { - drush_log(dt('Colorbox plugin has been downloaded to @path', array('@path' => $path)), 'success'); + if (is_dir($path . '/' . $dirname)) { + drush_log(dt('Colorbox plugin has been downloaded to @path', ['@path' => $path]), 'success'); } else { - drush_log(dt('Drush was unable to download the Colorbox plugin to @path', array('@path' => $path)), 'error'); + drush_log(dt('Drush was unable to download the Colorbox plugin to @path', ['@path' => $path]), 'error'); } } diff --git a/libraries.module b/libraries.module index 7028d2f9777d097f0814f2a75730a931c5b145db..2a8b623bc1f9160528eaeda28f59a741b08dca22 100644 --- a/libraries.module +++ b/libraries.module @@ -108,7 +108,7 @@ function libraries_get_path($name, $base_path = FALSE) { * https://www.drupal.org/node/2170763 */ function libraries_get_libraries() { - $searchdir = array(); + $searchdir = []; $config = DrupalKernel::findSitePath(\Drupal::request()); // @todo core/libraries @@ -131,8 +131,8 @@ function libraries_get_libraries() { $searchdir[] = "$config/libraries"; // Retrieve list of directories. - $directories = array(); - $nomask = array('CVS'); + $directories = []; + $nomask = ['CVS']; foreach ($searchdir as $dir) { if (is_dir($dir) && $handle = opendir($dir)) { while (FALSE !== ($file = readdir($handle))) { @@ -172,20 +172,20 @@ function libraries_scan_info_files() { $config = DrupalKernel::findSitePath(\Drupal::request()); // Build a list of directories. - $directories = \Drupal::moduleHandler()->invokeAll('libraries_info_file_paths', $args = array()); + $directories = \Drupal::moduleHandler()->invokeAll('libraries_info_file_paths', $args = []); $directories[] = "$profile/libraries"; $directories[] = 'sites/all/libraries'; $directories[] = 'libraries'; $directories[] = "$config/libraries"; // Scan for info files. - $files = array(); + $files = []; foreach ($directories as $dir) { if (file_exists($dir)) { - $files = array_merge($files, \Drupal::service('file_system')->scanDirectory($dir, '@^[a-z0-9._-]+\.libraries\.info\.yml$@', array( + $files = array_merge($files, \Drupal::service('file_system')->scanDirectory($dir, '@^[a-z0-9._-]+\.libraries\.info\.yml$@', [ 'key' => 'name', 'recurse' => FALSE, - ))); + ])); } } @@ -294,7 +294,7 @@ function libraries_traverse_library(&$library, $callback) { 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(); + $file_types = []; if (isset($library['files'])) { $file_types[] = &$library['files']; } @@ -306,12 +306,12 @@ function libraries_prepare_files(&$library, $version = NULL, $variant = NULL) { } foreach ($file_types as &$files) { // Go through all supported types of files. - foreach (array('js', 'css', 'php') as $type) { + 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] = array(); + $files[$type][$value] = []; unset($files[$type][$key]); } } @@ -351,19 +351,19 @@ function libraries_detect_dependencies(&$library, $version = NULL, $variant = NU if (!$info['installed']) { $library['installed'] = FALSE; $library['error'] = 'missing dependency'; - $library['error message'] = t('The %dependency library, which the %library library depends on, is not installed.', array( + $library['error message'] = t('The %dependency library, which the %library library depends on, is not installed.', [ '%dependency' => $dependency['name'], '%library' => $library['name'], - )); + ]); } elseif (!$dependency->isCompatible($info['version'])) { $library['installed'] = FALSE; $library['error'] = 'incompatible dependency'; - $library['error message'] = t('The version %dependency_version of the %dependency library is not compatible with the %library library.', array( + $library['error message'] = t('The version %dependency_version of the %dependency library is not compatible with the %library library.', [ '%dependency_version' => $info['version'], '%dependency' => $info['name'], '%library' => $library['name'], - )); + ]); } // Remove the version string from the dependency, so libraries_load() can @@ -401,7 +401,7 @@ function &libraries_info($name = NULL) { $libraries = &drupal_static(__FUNCTION__); if (!isset($libraries)) { - $libraries = array(); + $libraries = []; // Gather information from hook_libraries_info(). $module_handler = \Drupal::moduleHandler(); foreach ($module_handler->getImplementations('libraries_info') as $module) { @@ -414,13 +414,13 @@ function &libraries_info($name = NULL) { // @see drupal_alter() global $theme, $base_theme_info; if (isset($theme)) { - $theme_keys = array(); + $theme_keys = []; foreach ($base_theme_info as $base) { $theme_keys[] = $base->name; } $theme_keys[] = $theme; foreach ($theme_keys as $theme_key) { - $function = $theme_key . '_' . 'libraries_info'; + $function = $theme_key . '_libraries_info'; if (function_exists($function)) { foreach ($function() as $machine_name => $properties) { $properties['theme'] = $theme_key; @@ -440,7 +440,7 @@ function &libraries_info($name = NULL) { // 'type' key in info files. We therefore use Symfony's YAML parser // directly. // @todo Consider creating a dedicating InfoParser for library info files - // similar to \Drupal\Core\Extension\InfoParser + // similar to \Drupal\Core\Extension\InfoParser. $parser = new Parser(); foreach (libraries_scan_info_files() as $machine_name => $file) { $properties = $parser->parse(file_get_contents($file->uri)); @@ -487,7 +487,7 @@ function &libraries_info($name = NULL) { * https://www.drupal.org/node/2170763 */ function libraries_info_defaults(&$library, $name) { - $library += array( + $library += [ 'machine name' => $name, 'name' => $name, 'vendor url' => '', @@ -495,21 +495,21 @@ function libraries_info_defaults(&$library, $name) { 'path' => '', 'library path' => NULL, 'version callback' => 'libraries_get_version', - 'version arguments' => array(), - 'files' => array(), - 'dependencies' => array(), - 'variants' => array(), - 'versions' => array(), - 'integration files' => array(), - 'callbacks' => array(), - ); - $library['callbacks'] += array( - 'info' => array(), - 'pre-detect' => array(), - 'post-detect' => array(), - 'pre-load' => array(), - 'post-load' => array(), - ); + 'version arguments' => [], + 'files' => [], + 'dependencies' => [], + 'variants' => [], + 'versions' => [], + 'integration files' => [], + 'callbacks' => [], + ]; + $library['callbacks'] += [ + 'info' => [], + 'pre-detect' => [], + 'post-detect' => [], + 'pre-load' => [], + 'post-load' => [], + ]; // Add our own callbacks before any others. array_unshift($library['callbacks']['info'], 'libraries_prepare_files'); @@ -564,9 +564,9 @@ function libraries_detect($name) { } if ($library['library path'] === FALSE || !file_exists($library['library path'])) { $library['error'] = 'not found'; - $library['error message'] = t('The %library library could not be found.', array( + $library['error message'] = t('The %library library could not be found.', [ '%library' => $library['name'], - )); + ]); return $library; } @@ -579,16 +579,16 @@ function libraries_detect($name) { // indexed array of multiple parameters. if (isset($library['version arguments'][0])) { // Add the library as the first argument. - $library['version'] = call_user_func_array($library['version callback'], array_merge(array($library), $library['version arguments'])); + $library['version'] = call_user_func_array($library['version callback'], array_merge([$library], $library['version arguments'])); } else { $library['version'] = $library['version callback']($library, $library['version arguments']); } if (empty($library['version'])) { $library['error'] = 'not detected'; - $library['error message'] = t('The version of the %library library could not be detected.', array( + $library['error message'] = t('The version of the %library library could not be detected.', [ '%library' => $library['name'], - )); + ]); return $library; } } @@ -604,10 +604,10 @@ function libraries_detect($name) { } if (!$version) { $library['error'] = 'not supported'; - $library['error message'] = t('The installed version %version of the %library library is not supported.', array( + $library['error message'] = t('The installed version %version of the %library library is not supported.', [ '%version' => $library['version'], '%library' => $library['name'], - )); + ]); return $library; } @@ -628,18 +628,19 @@ function libraries_detect($name) { // We support both a single parameter, which is an associative array, // and an indexed array of multiple parameters. if (isset($variant['variant arguments'][0])) { - // Add the library as the first argument, and the variant name as the second. - $variant['installed'] = call_user_func_array($variant['variant callback'], array_merge(array($library, $variant_name), $variant['variant arguments'])); + // Add the library as the first argument, and the variant name as the + // second. + $variant['installed'] = call_user_func_array($variant['variant callback'], array_merge([$library, $variant_name], $variant['variant arguments'])); } else { $variant['installed'] = $variant['variant callback']($library, $variant_name, $variant['variant arguments']); } if (!$variant['installed']) { $variant['error'] = 'not found'; - $variant['error message'] = t('The %variant variant of the %library library could not be found.', array( + $variant['error message'] = t('The %variant variant of the %library library could not be found.', [ '%variant' => $variant_name, '%library' => $library['name'], - )); + ]); } } } @@ -679,7 +680,7 @@ function libraries_detect($name) { * https://www.drupal.org/node/2170763 */ function libraries_load($name, $variant = NULL) { - $loaded = &drupal_static(__FUNCTION__, array()); + $loaded = &drupal_static(__FUNCTION__, []); if (!isset($loaded[$name])) { $library = \Drupal::cache('libraries')->get($name); @@ -696,7 +697,7 @@ function libraries_load($name, $variant = NULL) { // Ensure that the $variant key exists, and if it does not, set its // 'installed' property to FALSE by default. This will prevent the loading // of the library files below. - $library['variants'] += array($variant => array('installed' => FALSE)); + $library['variants'] += [$variant => ['installed' => FALSE]]; $library = array_merge($library, $library['variants'][$variant]); } // Regardless of whether a specific variant was requested or not, there can @@ -754,7 +755,7 @@ function libraries_load_files($library) { // The parameters for drupal_add_js() and drupal_add_css() require special // handling. // @see drupal_process_attached() - foreach (array('js', 'css') as $type) { + foreach (['js', 'css'] as $type) { // Given the removal of core functions like _drupal_add_js and // _drupal_add_css the logic below cannot safely be run anymore. // @see https://www.drupal.org/node/2702563 @@ -765,7 +766,7 @@ function libraries_load_files($library) { // (and only) argument. if (!is_array($options)) { $data = $options; - $options = array(); + $options = []; } // In some cases, the first parameter ($data) is an array. Arrays can't // be passed as keys in PHP, so we have to get $data from the value @@ -804,11 +805,11 @@ function libraries_load_files($library) { // Load integration files. if (!empty($library['integration files'])) { foreach ($library['integration files'] as $module => $files) { - libraries_load_files(array( + libraries_load_files([ 'files' => $files, 'path' => '', 'library path' => drupal_get_path('module', $module), - )); + ]); } } @@ -846,12 +847,12 @@ function libraries_load_files($library) { */ function libraries_get_version($library, $options) { // Provide defaults. - $options += array( + $options += [ 'file' => '', 'pattern' => '', 'lines' => 20, 'cols' => 200, - ); + ]; $file = DRUPAL_ROOT . '/' . $library['library path'] . '/' . $options['file']; if (empty($options['file']) || !file_exists($file)) { diff --git a/src/Tests/LibrariesUnitTest.php b/src/Tests/LibrariesUnitTest.php index f616a92b8ea4caa3855b53244a81fa65f2b7ed0a..8a93c5679fc11fdeab0a4410f0c2206d38662fa0 100644 --- a/src/Tests/LibrariesUnitTest.php +++ b/src/Tests/LibrariesUnitTest.php @@ -14,7 +14,7 @@ class LibrariesUnitTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = array('libraries'); + public static $modules = ['libraries']; /** * Tests libraries_get_path(). @@ -32,20 +32,20 @@ class LibrariesUnitTest extends KernelTestBase { * Tests libraries_prepare_files(). */ function testLibrariesPrepareFiles() { - $expected = array( - 'files' => array( - 'js' => array('example.js' => array()), - 'css' => array('example.css' => array()), - 'php' => array('example.php' => array()), - ), - ); - $library = array( - 'files' => array( - 'js' => array('example.js'), - 'css' => array('example.css'), - 'php' => array('example.php'), - ), - ); + $expected = [ + 'files' => [ + 'js' => ['example.js' => []], + 'css' => ['example.css' => []], + 'php' => ['example.php' => []], + ], + ]; + $library = [ + 'files' => [ + 'js' => ['example.js'], + 'css' => ['example.css'], + 'php' => ['example.php'], + ], + ]; libraries_prepare_files($library, NULL, NULL); $this->assertEqual($expected, $library, 'libraries_prepare_files() works correctly.'); } diff --git a/src/Tests/LibrariesWebTest.php b/src/Tests/LibrariesWebTest.php index f0a0da04f75ff6c0d6b32d43e12ef3f20ba301b7..be28c802bb228ee42f362e412d90311a8bc16064 100644 --- a/src/Tests/LibrariesWebTest.php +++ b/src/Tests/LibrariesWebTest.php @@ -22,7 +22,7 @@ class LibrariesWebTest extends WebTestBase { * * @var array */ - public static $modules = array('libraries', 'libraries_test'); + public static $modules = ['libraries', 'libraries_test']; /** * The URL generator used in this test. @@ -51,23 +51,23 @@ class LibrariesWebTest extends WebTestBase { /** * Tests libraries_detect_dependencies(). */ - function testLibrariesDetectDependencies() { - $library = array( + public function testLibrariesDetectDependencies() { + $library = [ 'name' => 'Example', - 'dependencies' => array('Example missing'), - ); + 'dependencies' => ['Example missing'], + ]; libraries_detect_dependencies($library); $this->assertEqual($library['error'], 'missing dependency', 'libraries_detect_dependencies() detects missing dependency'); - $error_message = t('The %dependency library, which the %library library depends on, is not installed.', array( + $error_message = t('The %dependency library, which the %library library depends on, is not installed.', [ '%dependency' => 'Example missing', '%library' => $library['name'], - )); + ]); $this->verbose("Expected:<br>$error_message"); $this->verbose('Actual:<br>' . $library['error message']); $this->assertEqual($library['error message'], $error_message, 'Correct error message for a missing dependency'); // Test versioned dependencies. $version = '1.1'; - $compatible = array( + $compatible = [ '1.1', '<=1.1', '>=1.1', @@ -80,8 +80,8 @@ class LibrariesWebTest extends WebTestBase { '>0.1', '<1.2, >1.0', '>0.1, <=1.1', - ); - $incompatible = array( + ]; + $incompatible = [ '1.2', '2.0', '<1.1', @@ -93,10 +93,10 @@ class LibrariesWebTest extends WebTestBase { '>=1.2', '<1.1, >0.9', '>=0.1, <1.1', - ); - $library = array( + ]; + $library = [ 'name' => 'Example', - ); + ]; foreach ($compatible as $version_string) { $library['dependencies'][0] = "example_dependency ($version_string)"; // libraries_detect_dependencies() is a post-detect callback, so @@ -115,11 +115,11 @@ class LibrariesWebTest extends WebTestBase { } // Instead of repeating this assertion for each version string, we just // re-use the $library variable from the foreach loop. - $error_message = t('The version %dependency_version of the %dependency library is not compatible with the %library library.', array( + $error_message = t('The version %dependency_version of the %dependency library is not compatible with the %library library.', [ '%dependency_version' => $version, '%dependency' => 'Example dependency', '%library' => $library['name'], - )); + ]); $this->verbose("Expected:<br>$error_message"); $this->verbose('Actual:<br>' . $library['error message']); $this->assertEqual($library['error message'], $error_message, 'Correct error message for an incompatible dependency'); @@ -128,12 +128,14 @@ class LibrariesWebTest extends WebTestBase { /** * Tests libraries_scan_info_files(). */ - function testLibrariesScanInfoFiles() { - $expected = array('example_info_file' => (object) array( - 'uri' => drupal_get_path('module', 'libraries') . '/tests/example/example_info_file.libraries.info.yml', - 'filename' => 'example_info_file.libraries.info.yml', - 'name' => 'example_info_file.libraries.info', - )); + public function testLibrariesScanInfoFiles() { + $expected = [ + 'example_info_file' => (object) [ + 'uri' => drupal_get_path('module', 'libraries') . '/tests/example/example_info_file.libraries.info.yml', + 'filename' => 'example_info_file.libraries.info.yml', + 'name' => 'example_info_file.libraries.info', + ], + ]; $actual = libraries_scan_info_files(); $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>'); $this->verbose('Actual:<pre>' . var_export($actual, TRUE) . '</pre>'); @@ -144,19 +146,19 @@ class LibrariesWebTest extends WebTestBase { /** * Tests libraries_info(). */ - function testLibrariesInfo() { + public function testLibrariesInfo() { // Test that library information is found correctly. - $expected = array( + $expected = [ 'name' => 'Example files', 'library path' => drupal_get_path('module', 'libraries') . '/tests/example', 'version' => '1', - 'files' => array( - 'js' => array('example_1.js' => array()), - 'css' => array('example_1.css' => array()), - 'php' => array('example_1.php' => array()), - ), + 'files' => [ + 'js' => ['example_1.js' => []], + 'css' => ['example_1.css' => []], + 'php' => ['example_1.php' => []], + ], 'module' => 'libraries_test', - ); + ]; libraries_info_defaults($expected, 'example_files'); $library = libraries_info('example_files'); $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>'); @@ -164,10 +166,10 @@ class LibrariesWebTest extends WebTestBase { $this->assertEqual($library, $expected, 'Library information is correctly gathered.'); // Test a library specified with an .info file gets detected. - $expected = array( + $expected = [ 'name' => 'Example info file', 'info file' => drupal_get_path('module', 'libraries') . '/tests/example/example_info_file.libraries.info.yml', - ); + ]; libraries_info_defaults($expected, 'example_info_file'); $library = libraries_info('example_info_file'); // If this module was downloaded from Drupal.org, the Drupal.org packaging @@ -182,33 +184,33 @@ class LibrariesWebTest extends WebTestBase { /** * Tests libraries_detect(). */ - function testLibrariesDetect() { + public function testLibrariesDetect() { // Test missing library. $library = libraries_detect('example_missing'); $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>'); $this->assertEqual($library['error'], 'not found', 'Missing library not found.'); - $error_message = t('The %library library could not be found.', array( + $error_message = t('The %library library could not be found.', [ '%library' => $library['name'], - )); + ]); $this->assertEqual($library['error message'], $error_message, 'Correct error message for a missing library.'); // Test unknown library version. $library = libraries_detect('example_undetected_version'); $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>'); $this->assertEqual($library['error'], 'not detected', 'Undetected version detected as such.'); - $error_message = t('The version of the %library library could not be detected.', array( + $error_message = t('The version of the %library library could not be detected.', [ '%library' => $library['name'], - )); + ]); $this->assertEqual($library['error message'], $error_message, 'Correct error message for a library with an undetected version.'); // Test unsupported library version. $library = libraries_detect('example_unsupported_version'); $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>'); $this->assertEqual($library['error'], 'not supported', 'Unsupported version detected as such.'); - $error_message = t('The installed version %version of the %library library is not supported.', array( + $error_message = t('The installed version %version of the %library library is not supported.', [ '%version' => $library['version'], '%library' => $library['name'], - )); + ]); $this->assertEqual($library['error message'], $error_message, 'Correct error message for a library with an unsupported version.'); // Test supported library version. @@ -228,21 +230,21 @@ class LibrariesWebTest extends WebTestBase { // Test a top-level files property. $library = libraries_detect('example_files'); - $files = array( - 'js' => array('example_1.js' => array()), - 'css' => array('example_1.css' => array()), - 'php' => array('example_1.php' => array()), - ); + $files = [ + 'js' => ['example_1.js' => []], + 'css' => ['example_1.css' => []], + 'php' => ['example_1.php' => []], + ]; $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>'); $this->assertEqual($library['files'], $files, 'Top-level files property works.'); // Test version-specific library files. $library = libraries_detect('example_versions'); - $files = array( - 'js' => array('example_2.js' => array()), - 'css' => array('example_2.css' => array()), - 'php' => array('example_2.php' => array()), - ); + $files = [ + 'js' => ['example_2.js' => []], + 'css' => ['example_2.css' => []], + 'php' => ['example_2.php' => []], + ]; $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>'); $this->assertEqual($library['files'], $files, 'Version-specific library files found.'); @@ -250,10 +252,10 @@ class LibrariesWebTest extends WebTestBase { $library = libraries_detect('example_variant_missing'); $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>'); $this->assertEqual($library['variants']['example_variant']['error'], 'not found', 'Missing variant not found'); - $error_message = t('The %variant variant of the %library library could not be found.', array( + $error_message = t('The %variant variant of the %library library could not be found.', [ '%variant' => 'example_variant', '%library' => 'Example variant missing', - )); + ]); $this->assertEqual($library['variants']['example_variant']['error message'], $error_message, 'Correct error message for a missing variant.'); // Test existing variant. @@ -267,7 +269,7 @@ class LibrariesWebTest extends WebTestBase { * * @todo Remove or rewrite to accomodate integration with core Libraries. */ - function _testLibrariesLoad() { + public function _testLibrariesLoad() { // Test dependencies. $library = libraries_load('example_dependency_missing'); $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>'); @@ -286,52 +288,52 @@ class LibrariesWebTest extends WebTestBase { /** * Tests the applying of callbacks. */ - function testCallbacks() { - $expected = array( + public function testCallbacks() { + $expected = [ 'name' => 'Example callback', 'library path' => drupal_get_path('module', 'libraries') . '/tests/example', 'version' => '1', - 'versions' => array( - '1' => array( - 'variants' => array( - 'example_variant' => array( + 'versions' => [ + '1' => [ + 'variants' => [ + 'example_variant' => [ 'info callback' => 'not applied', 'pre-detect callback' => 'not applied', 'post-detect callback' => 'not applied', 'pre-load callback' => 'not applied', 'post-load callback' => 'not applied', - ), - ), + ], + ], 'info callback' => 'not applied', 'pre-detect callback' => 'not applied', 'post-detect callback' => 'not applied', 'pre-load callback' => 'not applied', 'post-load callback' => 'not applied', - ), - ), - 'variants' => array( - 'example_variant' => array( + ], + ], + 'variants' => [ + 'example_variant' => [ 'info callback' => 'not applied', 'pre-detect callback' => 'not applied', 'post-detect callback' => 'not applied', 'pre-load callback' => 'not applied', 'post-load callback' => 'not applied', - ), - ), - 'callbacks' => array( - 'info' => array('_libraries_test_info_callback'), - 'pre-detect' => array('_libraries_test_pre_detect_callback'), - 'post-detect' => array('_libraries_test_post_detect_callback'), - 'pre-load' => array('_libraries_test_pre_load_callback'), - 'post-load' => array('_libraries_test_post_load_callback'), - ), + ], + ], + 'callbacks' => [ + 'info' => ['_libraries_test_info_callback'], + 'pre-detect' => ['_libraries_test_pre_detect_callback'], + 'post-detect' => ['_libraries_test_post_detect_callback'], + 'pre-load' => ['_libraries_test_pre_load_callback'], + 'post-load' => ['_libraries_test_post_load_callback'], + ], 'info callback' => 'not applied', 'pre-detect callback' => 'not applied', 'post-detect callback' => 'not applied', 'pre-load callback' => 'not applied', 'post-load callback' => 'not applied', 'module' => 'libraries_test', - ); + ]; libraries_info_defaults($expected, 'example_callback'); // Test a callback in the 'info' group. @@ -398,7 +400,7 @@ class LibrariesWebTest extends WebTestBase { * @todo Remove or rewrite to accomodate integration with core Libraries. * @see _libraries_test_load() */ - function _testLibrariesOutput() { + public function _testLibrariesOutput() { // Test loading of a simple library with a top-level files property. $this->drupalGet('libraries_test/files'); $this->assertLibraryFiles('example_1', 'File loading'); @@ -463,38 +465,38 @@ class LibrariesWebTest extends WebTestBase { * (optional) The expected file extensions of $name. Defaults to * array('js', 'css', 'php'). */ - function assertLibraryFiles($name, $label = '', $extensions = array('js', 'css', 'php')) { + public function assertLibraryFiles($name, $label = '', $extensions = ['js', 'css', 'php']) { $label = ($label !== '' ? "$label: " : ''); // Test that the wrong files are not loaded... - $names = array( + $names = [ 'example_1' => FALSE, 'example_2' => FALSE, 'example_3' => FALSE, 'example_4' => FALSE, - ); + ]; // ...and the correct ones are. $names[$name] = TRUE; // Test for the specific HTML that the different file types appear as in the // DOM. - $html = array( - 'js' => array('<script src="', '"></script>'), - 'css' => array('<link rel="stylesheet" href="', '" media="all" />'), + $html = [ + 'js' => ['<script src="', '"></script>'], + 'css' => ['<link rel="stylesheet" href="', '" media="all" />'], // PHP files do not get added to the DOM directly. // @see _libraries_test_load() - 'php' => array('<li>', '</li>'), - ); + 'php' => ['<li>', '</li>'], + ]; - $html_expected = array(); - $html_not_expected = array(); + $html_expected = []; + $html_not_expected = []; foreach ($names as $name => $expected) { foreach ($extensions as $extension) { $filepath = drupal_get_path('module', 'libraries') . "/tests/example/$name.$extension"; // JavaScript and CSS files appear as full URLs and with an appended // query string. - if (in_array($extension, array('js', 'css'))) { + if (in_array($extension, ['js', 'css'])) { $filepath = $this->urlAssembler->assemble("base://$filepath", [ 'query' => [ $this->state->get('system.css_js_query_string') ?: '0' => NULL, @@ -502,7 +504,7 @@ class LibrariesWebTest extends WebTestBase { 'absolute' => TRUE, ]); // If index.php is part of the generated URLs, we need to strip it. - //$filepath = str_replace('index.php/', '', $filepath); + // $filepath = str_replace('index.php/', '', $filepath); } list($prefix, $suffix) = $html[$extension]; $raw = $prefix . $filepath . $suffix; diff --git a/tests/modules/libraries_test/libraries_test.module b/tests/modules/libraries_test/libraries_test.module index af1a4ac39a4c01a76cd561e1362c11d76af49e02..2f6ee0e369022c39fe4330ad7aed91a36109ded6 100644 --- a/tests/modules/libraries_test/libraries_test.module +++ b/tests/modules/libraries_test/libraries_test.module @@ -13,277 +13,277 @@ use Drupal\Core\Messenger\MessengerTrait; */ function libraries_test_libraries_info() { // Test library detection. - $libraries['example_missing'] = array( + $libraries['example_missing'] = [ 'name' => 'Example missing', 'library path' => drupal_get_path('module', 'libraries') . '/tests/missing', - ); - $libraries['example_undetected_version'] = array( + ]; + $libraries['example_undetected_version'] = [ 'name' => 'Example undetected version', 'library path' => drupal_get_path('module', 'libraries') . '/tests', 'version callback' => '_libraries_test_return_version', - 'version arguments' => array(FALSE), - ); - $libraries['example_unsupported_version'] = array( + 'version arguments' => [FALSE], + ]; + $libraries['example_unsupported_version'] = [ 'name' => 'Example unsupported version', 'library path' => drupal_get_path('module', 'libraries') . '/tests', 'version callback' => '_libraries_test_return_version', - 'version arguments' => array('1'), - 'versions' => array( - '2' => array(), - ), - ); + 'version arguments' => ['1'], + 'versions' => [ + '2' => [], + ], + ]; - $libraries['example_supported_version'] = array( + $libraries['example_supported_version'] = [ 'name' => 'Example supported version', 'library path' => drupal_get_path('module', 'libraries') . '/tests', 'version callback' => '_libraries_test_return_version', - 'version arguments' => array('1'), - 'versions' => array( - '1' => array(), - ), - ); + 'version arguments' => ['1'], + 'versions' => [ + '1' => [], + ], + ]; // Test the default version callback. - $libraries['example_default_version_callback'] = array( + $libraries['example_default_version_callback'] = [ 'name' => 'Example default version callback', 'library path' => drupal_get_path('module', 'libraries') . '/tests/example', - 'version arguments' => array( + 'version arguments' => [ 'file' => 'README.txt', // Version 1 'pattern' => '/Version (\d+)/', 'lines' => 5, - ), - ); + ], + ]; // Test a multiple-parameter version callback. - $libraries['example_multiple_parameter_version_callback'] = array( + $libraries['example_multiple_parameter_version_callback'] = [ 'name' => 'Example multiple parameter version callback', 'library path' => drupal_get_path('module', 'libraries') . '/tests/example', // Version 1 'version callback' => '_libraries_test_get_version', - 'version arguments' => array('README.txt', '/Version (\d+)/', 5), - ); + 'version arguments' => ['README.txt', '/Version (\d+)/', 5], + ]; // Test a top-level files property. - $libraries['example_files'] = array( + $libraries['example_files'] = [ 'name' => 'Example files', 'library path' => drupal_get_path('module', 'libraries') . '/tests/example', 'version' => '1', - 'files' => array( - 'js' => array('example_1.js'), - 'css' => array('example_1.css'), - 'php' => array('example_1.php'), - ), - ); + 'files' => [ + 'js' => ['example_1.js'], + 'css' => ['example_1.css'], + 'php' => ['example_1.php'], + ], + ]; // Test loading of integration files. // Normally added by the corresponding module via hook_libraries_info_alter(), // these files should be automatically loaded when the library is loaded. - $libraries['example_integration_files'] = array( + $libraries['example_integration_files'] = [ 'name' => 'Example integration files', 'library path' => drupal_get_path('module', 'libraries') . '/tests/example', 'version' => '1', - 'integration files' => array( - 'libraries_test' => array( - 'js' => array('libraries_test.js'), - 'css' => array('libraries_test.css'), - 'php' => array('libraries_test.inc'), - ), - ), - ); + 'integration files' => [ + 'libraries_test' => [ + 'js' => ['libraries_test.js'], + 'css' => ['libraries_test.css'], + 'php' => ['libraries_test.inc'], + ], + ], + ]; // Test version overloading. - $libraries['example_versions'] = array( + $libraries['example_versions'] = [ 'name' => 'Example versions', 'library path' => drupal_get_path('module', 'libraries') . '/tests/example', 'version' => '2', - 'versions' => array( - '1' => array( - 'files' => array( - 'js' => array('example_1.js'), - 'css' => array('example_1.css'), - 'php' => array('example_1.php'), - ), - ), - '2' => array( - 'files' => array( - 'js' => array('example_2.js'), - 'css' => array('example_2.css'), - 'php' => array('example_2.php'), - ), - ), - ), - ); + 'versions' => [ + '1' => [ + 'files' => [ + 'js' => ['example_1.js'], + 'css' => ['example_1.css'], + 'php' => ['example_1.php'], + ], + ], + '2' => [ + 'files' => [ + 'js' => ['example_2.js'], + 'css' => ['example_2.css'], + 'php' => ['example_2.php'], + ], + ], + ], + ]; // Test variant detection. - $libraries['example_variant_missing'] = array( + $libraries['example_variant_missing'] = [ 'name' => 'Example variant missing', 'library path' => drupal_get_path('module', 'libraries') . '/tests/example', 'version' => '1', - 'variants' => array( - 'example_variant' => array( - 'files' => array( - 'js' => array('example_3.js'), - 'css' => array('example_3.css'), - 'php' => array('example_3.php'), - ), + 'variants' => [ + 'example_variant' => [ + 'files' => [ + 'js' => ['example_3.js'], + 'css' => ['example_3.css'], + 'php' => ['example_3.php'], + ], 'variant callback' => '_libraries_test_return_installed', - 'variant arguments' => array(FALSE), - ), - ), - ); + 'variant arguments' => [FALSE], + ], + ], + ]; - $libraries['example_variant'] = array( + $libraries['example_variant'] = [ 'name' => 'Example variant', 'library path' => drupal_get_path('module', 'libraries') . '/tests/example', 'version' => '1', - 'variants' => array( - 'example_variant' => array( - 'files' => array( - 'js' => array('example_3.js'), - 'css' => array('example_3.css'), - 'php' => array('example_3.php'), - ), + 'variants' => [ + 'example_variant' => [ + 'files' => [ + 'js' => ['example_3.js'], + 'css' => ['example_3.css'], + 'php' => ['example_3.php'], + ], 'variant callback' => '_libraries_test_return_installed', - 'variant arguments' => array(TRUE), - ), - ), - ); + 'variant arguments' => [TRUE], + ], + ], + ]; // Test correct behaviour with multiple versions and multiple variants. - $libraries['example_versions_and_variants'] = array( + $libraries['example_versions_and_variants'] = [ 'name' => 'Example versions and variants', 'library path' => drupal_get_path('module', 'libraries') . '/tests/example', 'version' => '2', - 'versions' => array( - '1' => array( - 'variants' => array( - 'example_variant_1' => array( - 'files' => array( - 'js' => array('example_1.js'), - 'css' => array('example_1.css'), - 'php' => array('example_1.php'), - ), + 'versions' => [ + '1' => [ + 'variants' => [ + 'example_variant_1' => [ + 'files' => [ + 'js' => ['example_1.js'], + 'css' => ['example_1.css'], + 'php' => ['example_1.php'], + ], 'variant callback' => '_libraries_test_return_installed', - 'variant arguments' => array(TRUE), - ), - 'example_variant_2' => array( - 'files' => array( - 'js' => array('example_2.js'), - 'css' => array('example_2.css'), - 'php' => array('example_2.php'), - ), + 'variant arguments' => [TRUE], + ], + 'example_variant_2' => [ + 'files' => [ + 'js' => ['example_2.js'], + 'css' => ['example_2.css'], + 'php' => ['example_2.php'], + ], 'variant callback' => '_libraries_test_return_installed', - 'variant arguments' => array(TRUE), - ), - ), - ), - '2' => array( - 'variants' => array( - 'example_variant_1' => array( - 'files' => array( - 'js' => array('example_3.js'), - 'css' => array('example_3.css'), - 'php' => array('example_3.php'), - ), + 'variant arguments' => [TRUE], + ], + ], + ], + '2' => [ + 'variants' => [ + 'example_variant_1' => [ + 'files' => [ + 'js' => ['example_3.js'], + 'css' => ['example_3.css'], + 'php' => ['example_3.php'], + ], 'variant callback' => '_libraries_test_return_installed', - 'variant arguments' => array(TRUE), - ), - 'example_variant_2' => array( - 'files' => array( - 'js' => array('example_4.js'), - 'css' => array('example_4.css'), - 'php' => array('example_4.php'), - ), + 'variant arguments' => [TRUE], + ], + 'example_variant_2' => [ + 'files' => [ + 'js' => ['example_4.js'], + 'css' => ['example_4.css'], + 'php' => ['example_4.php'], + ], 'variant callback' => '_libraries_test_return_installed', - 'variant arguments' => array(TRUE), - ), - ), - ), - ), - ); + 'variant arguments' => [TRUE], + ], + ], + ], + ], + ]; // Test dependency loading. // We add one file to each library to be able to verify if it was loaded with // libraries_load(). // This library acts as a dependency for the libraries below. - $libraries['example_dependency'] = array( + $libraries['example_dependency'] = [ 'name' => 'Example dependency', 'library path' => drupal_get_path('module', 'libraries') . '/tests/example', 'version' => '1.1', - 'files' => array('js' => array('example_1.js')), - ); - $libraries['example_dependency_missing'] = array( + 'files' => ['js' => ['example_1.js']], + ]; + $libraries['example_dependency_missing'] = [ 'name' => 'Example dependency missing', 'library path' => drupal_get_path('module', 'libraries') . '/tests/example', 'version' => '1', - 'dependencies' => array('example_missing'), - 'files' => array('js' => array('example_1.js')), - ); - $libraries['example_dependency_incompatible'] = array( + 'dependencies' => ['example_missing'], + 'files' => ['js' => ['example_1.js']], + ]; + $libraries['example_dependency_incompatible'] = [ 'name' => 'Example dependency incompatible', 'library path' => drupal_get_path('module', 'libraries') . '/tests/example', 'version' => '1', - 'dependencies' => array('example_dependency (>1.1)'), - 'files' => array('js' => array('example_1.js')), - ); - $libraries['example_dependency_compatible'] = array( + 'dependencies' => ['example_dependency (>1.1)'], + 'files' => ['js' => ['example_1.js']], + ]; + $libraries['example_dependency_compatible'] = [ 'name' => 'Example dependency compatible', 'library path' => drupal_get_path('module', 'libraries') . '/tests/example', 'version' => '1', - 'dependencies' => array('example_dependency (>=1.1)'), - 'files' => array('js' => array('example_1.js')), - ); + 'dependencies' => ['example_dependency (>=1.1)'], + 'files' => ['js' => ['example_1.js']], + ]; // Test the applying of callbacks. - $libraries['example_callback'] = array( + $libraries['example_callback'] = [ 'name' => 'Example callback', 'library path' => drupal_get_path('module', 'libraries') . '/tests/example', 'version' => '1', - 'versions' => array( - '1' => array( - 'variants' => array( - 'example_variant' => array( + 'versions' => [ + '1' => [ + 'variants' => [ + 'example_variant' => [ // These keys are for testing purposes only. 'info callback' => 'not applied', 'pre-detect callback' => 'not applied', 'post-detect callback' => 'not applied', 'pre-load callback' => 'not applied', 'post-load callback' => 'not applied', - ), - ), + ], + ], // These keys are for testing purposes only. 'info callback' => 'not applied', 'pre-detect callback' => 'not applied', 'post-detect callback' => 'not applied', 'pre-load callback' => 'not applied', 'post-load callback' => 'not applied', - ), - ), - 'variants' => array( - 'example_variant' => array( + ], + ], + 'variants' => [ + 'example_variant' => [ // These keys are for testing purposes only. 'info callback' => 'not applied', 'pre-detect callback' => 'not applied', 'post-detect callback' => 'not applied', 'pre-load callback' => 'not applied', 'post-load callback' => 'not applied', - ), - ), - 'callbacks' => array( - 'info' => array('_libraries_test_info_callback'), - 'pre-detect' => array('_libraries_test_pre_detect_callback'), - 'post-detect' => array('_libraries_test_post_detect_callback'), - 'pre-load' => array('_libraries_test_pre_load_callback'), - 'post-load' => array('_libraries_test_post_load_callback'), - ), + ], + ], + 'callbacks' => [ + 'info' => ['_libraries_test_info_callback'], + 'pre-detect' => ['_libraries_test_pre_detect_callback'], + 'post-detect' => ['_libraries_test_post_detect_callback'], + 'pre-load' => ['_libraries_test_pre_load_callback'], + 'post-load' => ['_libraries_test_post_load_callback'], + ], // These keys are for testing purposes only. 'info callback' => 'not applied', 'pre-detect callback' => 'not applied', 'post-detect callback' => 'not applied', 'pre-load callback' => 'not applied', 'post-load callback' => 'not applied', - ); + ]; return $libraries; } @@ -292,7 +292,7 @@ function libraries_test_libraries_info() { * Implements hook_libraries_info_file_paths() */ function libraries_test_libraries_info_file_paths() { - return array(drupal_get_path('module', 'libraries') . '/tests/example'); + return [drupal_get_path('module', 'libraries') . '/tests/example']; } /** @@ -470,29 +470,29 @@ function _libraries_test_callback(&$library, $version, $variant, $group) { * Implements hook_menu(). */ function libraries_test_menu() { - $items['libraries_test/files'] = array( + $items['libraries_test/files'] = [ 'title' => 'Test files', 'route_name' => 'libraries_test_files', - ); - $items['libraries_test/integration_files'] = array( + ]; + $items['libraries_test/integration_files'] = [ 'title' => 'Test integration files', 'route_name' => 'libraries_test_integration_files', - ); - $items['libraries_test/versions'] = array( + ]; + $items['libraries_test/versions'] = [ 'title' => 'Test version loading', 'route_name' => 'libraries_test_versions', - ); - $items['libraries_test/variant'] = array( + ]; + $items['libraries_test/variant'] = [ 'title' => 'Test variant loading', 'route_name' => 'libraries_test_variant', - ); - $items['libraries_test/versions_and_variants'] = array( + ]; + $items['libraries_test/versions_and_variants'] = [ 'title' => 'Test concurrent version and variant loading', 'route_name' => 'libraries_test_versions_and_variants', - ); - $items['libraries_test/cache'] = array( + ]; + $items['libraries_test/cache'] = [ 'title' => 'Test caching of library information', 'route_name' => 'libraries_test_cache', - ); + ]; return $items; }