Skip to content

Commit

Permalink
Merge pull request civicrm#22519 from colemanw/customGroupCleanup
Browse files Browse the repository at this point in the history
[REF] CustomField Admin - Decouple page code from form code
  • Loading branch information
monishdeb authored Jan 25, 2022
2 parents a90c387 + aca7613 commit 3202de2
Show file tree
Hide file tree
Showing 17 changed files with 97 additions and 274 deletions.
2 changes: 1 addition & 1 deletion CRM/Campaign/Form/Survey/Questions.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function buildQuickForm() {
'There are no custom data sets for activity type "%1". To create one, <a href="%2" target="%3">click here</a>.',
[
1 => $activityTypes[$subTypeId],
2 => CRM_Utils_System::url('civicrm/admin/custom/group', 'action=add&reset=1'),
2 => CRM_Utils_System::url('civicrm/admin/custom/group/edit', 'action=add&reset=1'),
3 => '_blank',
]
)
Expand Down
6 changes: 3 additions & 3 deletions CRM/Core/DAO/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Core/CustomField.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:6273bed0debfe48b5b7caf40b3ea78b2)
* (GenCodeChecksum:6653fe86552a321a498736c14cabc41d)
*/

/**
Expand Down Expand Up @@ -45,8 +45,8 @@ class CRM_Core_DAO_CustomField extends CRM_Core_DAO {
protected static $_paths = [
'add' => 'civicrm/admin/custom/group/field/add?reset=1&action=add&gid=[custom_group_id]',
'update' => 'civicrm/admin/custom/group/field/update?action=update&reset=1&id=[id]&gid=[custom_group_id]',
'preview' => 'civicrm/admin/custom/group/field?action=preview&reset=1&id=[id]&gid=[custom_group_id]',
'delete' => 'civicrm/admin/custom/group/field?action=delete&reset=1&id=[id]&gid=[custom_group_id]',
'preview' => 'civicrm/admin/custom/group/preview&reset=1&fid=[id]',
'delete' => 'civicrm/admin/custom/group/field/delete?reset=1&id=[id]',
'move' => 'civicrm/admin/custom/group/field/move?reset=1&fid=[id]',
];

Expand Down
10 changes: 5 additions & 5 deletions CRM/Core/DAO/CustomGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Core/CustomGroup.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:e2730dbbc3151ef18d9aeba73577fa96)
* (GenCodeChecksum:0c41f19103b41d2f82bcd3b60aaf2165)
*/

/**
Expand Down Expand Up @@ -43,10 +43,10 @@ class CRM_Core_DAO_CustomGroup extends CRM_Core_DAO {
* @var string[]
*/
protected static $_paths = [
'add' => 'civicrm/admin/custom/group?action=add&reset=1',
'update' => 'civicrm/admin/custom/group?action=update&reset=1&id=[id]',
'preview' => 'civicrm/admin/custom/group?action=preview&reset=1&id=[id]',
'delete' => 'civicrm/admin/custom/group?action=delete&reset=1&id=[id]',
'add' => 'civicrm/admin/custom/group/edit?action=add&reset=1',
'update' => 'civicrm/admin/custom/group/edit?action=update&reset=1&id=[id]',
'preview' => 'civicrm/admin/custom/group/preview?reset=1&gid=[id]',
'delete' => 'civicrm/admin/custom/group/delete?reset=1&id=[id]',
];

