CRM-16230 - Permissions: handle extensions with and without descriptions
authorAndrew Hunt <andrew@aghstrategies.com>
Fri, 3 Apr 2015 21:37:10 +0000 (17:37 -0400)
committerAndrew Hunt <andrew@aghstrategies.com>
Fri, 3 Apr 2015 21:50:36 +0000 (17:50 -0400)
----------------------------------------
* CRM-16230: Extensions providing permissions will choke
  https://issues.civicrm.org/jira/browse/CRM-16230

CRM/Core/Permission.php
CRM/Core/Permission/Base.php

index b56d805b3d83e5b664602332ecf37f178d70ec99..9fb1bd155174fb01d2d8dc8c08ea51b9ee491717 100644 (file)
@@ -616,7 +616,7 @@ class CRM_Core_Permission {
     }
 
     // Add any permissions defined in hook_civicrm_permission implementations.
-    $module_permissions = $config->userPermissionClass->getAllModulePermissions();
+    $module_permissions = $config->userPermissionClass->getAllModulePermissions($descriptions);
     $permissions = array_merge($permissions, $module_permissions);
     return $permissions;
   }
index 3b47e271b8b6e7a33cfc37b56c03ea67bf306366..e3e9f4d5201a4a547ac20a2f2559e96da40e1c92 100644 (file)
@@ -256,9 +256,20 @@ class CRM_Core_Permission_Base {
    * @return array
    *   Array of permissions, in the same format as CRM_Core_Permission::getCorePermissions().
    */
-  public function getAllModulePermissions() {
+  public function getAllModulePermissions($descriptions = FALSE) {
     $permissions = array();
     CRM_Utils_Hook::permission($permissions);
+
+    if ($descriptions) {
+      foreach ($permissions as $permission => $label) {
+        $permissions[$permission] = (is_array($label)) ? $label : array($label);
+      }
+    }
+    else {
+      foreach ($permissions as $permission => $label) {
+        $permissions[$permission] = (is_array($label)) ? array_shift($label) : $label;
+      }
+    }
     return $permissions;
   }