From a4f468b6acd6b9c96c81a199009827a2d629fcd0 Mon Sep 17 00:00:00 2001 From: eileen Date: Sun, 29 Apr 2018 18:17:02 +1200 Subject: [PATCH] Fix Participant batch update to work with multiple value custom fields --- CRM/Event/Form/Task/Batch.php | 8 ++++++++ tests/phpunit/CRM/Event/Form/Task/BatchTest.php | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CRM/Event/Form/Task/Batch.php b/CRM/Event/Form/Task/Batch.php index fe71dc15e0..04927e1d09 100644 --- a/CRM/Event/Form/Task/Batch.php +++ b/CRM/Event/Form/Task/Batch.php @@ -474,6 +474,14 @@ class CRM_Event_Form_Task_Batch extends CRM_Event_Form_Task { $key, 'Participant' ); + foreach (array_keys($value) as $fieldName) { + // Unset the original custom field now that it has been formatting to the 'custom' + // array as it may not be in the right format for the api as is (notably for + // multiple checkbox values). + if (substr($fieldName, 0, 7) === 'custom_') { + unset($value[$fieldName]); + } + } $value['id'] = $key; diff --git a/tests/phpunit/CRM/Event/Form/Task/BatchTest.php b/tests/phpunit/CRM/Event/Form/Task/BatchTest.php index ad9b895a15..812c26ca18 100644 --- a/tests/phpunit/CRM/Event/Form/Task/BatchTest.php +++ b/tests/phpunit/CRM/Event/Form/Task/BatchTest.php @@ -9,14 +9,17 @@ class CRM_Event_Form_Task_BatchTest extends CiviUnitTestCase { public function testSubmit() { + $group = $this->CustomGroupCreate(['extends' => 'Participant', 'title' => 'Participant']); + $field = $this->customFieldCreate(['custom_group_id' => $group['id'], 'html_type' => 'CheckBox', 'option_values' => ['two' => 'A couple', 'three' => 'A few', 'four' => 'Too Many']]); $participantID = $this->participantCreate(); $participant = $this->callAPISuccessGetSingle('Participant', ['id' => $participantID]); $this->assertEquals(2, $participant['participant_status_id']); $form = $this->getFormObject('CRM_Event_Form_Task_Batch'); - $form->submit(['field' => [$participantID => ['participant_status_id' => 1]]]); + $form->submit(['field' => [$participantID => ['participant_status_id' => 1, 'custom_' . $field['id'] => ['two' => 1, 'four' => 1]]]]); $participant = $this->callAPISuccessGetSingle('Participant', ['id' => $participantID]); $this->assertEquals(1, $participant['participant_status_id']); } + } -- 2.25.1