/**
Expand Down
20 changes: 20 additions & 0 deletions CRM/Core/xml/Menu/Admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,33 @@
<access_arguments>administer CiviCRM data</access_arguments>
<weight>10</weight>
</item>
<item>
<path>civicrm/admin/custom/group/edit</path>
<title>Configure Custom Set</title>
<page_callback>CRM_Custom_Form_Group</page_callback>
</item>
<item>
<path>civicrm/admin/custom/group/preview</path>
<title>Custom Field Preview</title>
<page_callback>CRM_Custom_Form_Preview</page_callback>
</item>
<item>
<path>civicrm/admin/custom/group/delete</path>
<title>Delete Custom Set</title>
<page_callback>CRM_Custom_Form_DeleteGroup</page_callback>
</item>
<item>
<path>civicrm/admin/custom/group/field</path>
<title>Custom Data Fields</title>
<page_callback>CRM_Custom_Page_Field</page_callback>
<skipBreadcrumb>true</skipBreadcrumb>
<weight>11</weight>
</item>
<item>
<path>civicrm/admin/custom/group/field/delete</path>
<title>Delete Custom Field</title>
<page_callback>CRM_Custom_Form_DeleteField</page_callback>
</item>
<item>
<path>civicrm/admin/custom/group/field/option</path>
<title>Custom Field - Options</title>
Expand Down
2 changes: 1 addition & 1 deletion CRM/Custom/Form/DeleteField.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CRM_Custom_Form_DeleteField extends CRM_Core_Form {
* @access protected
*/
public function preProcess() {
$this->_id = $this->get('id');
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);

$defaults = [];
$params = ['id' => $this->_id];
Expand Down
2 changes: 1 addition & 1 deletion CRM/Custom/Form/DeleteGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CRM_Custom_Form_DeleteGroup extends CRM_Core_Form {
* @access protected
*/
public function preProcess() {
$this->_id = $this->get('id');
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);

$defaults = [];
$params = ['id' => $this->_id];
Expand Down
14 changes: 7 additions & 7 deletions CRM/Custom/Form/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
* @return void
*/
public function preProcess() {
//custom field id
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$this->setAction($this->_id ? CRM_Core_Action::UPDATE : CRM_Core_Action::ADD);

$this->assign('dataToHTML', self::$_dataToHTML);

Expand All @@ -97,13 +97,13 @@ public function preProcess() {
$this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this);
}

if ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_reserved', 'id')) {
if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_reserved')) {
CRM_Core_Error::statusBounce("You cannot add or edit fields in a reserved custom field-set.");
}

if ($this->_gid) {
$url = CRM_Utils_System::url('civicrm/admin/custom/group/field',
"reset=1&action=browse&gid={$this->_gid}"
"reset=1&gid={$this->_gid}"
);

$session = CRM_Core_Session::singleton();
Expand Down Expand Up @@ -192,8 +192,8 @@ public function buildQuickForm() {
if ($this->_gid) {
$this->_title = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'title');
$this->setTitle($this->_title . ' - ' . ($this->_id ? ts('Edit Field') : ts('New Field')));
$this->assign('gid', $this->_gid);
}
$this->assign('gid', $this->_gid);

// lets trim all the whitespace
$this->applyFilter('__ALL__', 'trim');
Expand Down Expand Up @@ -476,7 +476,7 @@ public function buildQuickForm() {
// if view mode pls freeze it with the done button.
if ($this->_action & CRM_Core_Action::VIEW) {
$this->freeze();
$url = CRM_Utils_System::url('civicrm/admin/custom/group/field', 'reset=1&action=browse&gid=' . $this->_gid);
$url = CRM_Utils_System::url('civicrm/admin/custom/group/field', 'reset=1&gid=' . $this->_gid);
$this->addElement('xbutton',
'done',
ts('Done'),
Expand Down Expand Up @@ -892,12 +892,12 @@ public function postProcess() {
if ($buttonName == $this->getButtonName('next', 'new')) {
$msg .= '<p>' . ts("Ready to add another.") . '</p>';
$session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field/add',
'reset=1&action=add&gid=' . $this->_gid
'reset=1&gid=' . $this->_gid
));
}
else {
$session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field',
'reset=1&action=browse&gid=' . $this->_gid
'reset=1&gid=' . $this->_gid
));
}
$session->setStatus($msg, ts('Saved'), 'success');
Expand Down
24 changes: 9 additions & 15 deletions CRM/Custom/Form/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,16 @@ public function preProcess() {
Civi::resources()->addScriptFile('civicrm', 'js/jquery/jquery.crmIconPicker.js');

// current set id
$this->_id = $this->get('id');
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$this->setAction($this->_id ? CRM_Core_Action::UPDATE : CRM_Core_Action::ADD);

if ($this->_id && $isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_id, 'is_reserved', 'id')) {
if ($this->_id && CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_id, 'is_reserved', 'id')) {
CRM_Core_Error::statusBounce("You cannot edit the settings of a reserved custom field-set.");
}
// setting title for html page
if ($this->_action == CRM_Core_Action::UPDATE) {

if ($this->_id) {
$title = CRM_Core_BAO_CustomGroup::getTitle($this->_id);
$this->setTitle(ts('Edit %1', [1 => $title]));
}
elseif ($this->_action == CRM_Core_Action::VIEW) {
$title = CRM_Core_BAO_CustomGroup::getTitle($this->_id);
$this->setTitle(ts('Preview %1', [1 => $title]));
}
else {
$this->setTitle(ts('New Custom Field Set'));
}

if (isset($this->_id)) {
$params = ['id' => $this->_id];
CRM_Core_BAO_CustomGroup::retrieve($params, $this->_defaults);

Expand All @@ -78,6 +69,9 @@ public function preProcess() {
$this->_subtypes = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($subExtends, 1, -1));
}
}
else {
$this->setTitle(ts('New Custom Field Set'));
}
}

