AdminUI - Alter core forms to redirect to the new AdminUI afform pages
authorcolemanw <coleman@civicrm.org>
Thu, 8 Jun 2023 19:35:53 +0000 (15:35 -0400)
committercolemanw <coleman@civicrm.org>
Thu, 8 Jun 2023 19:35:58 +0000 (15:35 -0400)
CRM/Custom/Form/Field.php
CRM/Custom/Form/Group.php
CRM/UF/Form/Field.php
CRM/UF/Form/Group.php
ext/civicrm_admin_ui/ang/afsearchAdminCustomGroups.aff.html
ext/civicrm_admin_ui/civicrm_admin_ui.php
ext/civicrm_admin_ui/managed/SavedSearch_Administer_Custom_Groups.mgd.php

index a9d5230e4df13fd73c1489ef88dabec81b2ce574..d96d999ee49f518b1136fdc8eacf368f031a98ad 100644 (file)
@@ -30,7 +30,7 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
    *
    * @var int
    */
-  protected $_gid;
+  public $_gid;
 
   /**
    * The field id, used when editing the field
index 07499e96da14e43bcdd6f23f2253439434a54f08..4f9baa45440224001e0df2c9e1f590bf6eef07fa 100644 (file)
@@ -25,7 +25,7 @@ class CRM_Custom_Form_Group extends CRM_Core_Form {
    *
    * @var int
    */
-  protected $_id;
+  public $_id;
 
   /**
    *  set is empty or not.
@@ -48,6 +48,7 @@ class CRM_Custom_Form_Group extends CRM_Core_Form {
    * @return void
    */
   public function preProcess() {
+    $this->preventAjaxSubmit();
     Civi::resources()->addScriptFile('civicrm', 'js/jquery/jquery.crmIconPicker.js');
 
     // current set id
@@ -378,6 +379,7 @@ class CRM_Custom_Form_Group extends CRM_Core_Form {
 
     $result = civicrm_api3('CustomGroup', 'create', $params);
     $group = $result['values'][$result['id']];
+    $this->_id = $result['id'];
 
     // reset the cache
     Civi::cache('fields')->flush();
index 03d583fa903bd53b877eccb62467d63b170a9e52..bb5cbce79bcb22f78a20b1f08fe0d2aded53e732 100644 (file)
@@ -25,7 +25,7 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
    *
    * @var int
    */
-  protected $_gid;
+  public $_gid;
 
   /**
    * The field id, used when editing the field.
index 881b1ceedfd42cb2dc906c610b3c4508a64ec2a5..841adc8242d670acdd1aae099b1bbf0f285c25f5 100644 (file)
@@ -84,6 +84,7 @@ class CRM_UF_Form_Group extends CRM_Core_Form {
    * Set variables up before form is built.
    */
   public function preProcess() {
+    $this->preventAjaxSubmit();
     // current form id
     $this->_id = $this->get('id');
     if (!$this->_id) {
@@ -350,6 +351,7 @@ class CRM_UF_Form_Group extends CRM_Core_Form {
 
       // create uf group
       $ufGroup = CRM_Core_BAO_UFGroup::add($params);
+      $this->_id = $ufGroup->id;
 
       if (!empty($params['is_active'])) {
         //make entry in uf join table
index b4ce20e8f04159190086c59e5cb32c59298bf331..e8464a6d25aac0b1e354aa82dede2f973f7ac425 100644 (file)
     <af-field name="extends" defn="{input_attrs: {multiple: true}, label: 'Used For'}" />
     <af-field name="CustomGroup_CustomField_custom_group_id_01.label" defn="{required: false, input_attrs: {}, label: 'Field'}" />
   </div>
-  <div class="btn-group pull-right">
-      <a class="btn btn-primary" ng-href="{{:: crmUrl('civicrm/admin/custom/group/edit', {reset: 1}) }}">
-        <i class="crm-i fa-plus"/>
-        {{:: ts('Add Set of Custom Fields') }}
-      </a>
-  </div>
   <crm-search-display-table search-name="Administer_Custom_Groups" display-name="Table"></crm-search-display-table>
 </div>
index 85db9c327710d8371e61ee7744686d1d89aa2b53..da9a2b631f21f1e5ae579de3a7fed39eb95c5ddc 100644 (file)
@@ -13,3 +13,50 @@ use CRM_CivicrmAdminUi_ExtensionUtil as E;
 function civicrm_admin_ui_civicrm_config(&$config) {
   _civicrm_admin_ui_civix_civicrm_config($config);
 }
+
+/**
+ * Implements hook_civicrm_postProcess().
+ */
+function civicrm_admin_ui_civicrm_postProcess($className, $form) {
+  // Alter core forms to redirect to the new AdminUI afform pages
+  switch ($className) {
+    case 'CRM_Custom_Form_Group':
+      if ($form->getAction() & CRM_Core_Action::ADD) {
+        $redirect = "civicrm/admin/custom/group/fields#/?gid=$form->_id";
+      }
+      else {
+        $redirect = 'civicrm/admin/custom/group';
+      }
+      break;
+
+    case 'CRM_Custom_Form_Field':
+      $buttonName = $form->controller->getButtonName();
+      // Redirect to field list unless "Save and New" was clicked
+      if ($buttonName != $form->getButtonName('next', 'new')) {
+        $redirect = "civicrm/admin/custom/group/fields#/?gid=$form->_gid";
+      }
+      break;
+
+    case 'CRM_UF_Form_Group':
+      if ($form->getAction() & CRM_Core_Action::ADD) {
+        $redirect = "civicrm/admin/uf/group/field#/?uf_group_id=$form->_id";
+      }
+      else {
+        $redirect = 'civicrm/admin/uf/group';
+      }
+      break;
+
+    case 'CRM_UF_Form_Field':
+      $buttonName = $form->controller->getButtonName();
+      // Redirect to field list unless "Save and New" was clicked
+      if ($buttonName != $form->getButtonName('next', 'new')) {
+        $redirect = "civicrm/admin/uf/group/field#/?uf_group_id=$form->_gid";
+      }
+      break;
+  }
+
+  if (isset($redirect)) {
+    $url = CRM_Utils_System::url($redirect, '', FALSE, NULL, FALSE);
+    CRM_Core_Session::singleton()->replaceUserContext($url);
+  }
+}
index 293f579751a77d72b5cbd0cdd22b78ac4fac84e9..8a8b96df21158286eb82a7fb6ccc43ffe406af25 100644 (file)
@@ -25,6 +25,7 @@ return [
             'extends:label',
             'extends_entity_column_id:label',
             'style:label',
+            'is_reserved',
             'COUNT(CustomGroup_CustomField_custom_group_id_01.id) AS COUNT_CustomGroup_CustomField_custom_group_id_01_id',
             'GROUP_CONCAT(DISTINCT CustomGroup_CustomField_custom_group_id_01.label) AS GROUP_CONCAT_CustomGroup_CustomField_custom_group_id_01_label',
           ],
@@ -148,7 +149,7 @@ return [
                   'text' => E::ts('Settings'),
                   'style' => 'default',
                   'path' => '',
-                  'condition' => [],
+                  'condition' => ['is_reserved', '=', FALSE],
                 ],
               ],
               'type' => 'buttons',
@@ -197,6 +198,12 @@ return [
             ],
           ],
           'placeholder' => 5,
+          'addButton' => [
+            'path' => 'civicrm/admin/custom/group/edit?reset=1',
+            'text' => E::ts('Add Set of Custom Fields'),
+            'icon' => 'fa-plus',
+            'autoOpen' => TRUE,
+          ],
         ],
         'acl_bypass' => FALSE,
       ],