diff --git a/libraries.module b/libraries.module index 39c8345..d1d6296 100644 --- a/libraries.module +++ b/libraries.module @@ -450,6 +450,8 @@ function libraries_info_defaults(&$library, $name) { 'versions' => array(), 'integration files' => array(), 'callbacks' => array(), + // @todo Remove in 7.x-3.x + 'post-load integration files' => FALSE, ); $library['callbacks'] += array( 'info' => array(), @@ -691,6 +693,33 @@ function libraries_load($name, $variant = NULL) { * The number of loaded files. */ function libraries_load_files($library) { + // Load integration files. + if (!$library['post-load integration files'] && !empty($library['integration files'])) { + $enabled_themes = array(); + foreach (list_themes() as $theme_name => $theme) { + if ($theme->status) { + $enabled_themes[] = $theme_name; + } + } + foreach ($library['integration files'] as $provider => $files) { + if (module_exists($provider)) { + libraries_load_files(array( + 'files' => $files, + 'path' => '', + 'library path' => drupal_get_path('module', $provider), + 'post-load integration files' => FALSE, + )); + } + elseif (in_array($provider, $enabled_themes)) { + libraries_load_files(array( + 'files' => $files, + 'path' => '', + 'library path' => drupal_get_path('theme', $provider), + 'post-load integration files' => FALSE, + )); + } + } + } // Construct the full path to the library for later use. $path = $library['library path']; @@ -743,7 +772,7 @@ function libraries_load_files($library) { } // Load integration files. - if (!empty($library['integration files'])) { + if ($library['post-load integration files'] && !empty($library['integration files'])) { $enabled_themes = array(); foreach (list_themes() as $theme_name => $theme) { if ($theme->status) { @@ -756,6 +785,7 @@ function libraries_load_files($library) { 'files' => $files, 'path' => '', 'library path' => drupal_get_path('module', $provider), + 'post-load integration files' => FALSE, )); } elseif (in_array($provider, $enabled_themes)) { @@ -763,6 +793,7 @@ function libraries_load_files($library) { 'files' => $files, 'path' => '', 'library path' => drupal_get_path('theme', $provider), + 'post-load integration files' => FALSE, )); } } diff --git a/tests/libraries.test b/tests/libraries.test index 75c8a9a..dd1a801 100644 --- a/tests/libraries.test +++ b/tests/libraries.test @@ -329,6 +329,13 @@ class LibrariesTestCase extends DrupalWebTestCase { // @see _libraries_require_once() $library = libraries_load('example_path_variable_override'); $this->assertEqual($library['loaded'], 2, 'PHP files cannot break library loading.'); + + // Test that the 'post-load integration files' property works correctly. + $library = libraries_load('example_module_integration_files_post_load'); + $this->verbose('
' . var_export($library, TRUE) . '
'); + // Including libraries_test_module_post_load.inc without previously loading + // example_1.php would result in a fatal error. + $this->pass('Integration files are loaded in the correct order.'); } /** diff --git a/tests/modules/libraries_test_module/libraries_test_module.module b/tests/modules/libraries_test_module/libraries_test_module.module index 045d71c..2fe66fa 100644 --- a/tests/modules/libraries_test_module/libraries_test_module.module +++ b/tests/modules/libraries_test_module/libraries_test_module.module @@ -94,6 +94,24 @@ function libraries_test_module_libraries_info() { ), ); + // Test loading of integration files after library files. + // We test the correct loading order by calling a function that is defined in + // example_1.php in libraries_test_module_post_load.inc. + $libraries['example_module_integration_files_post_load'] = array( + 'name' => 'Example module post-load integration files', + 'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example', + 'version' => '1', + 'files' => array( + 'php' => array('example_1.php'), + ), + 'integration files' => array( + 'libraries_test_module' => array( + 'php' => array('libraries_test_module_post_load.inc'), + ), + ), + 'post-load integration files' => TRUE, + ); + // Test version overloading. $libraries['example_versions'] = array( 'name' => 'Example versions', diff --git a/tests/modules/libraries_test_module/libraries_test_module_post_load.inc b/tests/modules/libraries_test_module/libraries_test_module_post_load.inc new file mode 100644 index 0000000..8e308f2 --- /dev/null +++ b/tests/modules/libraries_test_module/libraries_test_module_post_load.inc @@ -0,0 +1,15 @@ +