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

CustomField - Support filters in EntityReference fields #25960

Merged
merged 3 commits into from
Apr 12, 2023

Conversation

colemanw
Copy link
Member

@colemanw colemanw commented Mar 30, 2023

Overview

This adds basic support for filters on the new custom field type EntityReference.

Before

Filters supported on the old ContactReference custom field type, but not for the new EntityReference.
image

After

Filters now work for EntityReference forms. Minimalist "Advanced Filter" textfield now shown for EntityReference as well as ContactReference fields:
image

Technical Details

As of e9fe23e APIv4 started passing anything stored in the CustomField.filter column to the getFields metadata. This completes that work by ensuring the filters are applied at runtime for all forms (both Quickform and Afform), and exposing the filters to the create/edit custom field form.

Comments

This is not a great UX but it's a start. SearchKit-style field selectors would be an improvement but would require mixing Angular code into the create/edit custom field form which is QuickForm-based. Adding Angular code to that form would be a little tricky but not impossible.

@civibot
Copy link

civibot bot commented Mar 30, 2023

(Standard links)

@@ -46,7 +46,8 @@ public function __construct($name = NULL, array $data = [], $dataName = '') {
}

public function setUpHeadless(): CiviEnvBuilder {
return Test::headless()->apply();
// TODO: search_kit should probably be part of the 'headless()' baseline.
return Test::headless()->install(['org.civicrm.search_kit'])->apply();
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this move seems like a good balance.

Coleman linked this in another discussion, where it had been left as an open-question about how far up to move the install(...search_kit...) statement. The tension in that question: Search Kit is a "required extension", but that concept is contradictory:

  • As a "required" thing, it should be enabled by default in all integration tests (to make them more representative of the real runtime - and to avoid redundant boilerplate).
  • As an "extension", it should be a discrete thing with clear boundaries (and you can't enforce/test those boundaries if it's always-on).

That's a tricky line. The current patch is a decent balance (enabling it for a large block of tests where they're likely to be needed -- without making it totally required or affecting 3rd party suites).

This ensures filters are applied on both quickforms and afforms when defined for a custom field.
Note: There is still no UI for adding these filters to a custom field, but they can be set via api explorer.
@colemanw colemanw force-pushed the customAutocompleteFilter branch from c39aded to 85cc9cc Compare April 1, 2023 01:38
@colemanw colemanw changed the title CustomField - Support filters in EntityReference fields on all forms CustomField - Support filters in EntityReference fields Apr 1, 2023
@jensschuppe
Copy link
Contributor

We're currently testing this, I'll add a review soon.

@TychoSchottelius
Copy link

Hi there.
I have now tested the requirements from which this PR arose in our corresponding test environment:

  1. Cases have an additional field of type "Entity-Reference" that references events.
  2. With the filter field I can successfully limit the autocomplete selection to events of a certain type.

This prevents users from confusing the functionalities associated with certain event types.

I was able to define the filters in two different corresponding ways, both of which make sense from my point of view:

  1. event_type_id=11
  2. event_type_id:name=EU-Projekt

@colemanw colemanw added the merge ready PR will be merged after a few days if there are no objections label Apr 11, 2023
@colemanw
Copy link
Member Author

Thanks for the review @TychoSchottelius - sounds like this is merge-ready. Did you have anything to add @jensschuppe or is this good to merge?

@jensschuppe
Copy link
Contributor

@colemanw I think I agree 😄 Thanks, this makes Entity Reference Custom Fields much more useful!

@jensschuppe
Copy link
Contributor

... maybe this should be documented somewhere in the docs, alongside the fact that those global per-field filters will always apply, even when an Afform defines additional filtering via SearchKit.

@colemanw colemanw merged commit fe4d8c2 into civicrm:master Apr 12, 2023
@colemanw colemanw deleted the customAutocompleteFilter branch April 12, 2023 20:03
@peth-systopia
Copy link

Thanks very much @colemanw, this adds a lot more flexiblity and power to CiviCRM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-test master merge ready PR will be merged after a few days if there are no objections
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants