Merge pull request #23258 from civicrm/5.49
[civicrm-core.git] / CRM / Core / Permission / Backdrop.php
index 8226c45a168fb9ad881647038289cf2c6f2f466e..6fc230a4a324aceeb495bd57b433d1c842b48f5c 100644 (file)
@@ -68,7 +68,7 @@ class CRM_Core_Permission_Backdrop extends CRM_Core_Permission_DrupalBase {
     }
     if (function_exists('user_access')) {
       $account = NULL;
-      if ($userId) {
+      if ($userId || $userId === 0) {
         $account = user_load($userId);
       }
       return user_access($str, $account);
@@ -98,6 +98,31 @@ class CRM_Core_Permission_Backdrop extends CRM_Core_Permission_DrupalBase {
     return FALSE;
   }
 
+  /**
+   * @inheritDoc
+   */
+  public function getAvailablePermissions() {
+    // We want to list *only* Backdrop perms, so we'll *skip* Civi perms.
+    $allCorePerms = \CRM_Core_Permission::basicPermissions(TRUE);
+
+    $permissions = [];
+    $modules = system_get_info('module');
+    foreach ($modules as $moduleName => $module) {
+      $prefix = isset($module['name']) ? ($module['name'] . ': ') : '';
+      foreach (module_invoke($moduleName, 'permission') ?? [] as $permName => $perm) {
+        if (isset($allCorePerms[$permName])) {
+          continue;
+        }
+
+        $permissions["Drupal:$permName"] = [
+          'title' => $prefix . strip_tags($perm['title']),
+          'description' => $perm['description'] ?? NULL,
+        ];
+      }
+    }
+    return $permissions;
+  }
+
   /**
    * @inheritDoc
    */