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

Fix editing and saving a template contribution via form #21471

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions CRM/Contribute/Form/Contribution.php
Expand Up @@ -311,7 +311,7 @@ public function preProcess() {
$this->assign('payNow', $this->_payNow);
$this->setTitle(ts('Pay with Credit Card'));
}
elseif (!empty($this->_values['is_template'])) {
elseif ($this->_values['is_template']) {
$this->setPageTitle(ts('Template Contribution'));
}
elseif ($this->_mode) {
Expand Down 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 @@ -695,8 +701,10 @@ public function buildQuickForm() {
}
}

// If contribution is a template receive date is not required
$receiveDateRequired = !$this->_values['is_template'];
// add various dates
$this->addField('receive_date', ['entity' => 'contribution'], !$this->_mode, FALSE);
$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 @@ -884,6 +892,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['is_template'] != 1
) {
CRM_Contribute_BAO_Contribution::checkStatusValidation($self->_values, $fields, $errors);
}
Expand Down Expand Up @@ -943,6 +952,12 @@ public function postProcess() {
}
// Get the submitted form values.
$submittedValues = $this->controller->exportValues($this->_name);
if ($this->_values['is_template']) {
// If we are a template contribution we don't allow the contribution_status_id to be set
// on the form but we need it for the submit function.
$submittedValues['is_template'] = $this->_values['is_template'];
$submittedValues['contribution_status_id'] = $this->_values['contribution_status_id'];
}

try {
$contribution = $this->submit($submittedValues, $this->_action, $this->_ppID);
Expand Down