Skip to content

Commit

Permalink
dev/core#2096 Fix in-master-only regression on creating new events
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Oct 8, 2020
1 parent 8878666 commit 7af49a6
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions CRM/Event/Form/ManageEvent/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,20 @@ public function postProcess() {

$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])) {
$params[$block][$index]['id'] = $this->locationBlock['loc_block.' . $block . $fieldKey];
}
}
}
$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([
[
Expand Down Expand Up @@ -283,4 +287,27 @@ public function getTitle() {
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;
}

}

0 comments on commit 7af49a6

Please sign in to comment.