APIv4 - Add `readonly` property to settings getFields
authorColeman Watts <coleman@civicrm.org>
Mon, 3 May 2021 14:06:32 +0000 (10:06 -0400)
committerColeman Watts <coleman@civicrm.org>
Tue, 4 May 2021 21:52:58 +0000 (17:52 -0400)
Civi/Api4/Action/Setting/GetFields.php
Civi/Api4/Generic/BasicGetFieldsAction.php

index bcd9a048212d3646cb5dde871ead445668472a0c..dab24462689e0b8d20ecbb0e51b088fa4b8838c5 100644 (file)
@@ -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.',
+      ],
     ];
   }
 
index 124ba7f8213369e2aa26f723ea1091c2cdf5a7a9..c554e5c1d9a6058566399d3ce87eb0acb0040158 100644 (file)
@@ -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',