From 0f7f32cb05f542842cd092d9fc61b466f8d13024 Mon Sep 17 00:00:00 2001 From: Bradley Taylor Date: Fri, 8 Dec 2023 18:07:00 +0000 Subject: [PATCH] [REF][PHP8.2] Add PHP8.2 support to CRM_Contact_Page_View_Summary --- CRM/Contact/Page/View/Summary.php | 41 ++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/CRM/Contact/Page/View/Summary.php b/CRM/Contact/Page/View/Summary.php index f138745723..8b9c7f08bc 100644 --- a/CRM/Contact/Page/View/Summary.php +++ b/CRM/Contact/Page/View/Summary.php @@ -20,6 +20,42 @@ */ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { + /** + * Contents of contact_view_options setting. + * + * @var array + * @internal + */ + public $_viewOptions; + + /** + * Provide support for extensions that are using the _show{Block} properties + * (e.g. `_showCustomData`, `_showAddress`, `_showPhone` etc) + * + * These properties were dynamically defined, + * based on the available `contact_edit_options`, + * and so have been deprecated for PHP 8.2 support. + * + * Extension authors can read contact_edit_options directly. + * The show{Block} values are also still assigned to the template layer. + * + * @param string $name + * @return bool|null + */ + public function __get($name) { + if (str_starts_with($name, '_show')) { + $blockName = substr($name, strlen('_show')); + $editOptions = CRM_Core_BAO_Setting::valueOptions( + CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, + 'contact_edit_options' + ); + + CRM_Core_Error::deprecatedWarning('_show{Block} properties are deprecated in CRM_Contact_Page_View_Summary. Read contact_edit_options directly instead.'); + return $editOptions[$blockName] ?? FALSE; + } + return NULL; + } + /** * Heart of the viewing process. * @@ -216,9 +252,8 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { ); foreach ($editOptions as $blockName => $value) { - $varName = '_show' . $blockName; - $this->$varName = $value; - $this->assign(substr($varName, 1), $this->$varName); + $varName = 'show' . $blockName; + $this->assign($varName, $value); } // get contact name of shared contact names -- 2.25.1