+++ /opt/lampp/htdocs/mediacurrent/alaskadispatch_com/sites/all/modules/better_formats/better_formats.module	(working copy)
@@ -455,7 +455,11 @@
 
     $types  = $type;
     $format = array();
-    $roles  = implode(',', array_keys($user->roles));
+
+    foreach ($user->roles as $key => $name)
+      $roles [] = db_result(db_query('SELECT rid FROM {role} WHERE name = "%s"', $name));
+
+    $roles  = implode(',', $roles);
 
     // Prepare types for SQL.
     if ($mode !== 'block' && $per_node_type && $node_type) {

This is kind of a quick example, I'm sure you could come up with something better, but I have an OP site and the keys to the $user->roles aren't always the numeric rid, sometimes its the role name which causes a db error. I think we need something more reliable.

Comments

dragonwize’s picture

Status: Active » Closed (works as designed)

If your keys are not role IDs then something is wrong with your site. user_load is where the roles are loaded into the user object: http://api.drupal.org/api/drupal/modules--user--user.module/function/use...

drupalninja99’s picture

Array
(
    [2] => authenticated user
    [4] => author
    [author] => author
)

It's weird that it's giving me that in the $user->roles, I am using open publish 2.3.

jdonson’s picture

Why are roles not listed in order of rid @ admin/user/roles?

This makes me want to hack core, and I shant, but please give me some solutions. thx!

jdonson’s picture

same for

admin/user/permissions

dragonwize’s picture

@jdonson

Please do not hijack an issue for something unrelated.

Those are core pages and are ordered alphabetically. As with everything else, if you do not like it, Drupal provides methods to change whatever you want.