Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#5 | autoassignrole-1314668-5.patch | 1.09 KB | mike.davis |
#3 | autoassignrole-1314668-3.patch | 1.18 KB | mike.davis |
Comments
Comment #1
thomasgm CreditAttribution: thomasgm commentedI'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
Comment #2
HFlame7 CreditAttribution: HFlame7 commentedThomas' solution worked, thanks! Hopefully this can get implemented as a feature.
Comment #3
mike.davis CreditAttribution: mike.davis commentedThis 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.
Comment #5
mike.davis CreditAttribution: mike.davis commentedRerolled patch.
Comment #6
mike.davis CreditAttribution: mike.davis commentedPatch applied