'name' => 'label_field',
'description' => 'Field to show when displaying a record',
],
+ [
+ 'name' => 'icon_field',
+ 'data_type' => 'Array',
+ 'description' => 'Field(s) which contain the icon for a record, listed in order of precedence',
+ ],
[
'name' => 'order_by',
'description' => 'Default column to sort results',
$info['label_field'] = $dao::$_labelField;
$info['dao'] = $dao;
$info['table_name'] = $dao::$_tableName;
+ $info['icon_field'] = (array) ($dao::fields()['icon']['name'] ?? NULL);
}
foreach (ReflectionUtils::getTraits(static::class) as $trait) {
$info['type'][] = self::stripNamespace($trait);
$fields = CoreUtil::getApiClass($entityName)::get()->entityFields();
$idField = CoreUtil::getIdFieldName($entityName);
$labelField = CoreUtil::getInfoItem($entityName, 'label_field');
+ $iconFields = CoreUtil::getInfoItem($entityName, 'icon_field') ?? [];
$map = [
'id' => $idField,
'label' => $labelField,
if (isset($fields['color'])) {
$map['color'] = 'color';
}
- if (isset($fields['icon'])) {
- $map['icon'] = 'icon';
- }
+ $select = array_merge(array_values($map), $iconFields);
if (!$this->savedSearch) {
$this->savedSearch = ['api_entity' => $entityName];
}
}
if (empty($this->_apiParams['having'])) {
- $this->_apiParams['select'] = array_values($map);
+ $this->_apiParams['select'] = $select;
}
else {
- $this->_apiParams['select'] = array_merge($this->_apiParams['select'], array_values($map));
+ $this->_apiParams['select'] = array_merge($this->_apiParams['select'], $select);
}
$this->_apiParams['checkPermissions'] = $this->getCheckPermissions();
$apiResult = civicrm_api4($entityName, 'get', $this->_apiParams);
foreach ($map as $key => $fieldName) {
$mapped[$key] = $row[$fieldName];
}
+ foreach ($iconFields as $fieldName) {
+ if (!empty($row[$fieldName])) {
+ $mapped['icon'] = $row[$fieldName];
+ break;
+ }
+ }
$result[] = $mapped;
}
$result->setCountMatched($apiResult->countFetched());