From 6fb855460e99597f5edfc288247ecf2273c92661 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 3 May 2021 10:06:32 -0400 Subject: [PATCH] APIv4 - Add `readonly` property to settings getFields --- Civi/Api4/Action/Setting/GetFields.php | 9 +++++++++ Civi/Api4/Generic/BasicGetFieldsAction.php | 1 + 2 files changed, 10 insertions(+) diff --git a/Civi/Api4/Action/Setting/GetFields.php b/Civi/Api4/Action/Setting/GetFields.php index bcd9a04821..dab2446268 100644 --- a/Civi/Api4/Action/Setting/GetFields.php +++ b/Civi/Api4/Action/Setting/GetFields.php @@ -31,6 +31,7 @@ class GetFields extends \Civi\Api4\Generic\BasicGetFieldsAction { $names = $this->_itemsToGet('name'); $filter = $names ? ['name' => $names] : []; $settings = \Civi\Core\SettingsMetadata::getMetadata($filter, $this->domainId, $this->loadOptions); + $getReadonly = $this->_isFieldSelected('readonly'); foreach ($settings as $index => $setting) { // Unserialize default value if (!empty($setting['serialize']) && !empty($setting['default']) && is_string($setting['default'])) { @@ -39,6 +40,9 @@ class GetFields extends \Civi\Api4\Generic\BasicGetFieldsAction { if (!isset($setting['options'])) { $setting['options'] = !empty($setting['pseudoconstant']); } + if ($getReadonly) { + $setting['readonly'] = \Civi::settings()->getMandatory($setting['name']) !== NULL; + } // Filter out deprecated properties $settings[$index] = array_intersect_key($setting, array_column($this->fields(), NULL, 'name')); } @@ -87,6 +91,11 @@ class GetFields extends \Civi\Api4\Generic\BasicGetFieldsAction { 'name' => 'data_type', 'data_type' => 'Integer', ], + [ + 'name' => 'readonly', + 'data_type' => 'Boolean', + 'description' => 'True if value is set in code and cannot be overridden.', + ], ]; } diff --git a/Civi/Api4/Generic/BasicGetFieldsAction.php b/Civi/Api4/Generic/BasicGetFieldsAction.php index 124ba7f821..c554e5c1d9 100644 --- a/Civi/Api4/Generic/BasicGetFieldsAction.php +++ b/Civi/Api4/Generic/BasicGetFieldsAction.php @@ -318,6 +318,7 @@ class BasicGetFieldsAction extends BasicGetAction { [ 'name' => 'readonly', 'data_type' => 'Boolean', + 'description' => 'True for auto-increment, calculated, or otherwise non-editable fields.', ], [ 'name' => 'output_formatters', -- 2.25.1