Drupal 7 allows the roles to be ordered however you please.
I was thinking that when allowing a user to choose from a list of roles, rather than just having asc/desc alphabetical, it would be handy to have the choice to order by this predefined weight.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

thomasgm’s picture

I've made this change on the autoassignrole.module
// Sort the roles
if (variable_get('autoassignrole_user_sort', 'SORT_ASC') == 'SORT_ASC') {
asort($roles);
} else if (variable_get('autoassignrole_user_sort', 'SORT_DESC') == 'SORT_DESC') {
arsort($roles);
} else {
drupal_sort_weight($roles, $roles);
}

I've added one more IF and the ELSE

then got to autoassignrole.admin.inc and changed variable
$form['autoassignrole_user_sort'] = array(
'#type' => 'radios',
'#title' => t('Sorting'),
'#default_value' => variable_get('autoassignrole_user_sort', 'SORT_ASC'),
'#description' => t('Default sort order of roles the user will see.'),
'#options' => array(
'SORT_ASC' => t('Ascending'),
'SORT_DESC' => t('Descending'),
'SORT_WEIGHT' => t('Weight of field'),
),
);

This will make the roles being ordered by the weight defined on the Roles admin screen.
Now the question is, how can i do this using hook instead of hack the module?

kind regards

HFlame7’s picture

Issue summary: View changes

Thomas' solution worked, thanks! Hopefully this can get implemented as a feature.

mike.davis’s picture

Status: Active » Needs review
FileSize
1.18 KB

This is a nice little enhancement - I have created a patch file for this change for review.

Please can you make sure that you supply a patch file with changes rather than including code in a thread. The changes can be properly tested and applied correctly.

Status: Needs review » Needs work

The last submitted patch, 3: autoassignrole-1314668-3.patch, failed testing.

mike.davis’s picture

Status: Needs work » Needs review
FileSize
1.09 KB

Rerolled patch.

mike.davis’s picture

Status: Needs review » Fixed

Patch applied

  • mike.davis committed 3037f7c on 7.x-1.x
    Issue #1314668 by thomasgm: Added Sort/order user's role options by...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.