From 898951c6b91094fb1dbcddd723ef54aa847b6b66 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 19 May 2017 17:24:58 -0700 Subject: [PATCH] CRM-20600 - CRM_Core_Resources - Add hook for settings data --- CRM/Core/Resources.php | 1 + CRM/Utils/Hook.php | 13 +++++++++++++ tests/phpunit/CRM/Core/ResourcesTest.php | 11 +++++++++++ 3 files changed, 25 insertions(+) diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index e145938d16..68a2a7fde7 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -311,6 +311,7 @@ class CRM_Core_Resources { foreach ($this->settingsFactories as $callable) { $result = $this->mergeSettings($result, $callable()); } + CRM_Utils_Hook::alterResourceSettings($result); return $result; } diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index 2f263a3b79..9da03b4318 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -2071,6 +2071,19 @@ abstract class CRM_Utils_Hook { ); } + /** + * Modify the CRM_Core_Resources settings data. + * + * @param array $data + * @see CRM_Core_Resources::addSetting + */ + public static function alterResourceSettings(&$data) { + $event = \Civi\Core\Event\GenericHookEvent::create(array( + 'data' => &$data, + )); + Civi::dispatcher()->dispatch('hook_civicrm_alterResourceSettings', $event); + } + /** * EXPERIMENTAL: This hook allows one to register additional Angular modules * diff --git a/tests/phpunit/CRM/Core/ResourcesTest.php b/tests/phpunit/CRM/Core/ResourcesTest.php index 2977a9b289..2e57adc885 100644 --- a/tests/phpunit/CRM/Core/ResourcesTest.php +++ b/tests/phpunit/CRM/Core/ResourcesTest.php @@ -165,6 +165,17 @@ class CRM_Core_ResourcesTest extends CiviUnitTestCase { $this->assertTrue(strpos($actual, $expected) !== FALSE); } + public function testAddSettingHook() { + $test = $this; + Civi::dispatcher()->addListener('hook_civicrm_alterResourceSettings', function($event) use ($test) { + $test->assertEquals('apple', $event->data['fruit']['mine']); + $event->data['fruit']['mine'] = 'banana'; + }); + $this->res->addSetting(array('fruit' => array('mine' => 'apple'))); + $settings = $this->res->getSettings(); + $this->assertTreeEquals(array('fruit' => array('mine' => 'banana')), $settings); + } + public function testAddSettingFactory() { $this->res->addSettingsFactory(function () { return array('fruit' => array('yours' => 'orange')); -- 2.25.1