Skip to content

Instantly share code, notes, and snippets.

@gregmercer
Created December 6, 2012 18:46
Show Gist options
  • Save gregmercer/4226996 to your computer and use it in GitHub Desktop.
Save gregmercer/4226996 to your computer and use it in GitHub Desktop.
Get list of permissions in Drupal
$permissions = test_invoke_all('permission');
foreach ($permissions as $key => $value) {
$title = $value["title"];
$description = "";
$module = $value["module"];
if (isset($value["description"])) {
$description = $value["description"];
}
echo "$module&$key&$title&$description \n";
}
function test_invoke_all($hook) {
$args = func_get_args();
// Remove $hook from the arguments.
unset($args[0]);
$return = array();
foreach (module_implements($hook) as $module) {
$function = $module . '_' . $hook;
if (function_exists($function)) {
$result = call_user_func_array($function, $args);
if (isset($result) && is_array($result)) {
$temp = array();
foreach($result as $key => $value) {
$value["module"] = $module;
$temp[$key] = $value;
}
$return = array_merge_recursive($return, $temp);
}
elseif (isset($result)) {
$result["module"] = $module;
$return[] = $result;
}
}
}
return $return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment