From 7af49a64c8f25e05e5cf0b08c6644f7d12793507 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 8 Oct 2020 15:19:08 +1300 Subject: [PATCH] dev/core#2096 Fix in-master-only regression on creating new events --- CRM/Event/Form/ManageEvent/Location.php | 33 ++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/CRM/Event/Form/ManageEvent/Location.php b/CRM/Event/Form/ManageEvent/Location.php index aa5aca492a..3314d035eb 100644 --- a/CRM/Event/Form/ManageEvent/Location.php +++ b/CRM/Event/Form/ManageEvent/Location.php @@ -243,6 +243,10 @@ class CRM_Event_Form_ManageEvent_Location extends CRM_Event_Form_ManageEvent { $params[$block][1]['is_primary'] = 1; foreach ($locationEntities as $index => $locationEntity) { + if (!$this->isLocationHasData($block, $locationEntity)) { + unset($params[$block][$index]); + continue; + } $params[$block][$index]['location_type_id'] = $defaultLocationTypeID; $fieldKey = (int) $index === 1 ? '_id' : '_2_id'; if ($isUpdateToExistingLocationBlock && !empty($this->locationBlock['loc_block.' . $block . $fieldKey])) { @@ -250,9 +254,9 @@ class CRM_Event_Form_ManageEvent_Location extends CRM_Event_Form_ManageEvent { } } } - $addresses = Address::save(FALSE)->setRecords($params['address'])->execute(); - $emails = Email::save(FALSE)->setRecords($params['email'])->execute(); - $phones = Phone::save(FALSE)->setRecords($params['phone'])->execute(); + $addresses = empty($params['address']) ? [] : Address::save(FALSE)->setRecords($params['address'])->execute(); + $emails = empty($params['email']) ? [] : Email::save(FALSE)->setRecords($params['email'])->execute(); + $phones = empty($params['phone']) ? [] : Phone::save(FALSE)->setRecords($params['phone'])->execute(); $params['loc_block_id'] = LocBlock::save(FALSE)->setRecords([ [ @@ -283,4 +287,27 @@ class CRM_Event_Form_ManageEvent_Location extends CRM_Event_Form_ManageEvent { return ts('Event Location'); } + /** + * Is there some data to save for the given entity + * + * @param string $block + * @param array $locationEntity + * + * @return bool + */ + protected function isLocationHasData(string $block, array $locationEntity): bool { + if ($block === 'email') { + return !empty($locationEntity['email']); + } + if ($block === 'phone') { + return !empty($locationEntity['phone']); + } + foreach ($locationEntity as $value) { + if (!empty($value)) { + return TRUE; + } + } + return FALSE; + } + } -- 2.25.1