@@ -111,7 +111,8 @@ public function _run(Result $result) {
111
111
* @param array $values
112
112
*/
113
113
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 );
115
116
// Enforce field permissions
116
117
if ($ this ->checkPermissions ) {
117
118
foreach ($ values as $ key => $ field ) {
@@ -124,17 +125,15 @@ protected function formatResults(&$values) {
124
125
$ defaults = array_intersect_key ([
125
126
'title ' => empty ($ field ['name ' ]) ? NULL : ucwords (str_replace ('_ ' , ' ' , $ field ['name ' ])),
126
127
'entity ' => $ this ->getEntityName (),
127
- 'required ' => FALSE ,
128
- 'readonly ' => FALSE ,
129
128
'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
+ }
134
134
if (isset ($ defaults ['options ' ])) {
135
135
$ field ['options ' ] = $ this ->formatOptionList ($ field ['options ' ]);
136
136
}
137
- $ field += array_fill_keys ($ fields , NULL );
138
137
}
139
138
}
140
139
@@ -261,6 +260,7 @@ public function fields() {
261
260
[
262
261
'name ' => 'required ' ,
263
262
'data_type ' => 'Boolean ' ,
263
+ 'default_value ' => FALSE ,
264
264
],
265
265
[
266
266
'name ' => 'required_if ' ,
@@ -269,10 +269,11 @@ public function fields() {
269
269
[
270
270
'name ' => 'options ' ,
271
271
'data_type ' => 'Array ' ,
272
+ 'default_value ' => FALSE ,
272
273
],
273
274
[
274
275
'name ' => 'data_type ' ,
275
- 'data_type ' => 'String ' ,
276
+ 'default_value ' => 'String ' ,
276
277
'options ' => [
277
278
'Array ' => ts ('Array ' ),
278
279
'Boolean ' => ts ('Boolean ' ),
@@ -319,6 +320,7 @@ public function fields() {
319
320
'name ' => 'readonly ' ,
320
321
'data_type ' => 'Boolean ' ,
321
322
'description ' => 'True for auto-increment, calculated, or otherwise non-editable fields. ' ,
323
+ 'default_value ' => FALSE ,
322
324
],
323
325
[
324
326
'name ' => 'output_formatters ' ,
0 commit comments