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

Do not add custom fields of custom groups with style other than "Inline" to forms where in the UI those fields are loaded via Ajax #31495

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions CRM/Custom/Form/CustomDataTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ protected function addCustomDataFieldsToForm(string $entity, array $filters = []

$formValues = [];
foreach ($fields as $field) {
// Filter for fields in "Inline" style custom groups only, as others are not added to forms via Ajax. Not removing
// them here would register them in the QuickForm but not have POST values for them, which might result in data
// loss (most notably radio fields, for which no POST value will be interpreted as a reset).
// See https://lab.civicrm.org/dev/core/-/issues/5613
if (!isset(Civi::$statics[__CLASS__]['customGroups'][$field['custom_group']])) {
Civi::$statics[__CLASS__]['customGroups'][$field['custom_group']] = \Civi\Api4\CustomGroup::get(FALSE)
->addSelect('style')
->addWhere('name', '=', $field['custom_group'])
->execute()
->single();
}
if ('Inline' !== Civi::$statics[__CLASS__]['customGroups'][$field['custom_group']]['style']) {
continue;
}

// Here we add the custom fields to the form
// based on whether they have been 'POSTed'
foreach ($this->getInstancesOfField($field['custom_field_id']) as $elementName) {
Expand Down