You are here

function fasttoggle_sitewide_toggleable_roles in Fasttoggle 7

Same name and namespace in other branches
  1. 6 fasttoggle.inc \fasttoggle_sitewide_toggleable_roles()

Get a list of roles for the sitewide settings form.

Return value

array List of roles.

3 calls to fasttoggle_sitewide_toggleable_roles()
fasttoggle_user_permission in module/fasttoggle_user/fasttoggle_user.module
Implements hook_perm().
fasttoggle_user_role_access in module/fasttoggle_user/fasttoggle_user.module
Check access to toggle a particular role.
fasttoggle_user_toggleable_roles in module/fasttoggle_user/fasttoggle_user.inc
The list of roles a user can toggle.

File

module/fasttoggle_user/fasttoggle_user.inc, line 31
Fasttoggle user hook implementations.

Code

function fasttoggle_sitewide_toggleable_roles() {
  static $roles;
  if (!isset($roles)) {
    $potential_roles = fasttoggle_potential_toggleable_roles();
    $defaults = array();
    foreach ($potential_roles as $rid => $role_name) {
      $defaults["role_{$rid}"] = "role_{$rid}";
    }
    $values = variable_get('fasttoggle_user_role_settings', $defaults);
    $allowed_roles = array_filter(variable_get('fasttoggle_user_role_settings', $defaults));

    // Trim the group ("role_") off the front of each key.
    $new_array = array();
    foreach ($allowed_roles as $role) {
      $new_array[substr(array_pop($allowed_roles), 5)] = $role;
    }
    $roles = $new_array ? array_intersect_key(fasttoggle_potential_toggleable_roles(), $new_array) : array();
  }
  return $roles;
}