$indexField = $index && is_string($index) && !CRM_Utils_Rule::integer($index) ? $index : NULL;
$removeIndexField = FALSE;
- // If index field is not part of the select query, we add it here and remove it below
- if ($indexField && !empty($params['select']) && is_array($params['select']) && !\Civi\Api4\Utils\SelectUtil::isFieldSelected($indexField, $params['select'])) {
+ // If index field is not part of the select query, we add it here and remove it below (except for oddball "Setting" api)
+ if ($indexField && !empty($params['select']) && is_array($params['select']) && $entity !== 'Setting' && !\Civi\Api4\Utils\SelectUtil::isFieldSelected($indexField, $params['select'])) {
$params['select'][] = $indexField;
$removeIndexField = TRUE;
}
if ($index && is_array($index)) {
$indexCol = reset($index);
$indexField = key($index);
- if (property_exists($apiCall, 'select')) {
+ // Index array indicates only 1 or 2 fields need to be selected (except for oddball "Setting" api)
+ if ($entity !== 'Setting' && property_exists($apiCall, 'select')) {
$apiCall->setSelect([$indexCol]);
if ($indexField && $indexField != $indexCol) {
$apiCall->addSelect($indexField);
$this->assertTrue(is_array($settings[0]['value']));
}
+ /**
+ * Ensure settings work with the "index" mode.
+ */
+ public function testSettingsWithIndexParam() {
+ $settings = civicrm_api4('Setting', 'get', [], ['name' => 'value']);
+ $stringValues = FALSE;
+ $arrayValues = FALSE;
+ // With indexing by [name => value], keys should be string and values should be string/array
+ foreach ($settings as $name => $value) {
+ $this->assertTrue(is_string($name) && !is_numeric($name));
+ if (is_string($value)) {
+ $stringValues = TRUE;
+ }
+ elseif (is_array($value)) {
+ $arrayValues = TRUE;
+ }
+ }
+ $this->assertTrue($stringValues);
+ $this->assertTrue($arrayValues);
+ }
+
}