You are here

function entity_print_update_7001 in Entity Print 7

Introduce per entity type and per bundle permissions.

File

./entity_print.install, line 11
Entity print install file.

Code

function entity_print_update_7001() {

  // Get roles.
  $roles = user_roles();
  $loaded_roles = array();

  // Load roles by name to get the rid and the role name.
  foreach ($roles as $role) {
    $loaded_roles[] = user_role_load_by_name($role);
  }

  // Prepare permission array.
  $rid_permissions = array();
  foreach ($loaded_roles as $loaded_role) {
    $rid_permissions[] = array(
      'rid' => $loaded_role->rid,
      'permissions' => user_role_permissions(array(
        $loaded_role->rid => $loaded_role->name,
      )),
    );
  }

  // Set / unset permissions.
  foreach ($rid_permissions as $rid_permission) {
    $permissions = reset($rid_permission['permissions']);
    if (array_key_exists('entity print access', $permissions)) {
      user_role_change_permissions($rid_permission['rid'], array(
        'entity print access' => FALSE,
        'bypass entity print access' => TRUE,
      ));
    }
  }
}