Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APIv4 - Fix getFields to respect default_value from getFields #20481

Merged
merged 1 commit into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion 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:fc2cf4a8b27ca8d4eaced3f1a3fcddd5)
* (GenCodeChecksum:ddee40c6f144396056437d29bc0337d7)
*/

/**
Expand Down Expand Up @@ -437,6 +437,7 @@ public static function &fields() {
'html' => [
'label' => ts("Table Name"),
],
'readonly' => TRUE,
'add' => '2.0',
],
'is_multiple' => [
Expand Down
20 changes: 11 additions & 9 deletions Civi/Api4/Generic/BasicGetFieldsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public function _run(Result $result) {
* @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) {
Expand All @@ -124,17 +125,15 @@ protected function formatResults(&$values) {
$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);
}
}

Expand Down Expand Up @@ -261,6 +260,7 @@ public function fields() {
[
'name' => 'required',
'data_type' => 'Boolean',
'default_value' => FALSE,
],
[
'name' => 'required_if',
Expand All @@ -269,10 +269,11 @@ public function fields() {
[
'name' => 'options',
'data_type' => 'Array',
'default_value' => FALSE,
],
[
'name' => 'data_type',
'data_type' => 'String',
'default_value' => 'String',
'options' => [
'Array' => ts('Array'),
'Boolean' => ts('Boolean'),
Expand Down Expand Up @@ -319,6 +320,7 @@ public function fields() {
'name' => 'readonly',
'data_type' => 'Boolean',
'description' => 'True for auto-increment, calculated, or otherwise non-editable fields.',
'default_value' => FALSE,
],
[
'name' => 'output_formatters',
Expand Down
1 change: 1 addition & 0 deletions xml/schema/Core/CustomGroup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
<html>
<label>Table Name</label>
</html>
<readonly>true</readonly>
<add>2.0</add>
</field>
<field>
Expand Down