From 34cee7180a616051fb9d42dfab4e66c556af4aa8 Mon Sep 17 00:00:00 2001 From: colemanw Date: Thu, 8 Jun 2023 15:35:53 -0400 Subject: [PATCH] AdminUI - Alter core forms to redirect to the new AdminUI afform pages --- CRM/Custom/Form/Field.php | 2 +- CRM/Custom/Form/Group.php | 4 +- CRM/UF/Form/Field.php | 2 +- CRM/UF/Form/Group.php | 2 + .../ang/afsearchAdminCustomGroups.aff.html | 6 --- ext/civicrm_admin_ui/civicrm_admin_ui.php | 47 +++++++++++++++++++ ...vedSearch_Administer_Custom_Groups.mgd.php | 9 +++- 7 files changed, 62 insertions(+), 10 deletions(-) diff --git a/CRM/Custom/Form/Field.php b/CRM/Custom/Form/Field.php index a9d5230e4d..d96d999ee4 100644 --- a/CRM/Custom/Form/Field.php +++ b/CRM/Custom/Form/Field.php @@ -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 diff --git a/CRM/Custom/Form/Group.php b/CRM/Custom/Form/Group.php index 07499e96da..4f9baa4544 100644 --- a/CRM/Custom/Form/Group.php +++ b/CRM/Custom/Form/Group.php @@ -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(); diff --git a/CRM/UF/Form/Field.php b/CRM/UF/Form/Field.php index 03d583fa90..bb5cbce79b 100644 --- a/CRM/UF/Form/Field.php +++ b/CRM/UF/Form/Field.php @@ -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. diff --git a/CRM/UF/Form/Group.php b/CRM/UF/Form/Group.php index 881b1ceedf..841adc8242 100644 --- a/CRM/UF/Form/Group.php +++ b/CRM/UF/Form/Group.php @@ -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 diff --git a/ext/civicrm_admin_ui/ang/afsearchAdminCustomGroups.aff.html b/ext/civicrm_admin_ui/ang/afsearchAdminCustomGroups.aff.html index b4ce20e8f0..e8464a6d25 100644 --- a/ext/civicrm_admin_ui/ang/afsearchAdminCustomGroups.aff.html +++ b/ext/civicrm_admin_ui/ang/afsearchAdminCustomGroups.aff.html @@ -10,11 +10,5 @@ - diff --git a/ext/civicrm_admin_ui/civicrm_admin_ui.php b/ext/civicrm_admin_ui/civicrm_admin_ui.php index 85db9c3277..da9a2b631f 100644 --- a/ext/civicrm_admin_ui/civicrm_admin_ui.php +++ b/ext/civicrm_admin_ui/civicrm_admin_ui.php @@ -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); + } +} diff --git a/ext/civicrm_admin_ui/managed/SavedSearch_Administer_Custom_Groups.mgd.php b/ext/civicrm_admin_ui/managed/SavedSearch_Administer_Custom_Groups.mgd.php index 293f579751..8a8b96df21 100644 --- a/ext/civicrm_admin_ui/managed/SavedSearch_Administer_Custom_Groups.mgd.php +++ b/ext/civicrm_admin_ui/managed/SavedSearch_Administer_Custom_Groups.mgd.php @@ -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, ], -- 2.25.1