diff --git a/CRM/Contribute/Form/CancelSubscription.php b/CRM/Contribute/Form/CancelSubscription.php index 27d7f4de416c..97f2e3b2e68d 100644 --- a/CRM/Contribute/Form/CancelSubscription.php +++ b/CRM/Contribute/Form/CancelSubscription.php @@ -40,7 +40,25 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib protected $_mode = NULL; - protected $_selfService = FALSE; + /** + * Should custom data be suppressed on this form. + * + * We override to suppress custom data because historically it has not been + * shown on this form & we don't want to expose it as a by-product of + * other change without establishing that it would be good on this form. + * + * @return bool + */ + protected function isSuppressCustomData() { + return TRUE; + } + + /** + * Is the from being accessed by a front end user to update their own recurring. + * + * @var bool + */ + protected $selfService; /** * Set variables up before form is built. @@ -94,14 +112,6 @@ public function preProcess() { CRM_Core_Error::fatal('Required information missing.'); } - if (!CRM_Core_Permission::check('edit contributions')) { - if ($this->_subscriptionDetails->contact_id != $this->getContactID()) { - CRM_Core_Error::statusBounce(ts('You do not have permission to cancel this recurring contribution.')); - } - $this->_selfService = TRUE; - } - $this->assign('self_service', $this->_selfService); - // handle context redirection CRM_Contribute_BAO_ContributionRecur::setSubscriptionContext(); @@ -114,10 +124,32 @@ public function preProcess() { } } + /** + * Set entity fields for this cancellation. + */ + public function setEntityFields() { + $this->entityFields = [ + 'cancel_reason' => ['name' => 'cancel_reason'], + ]; + if (!$this->isSelfService()) { + $this->entityFields['send_cancel_request'] = [ + 'title' => ts('Send cancellation request to %1 ?', [1 => $this->_paymentProcessorObj->_processorName]), + 'name' => 'send_cancel_request', + 'not-auto-addable' => TRUE, + ]; + $this->entityFields['is_notify'] = [ + 'title' => ts('Notify Contributor?'), + 'name' => 'is_notify', + 'not-auto-addable' => TRUE, + ]; + } + } + /** * Build the form object. */ public function buildQuickForm() { + $this->buildQuickEntityForm(); // Determine if we can cancel recurring contribution via API with this processor $cancelSupported = $this->_paymentProcessorObj->supports('CancelRecurring'); if ($cancelSupported) { @@ -145,7 +177,7 @@ public function buildQuickForm() { } $type = 'next'; - if ($this->_selfService) { + if ($this->isSelfService()) { $type = 'submit'; } @@ -184,7 +216,7 @@ public function postProcess() { $cancelSubscription = TRUE; $params = $this->controller->exportValues($this->_name); - if ($this->_selfService) { + if ($this->isSelfService()) { // for self service force sending-request & notify if ($this->_paymentProcessorObj->supports('cancelRecurring')) { $params['send_cancel_request'] = 1; @@ -308,4 +340,23 @@ public function postProcess() { } } + /** + * Is this being used by a front end user to update their own recurring. + * + * @return bool + */ + protected function isSelfService() { + if (!is_null($this->selfService)) { + return $this->selfService; + } + $this->selfService = FALSE; + if (!CRM_Core_Permission::check('edit contributions')) { + if ($this->_subscriptionDetails->contact_id != $this->getContactID()) { + CRM_Core_Error::statusBounce(ts('You do not have permission to cancel this recurring contribution.')); + } + $this->selfService = TRUE; + } + return $this->selfService; + } + } diff --git a/CRM/Contribute/Form/ContributionRecur.php b/CRM/Contribute/Form/ContributionRecur.php index 24ad75822273..602cbe9d2fee 100644 --- a/CRM/Contribute/Form/ContributionRecur.php +++ b/CRM/Contribute/Form/ContributionRecur.php @@ -107,6 +107,15 @@ public function getDefaultContext() { return 'create'; } + /** + * Get the entity id being edited. + * + * @return int|null + */ + public function getEntityId() { + return $this->contributionRecurID; + } + /** * Set variables up before form is built. */ diff --git a/CRM/Core/Form/EntityFormTrait.php b/CRM/Core/Form/EntityFormTrait.php index 00a5c5b6e092..ff4c41c9403c 100644 --- a/CRM/Core/Form/EntityFormTrait.php +++ b/CRM/Core/Form/EntityFormTrait.php @@ -87,6 +87,15 @@ public function getEntityId() { return $this->_id; } + /** + * Should custom data be suppressed on this form. + * + * @return bool + */ + protected function isSuppressCustomData() { + return FALSE; + } + /** * Get the entity subtype ID being edited * @@ -105,6 +114,9 @@ public function getEntitySubTypeId($subTypeId) { * If the custom data is in the submitted data (eg. added via ajax loaded form) add to form. */ public function addCustomDataToForm() { + if ($this->isSuppressCustomData()) { + return TRUE; + } $customisableEntities = CRM_Core_SelectValues::customGroupExtends(); if (isset($customisableEntities[$this->getDefaultEntity()])) { CRM_Custom_Form_CustomData::addToForm($this); diff --git a/templates/CRM/Contribute/Form/CancelSubscription.tpl b/templates/CRM/Contribute/Form/CancelSubscription.tpl index 3d1d3dba58ec..ed8395b652bf 100644 --- a/templates/CRM/Contribute/Form/CancelSubscription.tpl +++ b/templates/CRM/Contribute/Form/CancelSubscription.tpl @@ -42,17 +42,5 @@ {/if} -{if !$self_service} -
{$form.send_cancel_request.label} | -{$form.send_cancel_request.html} | -
{$form.is_notify.label} | -{$form.is_notify.html} | -