Skip to content

Commit

Permalink
Afform - Exclude LocBlock fields that will be replaced by joins
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Aug 17, 2024
1 parent e5dbfd5 commit 8dca139
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ext/afform/admin/Civi/AfformAdmin/AfformAdminMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public static function getFields($entityName, $params = []) {
}
$params['values']['state_province_id'] = \Civi::settings()->get('defaultContactStateProvince');
}
// Exclude LocBlock fields that will be replaced by joins (see below)
if ($params['action'] === 'create' && $entityName === 'LocBlock') {
$params['where'][] = ['fk_entity', 'IS NULL'];
}
$fields = (array) civicrm_api4($entityName, 'getFields', $params);
// Add implicit joins to search fields
if ($params['action'] === 'get') {
Expand All @@ -121,6 +125,7 @@ public static function getFields($entityName, $params = []) {
if ($params['action'] === 'create' && $entityName === 'LocBlock') {
$joinParams = $params;
// Exclude fields that don't apply to locBlocks
array_pop($joinParams['where']);
$joinParams['where'][] = ['name', 'NOT IN', ['id', 'is_primary', 'is_billing', 'location_type_id', 'contact_id']];
foreach (['Address', 'Email', 'Phone', 'IM'] as $joinEntity) {
$joinEntityFields = (array) civicrm_api4($joinEntity, 'getFields', $joinParams);
Expand Down

0 comments on commit 8dca139

Please sign in to comment.