Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APIv4 - Improve custom field spec gathering #17471

Merged
merged 1 commit into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Civi/Api4/Service/Schema/Joinable/CustomGroupJoinable.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getEntityFields() {
if (!$this->entityFields) {
$fields = CustomField::get()
->setCheckPermissions(FALSE)
->setSelect(['custom_group.name', 'custom_group.extends', '*'])
->setSelect(['custom_group.name', 'custom_group.extends', 'custom_group.table_name', '*'])
->addWhere('custom_group.table_name', '=', $this->getTargetTable())
->execute();
foreach ($fields as $field) {
Expand Down
11 changes: 10 additions & 1 deletion Civi/Api4/Service/Spec/SpecGatherer.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,24 @@ private function addDAOFields($entity, $action, RequestSpec $specification, $val
}

/**
* Get custom fields that extend this entity
*
* @see \CRM_Core_SelectValues::customGroupExtends
*
* @param string $entity
* @param \Civi\Api4\Service\Spec\RequestSpec $specification
* @param array $values
* @throws \API_Exception
*/
private function addCustomFields($entity, RequestSpec $specification, $values = []) {
// Custom_group.extends pretty much maps 1-1 with entity names, except for a couple oddballs (Contact, Participant).
$extends = [$entity];
if ($entity === 'Contact') {
$extends = !empty($values['contact_type']) ? [$values['contact_type'], 'Contact'] : ['Contact', 'Individual', 'Organization', 'Household'];
$contactType = !empty($values['contact_type']) ? [$values['contact_type']] : \CRM_Contact_BAO_ContactType::basicTypes();
$extends = array_merge(['Contact'], $contactType);
}
if ($entity === 'Participant') {
$extends = ['Participant', 'ParticipantRole', 'ParticipantEventName', 'ParticipantEventType'];
}
$customFields = CustomField::get()
->setCheckPermissions(FALSE)
Expand Down