Skip to content

Commit

Permalink
Fix editing and saving a template contribution via form
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire committed Nov 30, 2021
1 parent da410c8 commit 6e6752e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion CRM/Contribute/Form/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,12 @@ public function setDefaultValues() {
$defaults['refund_trxn_id'] = $defaults['trxn_id'] ?? NULL;
}

if (!empty($defaults['contribution_status_id'])
&& ('Template' === CRM_Contribute_PseudoConstant::contributionStatus($defaults['contribution_status_id'], 'name'))
) {
$this->getElement('contribution_status_id')->freeze();
}

if (!$this->_id && empty($defaults['receive_date'])) {
$defaults['receive_date'] = date('Y-m-d H:i:s');
}
Expand Down Expand Up @@ -701,7 +707,8 @@ public function buildQuickForm() {
}

// add various dates
$this->addField('receive_date', ['entity' => 'contribution'], !$this->_mode, FALSE);
$receiveDateRequired = !($this->_values['is_test'] ?? FALSE) && ((int) $this->_values['is_template'] !== 1);
$this->addField('receive_date', ['entity' => 'contribution'], $receiveDateRequired, FALSE);
$this->addField('receipt_date', ['entity' => 'contribution'], FALSE, FALSE);
$this->addField('cancel_date', ['entity' => 'contribution', 'label' => ts('Cancelled / Refunded Date')], FALSE, FALSE);

Expand Down Expand Up @@ -889,6 +896,7 @@ public static function formRule($fields, $files, $self) {
if (($self->_action & CRM_Core_Action::UPDATE)
&& $self->_id
&& $self->_values['contribution_status_id'] != $fields['contribution_status_id']
&& $self->_values['contribution_status_id'] != CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Template')
) {
CRM_Contribute_BAO_Contribution::checkStatusValidation($self->_values, $fields, $errors);
}
Expand Down

0 comments on commit 6e6752e

Please sign in to comment.