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

dev/core#553: Creating new event takes value from default value not from saved template for custom fields #14480

Merged
merged 1 commit into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions CRM/Core/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -1599,11 +1599,14 @@ public static function freeResult($ids = NULL) {
* @param string $blockCopyOfDependencies
* Fields that you want to block from.
* getting copied
* @param bool $blockCopyofCustomValues
* Case when you don't want to copy the custom values set in a
* template as it will override/ignore the submitted custom values
*
* @return CRM_Core_DAO|bool
* the newly created copy of the object. False if none created.
*/
public static function copyGeneric($daoName, $criteria, $newData = NULL, $fieldsFix = NULL, $blockCopyOfDependencies = NULL) {
public static function copyGeneric($daoName, $criteria, $newData = NULL, $fieldsFix = NULL, $blockCopyOfDependencies = NULL, $blockCopyofCustomValues = FALSE) {
$object = new $daoName();
$newObject = FALSE;
if (!$newData) {
Expand Down Expand Up @@ -1671,7 +1674,9 @@ public static function copyGeneric($daoName, $criteria, $newData = NULL, $fields
}
}
$newObject->save();
$newObject->copyCustomFields($object->id, $newObject->id);
if (!$blockCopyofCustomValues) {
$newObject->copyCustomFields($object->id, $newObject->id);
}
CRM_Utils_Hook::post('create', CRM_Core_DAO_AllCoreTables::getBriefName($daoName), $newObject->id, $newObject);
}

Expand Down
10 changes: 9 additions & 1 deletion CRM/Event/BAO/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -946,11 +946,15 @@ public static function copy($id, $params = []) {
$fieldsFix['prefix']['is_show_location'] = 0;
}

$blockCopyOfCustomValue = (!empty($params['custom']));

$copyEvent = CRM_Core_DAO::copyGeneric('CRM_Event_DAO_Event',
['id' => $id],
// since the location is sharable, lets use the same loc_block_id.
['loc_block_id' => CRM_Utils_Array::value('loc_block_id', $eventValues)] + $params,
$fieldsFix
$fieldsFix,
NULL,
$blockCopyOfCustomValue
);
CRM_Price_BAO_PriceSet::copyPriceSet('civicrm_event', $id, $copyEvent->id);
CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin',
Expand Down Expand Up @@ -991,6 +995,10 @@ public static function copy($id, $params = []) {

$copyEvent->save();

if ($blockCopyOfCustomValue) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_event', $copyEvent->id);
}

CRM_Utils_System::flushCache();
CRM_Utils_Hook::copy('Event', $copyEvent);

Expand Down
30 changes: 17 additions & 13 deletions CRM/Event/Form/ManageEvent/EventInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ public function preProcess() {
parent::preProcess();
$this->assign('selectedChild', 'settings');

if ($this->_id) {
$this->assign('entityID', $this->_id);
$entityID = $this->_id ?: $this->_templateId;
if ($entityID) {
$this->assign('entityID', $entityID);
$eventType = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event',
$this->_id,
$entityID,
'event_type_id'
);
}
Expand Down Expand Up @@ -127,7 +128,6 @@ public function buildQuickForm() {
if ($this->_eventType) {
$this->assign('customDataSubType', $this->_eventType);
}
$this->assign('entityId', $this->_id);

$this->_first = TRUE;
$this->applyFilter('__ALL__', 'trim');
Expand Down Expand Up @@ -228,7 +228,7 @@ public static function formRule($values) {
* Process the form submission.
*/
public function postProcess() {
$params = $this->controller->exportValues($this->_name);
$params = array_merge($this->controller->exportValues($this->_name), $this->_submitValues);

//format params
$params['start_date'] = CRM_Utils_Array::value('start_date', $params);
Expand All @@ -241,19 +241,23 @@ public function postProcess() {
$params['default_role_id'] = CRM_Utils_Array::value('default_role_id', $params, FALSE);
$params['id'] = $this->_id;

$customFields = CRM_Core_BAO_CustomField::getFields('Event', FALSE, FALSE,
CRM_Utils_Array::value('event_type_id', $params)
);
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params,
$this->_id,
'Event'
);

//merge params with defaults from templates
if (!empty($params['template_id'])) {
$params = array_merge(CRM_Event_BAO_Event::getTemplateDefaultValues($params['template_id']), $params);
foreach ($params as $key => $value) {
$customFieldInfo = CRM_Core_BAO_CustomField::getKeyID($key, TRUE);
if (!empty($customFieldInfo[1])) {
$params[str_replace($customFieldInfo[1], '-' . $customFieldInfo[1], $key)] = $value;
unset($params[$key]);
}
}
}

$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params,
$this->_id,
'Event'
);

// now that we have the event’s id, do some more template-based stuff
if (!empty($params['template_id'])) {
$event = CRM_Event_BAO_Event::copy($params['template_id'], $params);
Expand Down