Skip to content

Commit

Permalink
Angular - Noisily deprecate 'settings' in favor of 'settingsFactory'
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Oct 12, 2023
1 parent 7a915c4 commit 976cedd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
21 changes: 21 additions & 0 deletions CRM/Utils/Check/Component/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -1106,4 +1106,25 @@ public function checkPHPIntlExists() {
return $messages;
}

public function checkAngularModuleSettings() {
$messages = [];
$modules = Civi::container()->get('angular')->getModules();
foreach ($modules as $name => $module) {
if (!empty($module['settings'])) {
$messages[] = new CRM_Utils_Check_Message(
__FUNCTION__ . $name,
ts('The Angular file "%1" from extension "%2" must be updated to use "settingsFactory" instead of "settings". <a %3>Developer info...</a>', [
1 => $name,
2 => $module['ext'],
3 => 'target="_blank" href="https://github.com/civicrm/civicrm-core/pull/19052"',
]),
ts('Unsupported Angular Setting'),
\Psr\Log\LogLevel::WARNING,
'fa-code'
);
}
}
return $messages;
}

}
3 changes: 3 additions & 0 deletions Civi/Angular/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public function getModules() {
foreach ($angularModules as $module => $info) {
// Merge in defaults
$angularModules[$module] += ['basePages' => ['civicrm/a']];
if (!empty($info['settings'])) {
\CRM_Core_Error::deprecatedWarning('Angular "settings" is not supported. See https://github.com/civicrm/civicrm-core/pull/19052');
}
// Validate settingsFactory callables
if (isset($info['settingsFactory'])) {
// To keep the cache small, we want `settingsFactory` to contain the string names of class & function, not an object
Expand Down
9 changes: 1 addition & 8 deletions tests/phpunit/Civi/Angular/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public function testGetModules(): void {
'js' => 0,
'css' => 0,
'partials' => 0,
'settings' => 0,
'settingsFactory' => 0,
];

Expand Down Expand Up @@ -75,12 +74,7 @@ public function testGetModules(): void {
$counts['partials']++;
}
}
if (isset($module['settings'])) {
$this->assertTrue(is_array($module['settings']));
foreach ($module['settings'] as $name => $value) {
$counts['settings']++;
}
}
$this->assertArrayNotHasKey('settings', $module);
if (isset($module['settingsFactory'])) {
$this->assertTrue(is_callable($module['settingsFactory']));
$counts['settingsFactory']++;
Expand All @@ -91,7 +85,6 @@ public function testGetModules(): void {
$this->assertTrue($counts['css'] > 0, 'Expect to find at least one CSS file');
$this->assertTrue($counts['partials'] > 0, 'Expect to find at least one partial HTML file');
$this->assertTrue($counts['settingsFactory'] > 0, 'Expect to find at least one settingsFactory');
$this->assertEquals(0, $counts['settings'], 'Angular settings are deprecated in favor of settingsFactory');
}

/**
Expand Down

0 comments on commit 976cedd

Please sign in to comment.