(dev/core#4674) MailSettings - Provide setup URL's through BAO
authorTim Otten <totten@civicrm.org>
Thu, 19 Oct 2023 23:47:45 +0000 (16:47 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 19 Oct 2023 23:52:00 +0000 (16:52 -0700)
CRM/Core/BAO/MailSettings.php
CRM/Utils/Hook.php
templates/CRM/Admin/Page/MailSettings.tpl

index e9c1a5d245ef0e7f7670523e166903ddd63ae16e..2d8b6b85ef6dcf70fcdff09bc7755f9a829800c5 100644 (file)
@@ -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;
   }
 
index 2477cb6325cb39d3d1a0f3effc0edc9d52c75397..e96b976ce4f467e71d8f7fb052302921053fabda 100644 (file)
@@ -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) {
index 7fce4665dd291f60ecd8fd291a05b9d566bebbd5..80b2996e2584a5305ff37d55688c69b9782eba26 100644 (file)
@@ -61,7 +61,7 @@
             <select id="crm-mail-setup" name="crm-mail-setup" class="crm-select2 crm-form-select" aria-label="{ts}Add Mail Account{/ts}">
                 <option value="" aria-hidden="true">{ts}Add Mail Account{/ts}</option>
                 {foreach from=$setupActions key=setupActionsName item=setupAction}
-                    <option value="{$setupActionsName|escape}">{$setupAction.title|escape}</option>
+                    <option data-url="{$setupAction.url|escape}" value="{$setupActionsName|escape}">{$setupAction.title|escape}</option>
                 {/foreach}
             </select>
         </form>
@@ -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');
         });
     </script>
 {/literal}