Skip to content
Snippets Groups Projects
Unverified Commit a674c37c authored by Eileen McNaughton's avatar Eileen McNaughton Committed by GitHub
Browse files

Merge pull request #20481 from colemanw/getFieldsFix

APIv4 - Fix getFields to respect default_value from getFields
parents bedd4475 88620a59
Branches
Tags
No related merge requests found
......@@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Core/CustomGroup.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:fc2cf4a8b27ca8d4eaced3f1a3fcddd5)
* (GenCodeChecksum:ddee40c6f144396056437d29bc0337d7)
*/
/**
......@@ -437,6 +437,7 @@ class CRM_Core_DAO_CustomGroup extends CRM_Core_DAO {
'html' => [
'label' => ts("Table Name"),
],
'readonly' => TRUE,
'add' => '2.0',
],
'is_multiple' => [
......
......@@ -111,7 +111,8 @@ class BasicGetFieldsAction extends BasicGetAction {
* @param array $values
*/
protected function formatResults(&$values) {
$fields = array_column($this->fields(), 'name');
$fieldDefaults = array_column($this->fields(), 'default_value', 'name') +
array_fill_keys(array_column($this->fields(), 'name'), NULL);
// Enforce field permissions
if ($this->checkPermissions) {
foreach ($values as $key => $field) {
......@@ -124,17 +125,15 @@ class BasicGetFieldsAction extends BasicGetAction {
$defaults = array_intersect_key([
'title' => empty($field['name']) ? NULL : ucwords(str_replace('_', ' ', $field['name'])),
'entity' => $this->getEntityName(),
'required' => FALSE,
'readonly' => FALSE,
'options' => !empty($field['pseudoconstant']),
'data_type' => \CRM_Utils_Array::value('type', $field, 'String'),
], array_flip($fields));
$field += $defaults;
$field['label'] = $field['label'] ?? $field['title'];
], $fieldDefaults);
$field += $defaults + $fieldDefaults;
if (array_key_exists('label', $fieldDefaults)) {
$field['label'] = $field['label'] ?? $field['title'] ?? $field['name'];
}
if (isset($defaults['options'])) {
$field['options'] = $this->formatOptionList($field['options']);
}
$field += array_fill_keys($fields, NULL);
}
}
......@@ -261,6 +260,7 @@ class BasicGetFieldsAction extends BasicGetAction {
[
'name' => 'required',
'data_type' => 'Boolean',
'default_value' => FALSE,
],
[
'name' => 'required_if',
......@@ -269,10 +269,11 @@ class BasicGetFieldsAction extends BasicGetAction {
[
'name' => 'options',
'data_type' => 'Array',
'default_value' => FALSE,
],
[
'name' => 'data_type',
'data_type' => 'String',
'default_value' => 'String',
'options' => [
'Array' => ts('Array'),
'Boolean' => ts('Boolean'),
......@@ -319,6 +320,7 @@ class BasicGetFieldsAction extends BasicGetAction {
'name' => 'readonly',
'data_type' => 'Boolean',
'description' => 'True for auto-increment, calculated, or otherwise non-editable fields.',
'default_value' => FALSE,
],
[
'name' => 'output_formatters',
......
......@@ -147,6 +147,7 @@
<html>
<label>Table Name</label>
</html>
<readonly>true</readonly>
<add>2.0</add>
</field>
<field>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment