From dfeea5fca197e70279f63dfeb732b0bbaf48d038 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 15 Dec 2023 08:28:33 +1300 Subject: [PATCH] Add standardised for get traits --- CRM/Contribute/Form/ContributeFormTrait.php | 39 ++++++++++++++++ CRM/Member/Form/MembershipFormTrait.php | 51 +++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 CRM/Member/Form/MembershipFormTrait.php diff --git a/CRM/Contribute/Form/ContributeFormTrait.php b/CRM/Contribute/Form/ContributeFormTrait.php index b5f23429e9..46d327ea06 100644 --- a/CRM/Contribute/Form/ContributeFormTrait.php +++ b/CRM/Contribute/Form/ContributeFormTrait.php @@ -88,4 +88,43 @@ trait CRM_Contribute_Form_ContributeFormTrait { return NULL; } + /** + * Get the value for a field relating to the contribution. + * + * All values returned in apiv4 format. Escaping may be required. + * + * @api This function will not change in a minor release and is supported for + * use outside of core. This annotation / external support for properties + * is only given where there is specific test cover. + * + * @param string $fieldName + * + * @return mixed + * @throws \CRM_Core_Exception + */ + public function getContributionRecurValue(string $fieldName) { + if ($this->isDefined('ContributionRecur')) { + return $this->lookup('ContributionRecur', $fieldName); + } + $id = $this->getContributionRecurID(); + if ($id) { + $this->define('ContributionRecur', 'ContributionRecur', ['id' => $id]); + return $this->lookup('ContributionRecur', $fieldName); + } + return NULL; + } + + /** + * Get the selected Contribution ID. + * + * @api This function will not change in a minor release and is supported for + * use outside of core. This annotation / external support for properties + * is only given where there is specific test cover. + * + * @noinspection PhpUnhandledExceptionInspection + */ + public function getContributionRecurID(): ?int { + throw new CRM_Core_Exception('`getContributionID` must be implemented'); + } + } diff --git a/CRM/Member/Form/MembershipFormTrait.php b/CRM/Member/Form/MembershipFormTrait.php new file mode 100644 index 0000000000..1d1b0c3c61 --- /dev/null +++ b/CRM/Member/Form/MembershipFormTrait.php @@ -0,0 +1,51 @@ +isDefined('Membership')) { + return $this->lookup('Membership', $fieldName); + } + $id = $this->getMembershipID(); + if ($id) { + $this->define('Membership', 'Membership', ['id' => $id]); + return $this->lookup('Membership', $fieldName); + } + return NULL; + } + + /** + * Get the selected Membership ID. + * + * @api This function will not change in a minor release and is supported for + * use outside of core. This annotation / external support for properties + * is only given where there is specific test cover. + * + * @noinspection PhpUnhandledExceptionInspection + */ + public function getMembershipID(): ?int { + throw new CRM_Core_Exception('`getMembershipID` must be implemented'); + } + +} -- 2.25.1