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

Allow values to be passed to api4 GetFields #16154

Merged
merged 1 commit into from
Dec 30, 2019

Conversation

colemanw
Copy link
Member

Overview

When doing GetFields from the api, some fields only apply to certain contact types.
This is a step toward getting filtering on api4 getFields by accepting values as a param.

Before

GetFields returns all fields.

After

It's now possible to filter getFields by contact type, only returning custom fields appropriate to certain contact types.

Technical Details

This also fixes a bug where multi-record custom sets were being returned in contact getFields.

Comments

So far this only filters custom fields by contact type, but values is now being passed to allow more filtering in future.

@civibot
Copy link

civibot bot commented Dec 28, 2019

(Standard links)

@civibot civibot bot added the master label Dec 28, 2019
@seamuslee001
Copy link
Contributor

@seamuslee001
Copy link
Contributor

@colemanw just checking if you say specified contact_type as individual will this still return custom fields where no contact_type has been specified?, Also do we need to consider the subtype as well?

So far this only filters custom fields by contact type,
but values is now being passed to allow more filtering.
@colemanw
Copy link
Member Author

@seamuslee001 I've fixed the style warning.
Yes there a lot of sub-types to consider (not just contact but also activity, event, case, etc). I will do a followup PR for those, but this one is at least a step in the right direction.

$getFields = Contact::getFields()->setCheckPermissions(FALSE);
$this->assertContains('MyIndividualFields.FavColor', $getFields->execute()->column('name'));
$this->assertContains('MyIndividualFields.FavColor', $getFields->setValues(['contact_type' => 'Individual'])->execute()->column('name'));
$this->assertNotContains('MyIndividualFields.FavColor', $getFields->setValues(['contact_type' => 'Household'])->execute()->column('name'));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seamuslee001 this test asserts that fields for Individual are returned even if no contact type is specified.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@colemanw i was more thinking of if you specified Individual in the contact type when doing a getfields that custom fields for All contacts are still returned

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does.

@colemanw
Copy link
Member Author

@seamuslee001 once this is merged I have a couple followup PRs for further improvements.

@eileenmcnaughton
Copy link
Contributor

I think this is OK to merge - it's a new api feature with a test & I think we still want to keep apiv4 moving fairly fluidly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants