From 3f57d516f193ef98f36608c82ca498c6dce54531 Mon Sep 17 00:00:00 2001 From: Will Long Date: Fri, 20 Oct 2017 14:23:14 -0500 Subject: [PATCH] added hook support for drupal 8 --- CRM/Utils/Hook/Drupal8.php | 9 +++++++++ CRM/Utils/Hook/DrupalBase.php | 19 +++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CRM/Utils/Hook/Drupal8.php b/CRM/Utils/Hook/Drupal8.php index 137a05e891..de0d8c4e77 100644 --- a/CRM/Utils/Hook/Drupal8.php +++ b/CRM/Utils/Hook/Drupal8.php @@ -32,4 +32,13 @@ */ class CRM_Utils_Hook_Drupal8 extends CRM_Utils_Hook_DrupalBase { + /** + * {@inheritdoc} + */ + protected function getDrupalModules() { + if (class_exists('\Drupal')) { + return array_keys(\Drupal::moduleHandler()->getModuleList()); + } + } + } diff --git a/CRM/Utils/Hook/DrupalBase.php b/CRM/Utils/Hook/DrupalBase.php index 2adce368b7..1c8c4eaa90 100644 --- a/CRM/Utils/Hook/DrupalBase.php +++ b/CRM/Utils/Hook/DrupalBase.php @@ -91,10 +91,7 @@ class CRM_Utils_Hook_DrupalBase extends CRM_Utils_Hook { public function buildModuleList() { if ($this->isBuilt === FALSE) { if ($this->drupalModules === NULL) { - if (function_exists('module_list')) { - // copied from user_module_invoke - $this->drupalModules = module_list(); - } + $this->drupalModules = $this->getDrupalModules(); } if ($this->civiModules === NULL) { @@ -128,4 +125,18 @@ class CRM_Utils_Hook_DrupalBase extends CRM_Utils_Hook { } } + /** + * Gets modules installed on the Drupal site. + * + * @return array|null + * The machine names of the modules installed in Drupal, or NULL if unable + * to determine the modules. + */ + protected function getDrupalModules() { + if (function_exists('module_list')) { + // copied from user_module_invoke + return module_list(); + } + } + } -- 2.25.1