PHP code example of kewljuice / calibr8_civicrm

1. Go to this page and download the library: Download kewljuice/calibr8_civicrm library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kewljuice / calibr8_civicrm example snippets


 // Export CiviCRM permissions as JSON.
 
 // Fetch roles.
 $permissions = \Drupal::service('user.permissions')->getPermissions();
 $permissions_by_provider = [];
 foreach ($permissions as $key => $permission) {
   $permissions_by_provider[$permission['provider']][] = $key;
 }

 // Loop all roles from System.
 $roles = \Drupal\user\Entity\Role::loadMultiple();
 $permissions_by_role = [];
 foreach ($roles as $role) {
   $perms = $role->getPermissions();
   foreach ($perms as $perm) {
     if (in_array($perm, $permissions_by_provider['civicrm'])) {
       $permissions_by_role[$role->id()][] = $perm;
     }
   }
 }
 
 // Export.
 $permissions_by_role = json_encode($permissions_by_role);
 dpm($permissions_by_role);