From: Tim Otten Date: Thu, 19 Oct 2023 23:47:45 +0000 (-0700) Subject: (dev/core#4674) MailSettings - Provide setup URL's through BAO X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=9b2e04c2a8e34cac45a7f396a2aef12715424fc5;p=civicrm-core.git (dev/core#4674) MailSettings - Provide setup URL's through BAO --- diff --git a/CRM/Core/BAO/MailSettings.php b/CRM/Core/BAO/MailSettings.php index e9c1a5d245..2d8b6b85ef 100644 --- a/CRM/Core/BAO/MailSettings.php +++ b/CRM/Core/BAO/MailSettings.php @@ -19,7 +19,7 @@ class CRM_Core_BAO_MailSettings extends CRM_Core_DAO_MailSettings { /** * Get a list of setup-actions. * - * @return array + * @return array{array{title:string, callback: mixed, url: string}} * List of available actions. See description in the hook-docs. * @see CRM_Utils_Hook::mailSetupActions() */ @@ -31,6 +31,13 @@ class CRM_Core_BAO_MailSettings extends CRM_Core_DAO_MailSettings { ]; CRM_Utils_Hook::mailSetupActions($setupActions); + + foreach ($setupActions as $key => &$setupAction) { + if (!isset($setupAction['url'])) { + $setupAction['url'] = (string) Civi::url('//civicrm/ajax/setupMailAccount')->addQuery(['type' => $key]); + } + } + return $setupActions; } diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index 2477cb6325..e96b976ce4 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -1145,6 +1145,9 @@ abstract class CRM_Utils_Hook { * - title: string * - callback: string|array, the function which starts the setup process. * The function is expected to return a 'url' for the config screen. + * - url: string (optional), a URL which starts the setup process. + * If omitted, then a default URL is generated. The effect of opening the URL is + * to invoke the `callback`. * @return mixed */ public static function mailSetupActions(&$setupActions) { diff --git a/templates/CRM/Admin/Page/MailSettings.tpl b/templates/CRM/Admin/Page/MailSettings.tpl index 7fce4665dd..80b2996e25 100644 --- a/templates/CRM/Admin/Page/MailSettings.tpl +++ b/templates/CRM/Admin/Page/MailSettings.tpl @@ -61,7 +61,7 @@ @@ -80,8 +80,7 @@ return; } event.stopPropagation(); - var url = CRM.url('civicrm/ajax/setupMailAccount', {type: event.val}); - window.location = url; + window.location = cj(event.choice.element).data('url'); }); {/literal}