From 2673ef11a3d7e42994a72c00ad5caa3d603afb79 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 23 Nov 2023 21:50:22 +1300 Subject: [PATCH] Stop setting unused, undefined property _lineItem This removes the last reference to _lineItem in the Contribution flow. However, magic methods are added to support most extension access to them --- CRM/Contribute/Form/Contribution/Confirm.php | 3 -- CRM/Contribute/Form/ContributionBase.php | 41 +++++++++++++++++++- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 7ae0b06378..0857e180a9 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -263,9 +263,6 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr */ public function preProcess() { parent::preProcess(); - - // lineItem isn't set until Register postProcess - $this->_lineItem = [$this->getPriceSetID() => $this->getLineItems()];; $this->_ccid = $this->get('ccid'); $this->_params = $this->controller->exportValues('Main'); diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index 90e7170a7c..9c925487f1 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -227,6 +227,41 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { return $this->getPriceSetID() && CRM_Price_BAO_PriceSet::isQuickConfig($this->getPriceSetID()); } + /** + * Provide support for extensions that are used to being able to retrieve _lineItem + * + * Note extension should call getPriceSetID() and getLineItems() directly. + * They are supported for external use per the api annotation. + * + * @param string $name + * + * @noinspection PhpUnhandledExceptionInspection + */ + public function __get($name) { + if ($name === '_lineItem') { + // At some point add a deprecation notice here. + return [$this->getPriceSetID() => $this->getLineItems()]; + } + CRM_Core_Error::deprecatedWarning('attempt to access invalid property :' . $name); + } + + /** + * Provide support for extensions that are used to being able to retrieve _lineItem + * + * Note extension should call getPriceSetID() and getLineItems() directly. + * They are supported for external use per the api annotation. + * + * @param string $name + * @param mixed $value + */ + public function __set($name, $value) { + if ($name === '_lineItem') { + $this->order->setLineItems($value[$this->getPriceSetID()]); + return; + } + CRM_Core_Error::deprecatedWarning('attempt to set invalid property :' . $name); + } + /** * Is the form being submitted in test mode. * @@ -247,6 +282,10 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { * * Out of caution we still allow `get`, `set` to take precedence. * + * @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. + * * @return int|null * @throws \CRM_Core_Exception */ @@ -724,7 +763,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { foreach ($vars as $v) { if (isset($this->_params[$v])) { - if ($v == "amount" && $this->_params[$v] === 0) { + if ($v === 'amount' && $this->_params[$v] === 0) { $this->_params[$v] = CRM_Utils_Money::format($this->_params[$v], NULL, NULL, TRUE); } $this->assign($v, $this->_params[$v]); -- 2.25.1