Skip to content

Commit a674c37

Browse files
Merge pull request #20481 from colemanw/getFieldsFix
APIv4 - Fix getFields to respect default_value from getFields
2 parents bedd447 + 88620a5 commit a674c37

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

CRM/Core/DAO/CustomGroup.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Generated from xml/schema/CRM/Core/CustomGroup.xml
88
* DO NOT EDIT. Generated by CRM_Core_CodeGen
9-
* (GenCodeChecksum:fc2cf4a8b27ca8d4eaced3f1a3fcddd5)
9+
* (GenCodeChecksum:ddee40c6f144396056437d29bc0337d7)
1010
*/
1111

1212
/**
@@ -437,6 +437,7 @@ public static function &fields() {
437437
'html' => [
438438
'label' => ts("Table Name"),
439439
],
440+
'readonly' => TRUE,
440441
'add' => '2.0',
441442
],
442443
'is_multiple' => [

Civi/Api4/Generic/BasicGetFieldsAction.php

+11-9
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ public function _run(Result $result) {
111111
* @param array $values
112112
*/
113113
protected function formatResults(&$values) {
114-
$fields = array_column($this->fields(), 'name');
114+
$fieldDefaults = array_column($this->fields(), 'default_value', 'name') +
115+
array_fill_keys(array_column($this->fields(), 'name'), NULL);
115116
// Enforce field permissions
116117
if ($this->checkPermissions) {
117118
foreach ($values as $key => $field) {
@@ -124,17 +125,15 @@ protected function formatResults(&$values) {
124125
$defaults = array_intersect_key([
125126
'title' => empty($field['name']) ? NULL : ucwords(str_replace('_', ' ', $field['name'])),
126127
'entity' => $this->getEntityName(),
127-
'required' => FALSE,
128-
'readonly' => FALSE,
129128
'options' => !empty($field['pseudoconstant']),
130-
'data_type' => \CRM_Utils_Array::value('type', $field, 'String'),
131-
], array_flip($fields));
132-
$field += $defaults;
133-
$field['label'] = $field['label'] ?? $field['title'];
129+
], $fieldDefaults);
130+
$field += $defaults + $fieldDefaults;
131+
if (array_key_exists('label', $fieldDefaults)) {
132+
$field['label'] = $field['label'] ?? $field['title'] ?? $field['name'];
133+
}
134134
if (isset($defaults['options'])) {
135135
$field['options'] = $this->formatOptionList($field['options']);
136136
}
137-
$field += array_fill_keys($fields, NULL);
138137
}
139138
}
140139

@@ -261,6 +260,7 @@ public function fields() {
261260
[
262261
'name' => 'required',
263262
'data_type' => 'Boolean',
263+
'default_value' => FALSE,
264264
],
265265
[
266266
'name' => 'required_if',
@@ -269,10 +269,11 @@ public function fields() {
269269
[
270270
'name' => 'options',
271271
'data_type' => 'Array',
272+
'default_value' => FALSE,
272273
],
273274
[
274275
'name' => 'data_type',
275-
'data_type' => 'String',
276+
'default_value' => 'String',
276277
'options' => [
277278
'Array' => ts('Array'),
278279
'Boolean' => ts('Boolean'),
@@ -319,6 +320,7 @@ public function fields() {
319320
'name' => 'readonly',
320321
'data_type' => 'Boolean',
321322
'description' => 'True for auto-increment, calculated, or otherwise non-editable fields.',
323+
'default_value' => FALSE,
322324
],
323325
[
324326
'name' => 'output_formatters',

xml/schema/Core/CustomGroup.xml

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
<html>
148148
<label>Table Name</label>
149149
</html>
150+
<readonly>true</readonly>
150151
<add>2.0</add>
151152
</field>
152153
<field>

0 commit comments

Comments
 (0)