Allow EntityReference custom fields to store multiple values - #36353
Open
mattwire wants to merge 1 commit into
Open
Allow EntityReference custom fields to store multiple values#36353mattwire wants to merge 1 commit into
mattwire wants to merge 1 commit into
Conversation
|
🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷 Introduction for new contributors...
PR commands & links...
|
mattwire
force-pushed
the
entityref-multi-value
branch
from
July 28, 2026 14:04
736ce29 to
40e2e38
Compare
mattwire
added a commit
to mattwire/civicrm-core
that referenced
this pull request
Jul 28, 2026
# Conflicts: # CRM/Core/BAO/CustomField.php # tests/phpunit/CRM/Core/BAO/CustomFieldTest.php
mattwire
added a commit
to mattwire/civicrm-core
that referenced
this pull request
Jul 28, 2026
# Conflicts: # CRM/Core/BAO/CustomField.php # tests/phpunit/CRM/Core/BAO/CustomFieldTest.php
The storage layer already supported this (serialize -> text column, FK
constraint already skipped for serialized EntityReference) but it was
never exposed: the UI hid the "Multi-Select" toggle for EntityReference,
the widget never passed serialize through to select.multiple, and
formatDisplayValue() broke on ->single() for more than one value.
Also fixes two related bugs found via live QA: an empty serialized value
reaching formatDisplayValue() as a raw array crashed the custom-data view
template ("Array to string conversion"), and GetLinks::replaceTokens()
threw when a token resolved to an array instead of a string - now
unwraps an unambiguous single-item array and drops the link otherwise.
mattwire
force-pushed
the
entityref-multi-value
branch
from
July 28, 2026 22:44
40e2e38 to
99ff71f
Compare
mattwire
added a commit
to mattwire/civicrm-core
that referenced
this pull request
Jul 28, 2026
# Conflicts: # CRM/Core/BAO/CustomField.php # tests/phpunit/CRM/Core/BAO/CustomFieldTest.php
Member
|
@mattwire after the debacle with multi-valued ContactReference custom fields, we agreed "let's never do this again." In hindsight, it was a mistake as it breaks FK links, breaks searchability, breaks sortability, etc. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Enable multi-select for EntityReference fields. Just like we can do for Contacts.
Config:
Single select:
Multi select:
Before
EntityReference custom fields can't be multi-select.
After
EntityReference custom fields can be multi-select.
Technical Details
The storage layer already fully supported this: fieldToSQLType() returns 'text' for any serialized field regardless of data type, and prepareCreateParams() already skips the FK constraint for a serialized EntityReference field ("Serialized fields store value-separated strings which are incompatible with FK constraints"). It was only ever exposed through the UI/widget for other Autocomplete-Select fields, not this one:
Comments