3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Create a page for displaying Custom Fields.
21 * Heart of this class is the run method which checks
22 * for action type and then displays the appropriate
26 class CRM_Custom_Page_Field
extends CRM_Core_Page
{
28 public $useLivePageJS = TRUE;
31 * The group id of the field.
38 * The action links that we need to display for the browse screen.
42 private static $_actionLinks;
45 * Get the action links for this page.
48 * array of action links that we need to display for the browse screen
50 public static function &actionLinks() {
51 if (!isset(self
::$_actionLinks)) {
52 self
::$_actionLinks = [
53 CRM_Core_Action
::UPDATE
=> [
54 'name' => ts('Edit Field'),
55 'url' => 'civicrm/admin/custom/group/field/update',
56 'qs' => 'action=update&reset=1&gid=%%gid%%&id=%%id%%',
57 'title' => ts('Edit Custom Field'),
59 CRM_Core_Action
::BROWSE
=> [
60 'name' => ts('Edit Multiple Choice Options'),
61 'url' => 'civicrm/admin/custom/group/field/option',
62 'qs' => 'reset=1&action=browse&gid=%%gid%%&fid=%%id%%',
63 'title' => ts('List Custom Options'),
65 CRM_Core_Action
::PREVIEW
=> [
66 'name' => ts('Preview Field Display'),
67 'url' => 'civicrm/admin/custom/group/preview',
68 'qs' => 'action=preview&reset=1&fid=%%id%%',
69 'title' => ts('Preview Custom Field'),
71 CRM_Core_Action
::DISABLE
=> [
72 'name' => ts('Disable'),
73 'ref' => 'crm-enable-disable',
74 'title' => ts('Disable Custom Field'),
76 CRM_Core_Action
::ENABLE
=> [
77 'name' => ts('Enable'),
78 'ref' => 'crm-enable-disable',
79 'title' => ts('Enable Custom Field'),
81 CRM_Core_Action
::EXPORT
=> [
83 'url' => 'civicrm/admin/custom/group/field/move',
84 'class' => 'small-popup',
85 'qs' => 'reset=1&fid=%%id%%',
86 'title' => ts('Move Custom Field'),
88 CRM_Core_Action
::DELETE
=> [
89 'name' => ts('Delete'),
90 'url' => 'civicrm/admin/custom/group/field/delete',
91 'qs' => 'reset=1&id=%%id%%',
92 'title' => ts('Delete Custom Field'),
96 return self
::$_actionLinks;
100 * Browse all custom group fields.
104 public function browse() {
105 $resourceManager = CRM_Core_Resources
::singleton();
106 if (!empty($_GET['new']) && $resourceManager->ajaxPopupsEnabled
) {
107 $resourceManager->addScriptFile('civicrm', 'js/crm.addNew.js', 999, 'html-header');
111 $customFieldBAO = new CRM_Core_BAO_CustomField();
114 $customFieldBAO->custom_group_id
= $this->_gid
;
115 $customFieldBAO->orderBy('weight, label');
116 $customFieldBAO->find();
118 while ($customFieldBAO->fetch()) {
119 $customField[$customFieldBAO->id
] = [];
120 CRM_Core_DAO
::storeValues($customFieldBAO, $customField[$customFieldBAO->id
]);
121 $action = array_sum(array_keys(self
::actionLinks()));
122 if ($customFieldBAO->is_active
) {
123 $action -= CRM_Core_Action
::ENABLE
;
126 $action -= CRM_Core_Action
::DISABLE
;
129 switch ($customFieldBAO->data_type
) {
134 // if Multi Select field is selected in custom field
135 if ($customFieldBAO->html_type
== 'Text') {
136 $action -= CRM_Core_Action
::BROWSE
;
140 case "ContactReference":
144 case "StateProvince":
148 $action -= CRM_Core_Action
::BROWSE
;
152 $customFieldDataType = array_column(CRM_Core_BAO_CustomField
::dataType(), 'label', 'id');
153 $customField[$customFieldBAO->id
]['data_type'] = $customFieldDataType[$customField[$customFieldBAO->id
]['data_type']];
154 $customField[$customFieldBAO->id
]['order'] = $customField[$customFieldBAO->id
]['weight'];
155 $customField[$customFieldBAO->id
]['action'] = CRM_Core_Action
::formLink(self
::actionLinks(), $action,
157 'id' => $customFieldBAO->id
,
158 'gid' => $this->_gid
,
162 'customField.row.actions',
168 $returnURL = CRM_Utils_System
::url('civicrm/admin/custom/group/field', "reset=1&action=browse&gid={$this->_gid}");
169 $filter = "custom_group_id = {$this->_gid}";
170 CRM_Utils_Weight
::addOrder($customField, 'CRM_Core_DAO_CustomField',
171 'id', $returnURL, $filter
174 $this->assign('customField', $customField);
180 * This method is called after the page is created. It checks for the
181 * type of action and executes that action.
185 public function run() {
186 $this->_gid
= CRM_Utils_Request
::retrieve('gid', 'Positive', $this, TRUE);
188 if (CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid
, 'is_reserved')) {
189 CRM_Core_Error
::statusBounce("You cannot add or edit fields in a reserved custom field-set.");
192 $groupTitle = CRM_Core_BAO_CustomGroup
::getTitle($this->_gid
);
193 $this->assign('gid', $this->_gid
);
194 $this->assign('groupTitle', $groupTitle);
196 // assign vars to templates
197 $this->assign('action', 'browse');
201 return parent
::run();