From 091f056298ed53389ad1202234952ac1cf484db7 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 8 Nov 2021 11:55:14 +1300 Subject: [PATCH] Extract getGroupOrganizationUrl & ensure always assigned --- CRM/Contact/Page/View.php | 33 +++++++++++---------- templates/CRM/Contact/Page/View/Summary.tpl | 2 +- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/CRM/Contact/Page/View.php b/CRM/Contact/Page/View.php index ce076fe83c..bd7d327bc2 100644 --- a/CRM/Contact/Page/View.php +++ b/CRM/Contact/Page/View.php @@ -157,7 +157,7 @@ class CRM_Contact_Page_View extends CRM_Core_Page { // check logged in user permission self::checkUserPermission($this); - list($displayName, $contactImage, $contactType, $contactSubtype, $contactImageUrl) = self::getContactDetails($this->_contactId); + [$displayName, $contactImage, $contactType, $contactSubtype, $contactImageUrl] = self::getContactDetails($this->_contactId); $this->assign('displayName', $displayName); $this->set('contactType', $contactType); @@ -208,19 +208,7 @@ class CRM_Contact_Page_View extends CRM_Core_Page { // Add links for actions menu self::addUrls($this, $this->_contactId); - - if ($contactType == 'Organization' && - CRM_Core_Permission::check('administer Multiple Organizations') && - Civi::settings()->get('is_enabled')) { - //check is any relationship between the organization and groups - $groupOrg = CRM_Contact_BAO_GroupOrganization::hasGroupAssociated($this->_contactId); - if ($groupOrg) { - $groupOrganizationUrl = CRM_Utils_System::url('civicrm/group', - "reset=1&oid={$this->_contactId}" - ); - $this->assign('groupOrganizationUrl', $groupOrganizationUrl); - } - } + $this->assign('groupOrganizationUrl', $this->getGroupOrganizationUrl($contactType)); } /** @@ -292,7 +280,7 @@ class CRM_Contact_Page_View extends CRM_Core_Page { static $contactDetails; $contactImage = NULL; if (!isset($contactDetails[$contactId])) { - list($displayName, $contactImage) = self::getContactDetails($contactId); + [$displayName, $contactImage] = self::getContactDetails($contactId); $contactDetails[$contactId] = [ 'displayName' => $displayName, 'contactImage' => $contactImage, @@ -371,4 +359,19 @@ class CRM_Contact_Page_View extends CRM_Core_Page { } } + /** + * @param string $contactType + * + * @return string + */ + protected function getGroupOrganizationUrl(string $contactType): string { + if ($contactType !== 'Organization' || !CRM_Core_Permission::check('administer Multiple Organizations') + || !CRM_Contact_BAO_GroupOrganization::hasGroupAssociated($this->_contactId) + || !Civi::settings()->get('is_enabled') + ) { + return ''; + } + return CRM_Utils_System::url('civicrm/group', "reset=1&oid={$this->_contactId}"); + } + } diff --git a/templates/CRM/Contact/Page/View/Summary.tpl b/templates/CRM/Contact/Page/View/Summary.tpl index 992ef9e2db..2b265879cb 100644 --- a/templates/CRM/Contact/Page/View/Summary.tpl +++ b/templates/CRM/Contact/Page/View/Summary.tpl @@ -93,7 +93,7 @@ {/if} {/if} - {if !empty($groupOrganizationUrl)} + {if $groupOrganizationUrl}
  • {crmButton href=$groupOrganizationUrl class="associated-groups" icon="cubes"} {ts}Associated Multi-Org Group{/ts} -- 2.25.1