From c447a9a90ef35c65d106eac1b79742f101e0b266 Mon Sep 17 00:00:00 2001 From: podarok <podarok@116002.no-reply.drupal.org> Date: Tue, 15 Dec 2020 11:48:56 -0500 Subject: [PATCH] =?UTF-8?q?Issue=20#3119010=20by=20podarok,=20xeM8VfDh,=20?= =?UTF-8?q?douggreen,=20Suresh=20Prabhu=20Parkala,=20boromino,=20jungle,?= =?UTF-8?q?=20aspilicious,=20sajid=5F007,=20Ga=C3=ABlG,=20podarok,=20devde?= =?UTF-8?q?sagar,=20FatGuyLaughing,=20Anybody,=20Raunak.singh,=20berramou,?= =?UTF-8?q?=20drupgirl,=20fgm,=20joseph.olstad,=20dksdev01:=20Drupal=209?= =?UTF-8?q?=20Deprecated=20Code=20Report?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libraries.drush.inc | 4 ++-- libraries.info.yml | 1 + libraries.install | 2 +- libraries.module | 17 +++++++++-------- src/ExternalLibrary/LibraryManager.php | 4 +++- .../libraries_test/libraries_test.module | 3 ++- .../src/Controller/ExampleController.php | 2 +- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/libraries.drush.inc b/libraries.drush.inc index 22b7d62..3d9f7cd 100644 --- a/libraries.drush.inc +++ b/libraries.drush.inc @@ -62,8 +62,8 @@ function libraries_drush_invalidate_cache() { */ function libraries_drush_list() { $libraries = array(); - foreach (libraries_info() as $name => $info) { - $libraries[$name] = libraries_detect($name); + foreach (\Drupal::service('libraries.manager')->info() as $name => $info) { + $libraries[$name] = \Drupal::service('libraries.manager')->getLibrary($name); } ksort($libraries); diff --git a/libraries.info.yml b/libraries.info.yml index 1891a6f..63b0843 100644 --- a/libraries.info.yml +++ b/libraries.info.yml @@ -2,3 +2,4 @@ name: Libraries type: module description: Allows version-dependent and shared usage of external libraries. core: 8.x +core_version_requirement: ^8 || ^9 diff --git a/libraries.install b/libraries.install index a2edea4..666f84e 100644 --- a/libraries.install +++ b/libraries.install @@ -23,6 +23,6 @@ function libraries_install() { */ function libraries_uninstall() { if (is_dir('public://library-definitions')) { - file_unmanaged_delete_recursive('public://library-definitions'); + \Drupal::service('file_system')->deleteRecursive('public://library-definitions'); } } diff --git a/libraries.module b/libraries.module index 3006c34..e7fe5be 100644 --- a/libraries.module +++ b/libraries.module @@ -11,6 +11,7 @@ use Drupal\libraries\ExternalLibrary\Asset\AttachableAssetLibraryRegistrationInt use Drupal\libraries\ExternalLibrary\Utility\LibraryAccessorInterface; use Drupal\libraries\ExternalLibrary\Utility\LibraryIdAccessorInterface; use Symfony\Component\Yaml\Parser; +use Drupal\Core\Extension\Dependency; /** * Implements hook_library_info_build(). @@ -115,7 +116,7 @@ function libraries_get_libraries() { // Similar to 'modules' and 'themes' directories inside an installation // profile, installation profiles may want to place libraries into a // 'libraries' directory. - if ($profile = drupal_get_profile()) { + if ($profile = \Drupal::installProfile()) { $profile_path = drupal_get_path('profile', $profile); $searchdir[] = "$profile_path/libraries"; }; @@ -167,7 +168,7 @@ function libraries_get_libraries() { * https://www.drupal.org/node/2170763 */ function libraries_scan_info_files() { - $profile = drupal_get_path('profile', drupal_get_profile()); + $profile = \Drupal\Core\Extension\ExtensionList::getPath('profile', \Drupal::installProfile()); $config = DrupalKernel::findSitePath(\Drupal::request()); // Build a list of directories. @@ -345,9 +346,9 @@ function libraries_prepare_files(&$library, $version = NULL, $variant = NULL) { function libraries_detect_dependencies(&$library, $version = NULL, $variant = NULL) { if (isset($library['dependencies'])) { foreach ($library['dependencies'] as &$dependency_string) { - $dependency_info = ModuleHandler::parseDependency($dependency_string); - $dependency = libraries_detect($dependency_info['name']); - if (!$dependency['installed']) { + $dependency = Dependency::createFromString($dependency_string); + $info = libraries_detect($dependency->getName()); + 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( @@ -355,12 +356,12 @@ function libraries_detect_dependencies(&$library, $version = NULL, $variant = NU '%library' => $library['name'], )); } - elseif (drupal_check_incompatibility($dependency_info, $dependency['version'])) { + 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( - '%dependency_version' => $dependency['version'], - '%dependency' => $dependency['name'], + '%dependency_version' => $info['version'], + '%dependency' => $info['name'], '%library' => $library['name'], )); } diff --git a/src/ExternalLibrary/LibraryManager.php b/src/ExternalLibrary/LibraryManager.php index 17a6223..6b92d9d 100644 --- a/src/ExternalLibrary/LibraryManager.php +++ b/src/ExternalLibrary/LibraryManager.php @@ -61,7 +61,9 @@ class LibraryManager implements LibraryManagerInterface { public function getRequiredLibraryIds() { $library_ids = []; foreach (['module', 'theme'] as $type) { - foreach (system_get_info($type) as $info) { + $service_id = 'extension.list.' . $type; + $extension_list = \Drupal::service($service_id); + foreach ($extension_list->getAllInstalledInfo() as $info) { if (isset($info['library_dependencies'])) { $library_ids = array_merge($library_ids, $info['library_dependencies']); } diff --git a/tests/modules/libraries_test/libraries_test.module b/tests/modules/libraries_test/libraries_test.module index 1a30ebc..af1a4ac 100644 --- a/tests/modules/libraries_test/libraries_test.module +++ b/tests/modules/libraries_test/libraries_test.module @@ -6,6 +6,7 @@ */ use Drupal\Component\Utility\SafeMarkup; +use Drupal\Core\Messenger\MessengerTrait; /** * Implements hook_libraries_info(). @@ -461,7 +462,7 @@ function _libraries_test_callback(&$library, $version, $variant, $group) { // Only set the message for the top-level library to prevent confusing, // duplicate messages. if (!isset($version) && !isset($variant) && \Drupal::state()->get('libraries_test.cache', FALSE)) { - drupal_set_message(SafeMarkup::set("The <em>$group</em> callback group was invoked.")); + \Drupal::messenger()->addMessage(SafeMarkup::set("The <em>$group</em> callback group was invoked.")); } } diff --git a/tests/modules/libraries_test/src/Controller/ExampleController.php b/tests/modules/libraries_test/src/Controller/ExampleController.php index 217ebf2..522967c 100644 --- a/tests/modules/libraries_test/src/Controller/ExampleController.php +++ b/tests/modules/libraries_test/src/Controller/ExampleController.php @@ -23,7 +23,7 @@ class ExampleController implements ContainerInjectionInterface { * more information. */ private function buildPage($library, $variant = NULL) { - libraries_load($library, $variant); + \Drupal::service('libraries.manager')->load($library, $variant); // JavaScript and CSS files can be checked directly by SimpleTest, so we only // need to manually check for PHP files. $output = ''; -- GitLab