This makes it easier to tell custom fields apart in SearchKit when they have similar names to core or other custom fields.
This takes advantage of API4.getFields returning both a "title" and "label" attribute.
This keeps "title" the same while appending group title to "label".
$entityFields = (array) \Civi::cache('metadata')->get($cacheKey);
if (!$entityFields) {
$fields = CustomField::get(FALSE)
- ->setSelect(['custom_group.name', 'custom_group.extends', 'custom_group.table_name', '*'])
+ ->setSelect(['custom_group.name', 'custom_group.extends', 'custom_group.table_name', 'custom_group.title', '*'])
->addWhere('custom_group.table_name', '=', $this->getTargetTable())
->execute();
foreach ($fields as $field) {
$field->setColumnName($data['column_name']);
$field->setCustomFieldId($data['id'] ?? NULL);
$field->setCustomGroupName($data['custom_group.name']);
- $field->setTitle($data['label'] ?? NULL);
+ $field->setTitle($data['label']);
+ $field->setLabel($data['custom_group.title'] . ': ' . $data['label']);
$field->setHelpPre($data['help_pre'] ?? NULL);
$field->setHelpPost($data['help_post'] ?? NULL);
$field->setOptions(self::customFieldHasOptions($data));
$customFields = CustomField::get(FALSE)
->addWhere('custom_group.extends', 'IN', $extends)
->addWhere('custom_group.is_multiple', '=', '0')
- ->setSelect(['custom_group.name', '*'])
+ ->setSelect(['custom_group.name', 'custom_group.title', '*'])
->execute();
foreach ($customFields as $fieldArray) {
private function getCustomGroupFields($customGroup, RequestSpec $specification) {
$customFields = CustomField::get(FALSE)
->addWhere('custom_group.name', '=', $customGroup)
- ->setSelect(['custom_group.name', 'custom_group.table_name', '*'])
+ ->setSelect(['custom_group.name', 'custom_group.table_name', 'custom_group.title', '*'])
->execute();
foreach ($customFields as $fieldArray) {
$data = [
'custom_group_id' => $customGroupId,
'custom_group.name' => 'my_group',
+ 'custom_group.title' => 'My Group',
'id' => $customFieldId,
'name' => $name,
+ 'label' => $name,
'data_type' => 'String',
'html_type' => 'Select',
'column_name' => $name,