Extract getGroupOrganizationUrl & ensure always assigned
authorEileen McNaughton <emcnaughton@wikimedia.org>
Sun, 7 Nov 2021 22:55:14 +0000 (11:55 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Sun, 7 Nov 2021 22:55:14 +0000 (11:55 +1300)
CRM/Contact/Page/View.php
templates/CRM/Contact/Page/View/Summary.tpl

index ce076fe83c89d94e7652d5ef7f6d248864db0f67..bd7d327bc20662eecd5bce1f54c2f7bc460322de 100644 (file)
@@ -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}");
+  }
+
 }
index 992ef9e2dbc03289103217e05f94b923ab139fc3..2b265879cb68e2100ddeba3eeef7f03cada2bf14 100644 (file)
@@ -93,7 +93,7 @@
           {/if}
         {/if}
 
-        {if !empty($groupOrganizationUrl)}
+        {if $groupOrganizationUrl}
           <li class="crm-contact-associated-groups">
             {crmButton href=$groupOrganizationUrl class="associated-groups" icon="cubes"}
               {ts}Associated Multi-Org Group{/ts}