/**
Expand Down Expand Up @@ -405,7 +399,7 @@ public function postProcess() {
else {
// Jump directly to adding a field if popups are disabled
$action = CRM_Core_Resources::singleton()->ajaxPopupsEnabled ? '' : '/add';
$url = CRM_Utils_System::url("civicrm/admin/custom/group/field$action", 'reset=1&new=1&gid=' . $group['id'] . '&action=' . ($action ? 'add' : 'browse'));
$url = CRM_Utils_System::url("civicrm/admin/custom/group/field$action", 'reset=1&new=1&gid=' . $group['id']);
CRM_Core_Session::setStatus(ts("Your custom field set '%1' has been added. You can add custom fields now.",
[1 => $group['title']]
), ts('Saved'), 'success');
Expand Down
22 changes: 17 additions & 5 deletions CRM/Custom/Form/Preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
*/
class CRM_Custom_Form_Preview extends CRM_Core_Form {

/**
* @var int
*/
protected $_groupId;

/**
* @var int
*/
protected $_fieldId;

/**
* The group tree data.
*
Expand All @@ -40,15 +50,15 @@ class CRM_Custom_Form_Preview extends CRM_Core_Form {
* @return void
*/
public function preProcess() {
// get the controller vars
$this->_groupId = $this->get('groupId');
$this->_fieldId = $this->get('fieldId');
// Get field id if previewing a single field
$this->_fieldId = CRM_Utils_Request::retrieve('fid', 'Positive', $this);

// Single field preview
if ($this->_fieldId) {
// field preview
$defaults = [];
$params = ['id' => $this->_fieldId];
$fieldDAO = new CRM_Core_DAO_CustomField();
CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $defaults);
$this->_groupId = $defaults['custom_group_id'];

if (!empty($defaults['is_view'])) {
CRM_Core_Error::statusBounce(ts('This field is view only so it will not display on edit form.'));
Expand All @@ -64,7 +74,9 @@ public function preProcess() {
$this->_groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $this);
$this->assign('preview_type', 'field');
}
// Group preview
else {
$this->_groupId = CRM_Utils_Request::retrieve('gid', 'Positive', $this, TRUE);
$groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail($this->_groupId);
$this->_groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, TRUE, $this);
$this->assign('preview_type', 'group');
Expand Down
Loading

0 comments on commit 3202de2

Please sign in to comment.