| 1 |
========================================
|
| 2 |
Role Weights - role_weights
|
| 3 |
Paul Byrne <paul@leafish.co.uk>
|
| 4 |
Last updated 31/03/2009
|
| 5 |
========================================
|
| 6 |
|
| 7 |
A small utility module to allow site admins to specify certain weights for user roles. Its
|
| 8 |
not much use on its own, more of a helper module for other modules which require this
|
| 9 |
functionality. Role Weights also provides Tokens and some Views support: views are able
|
| 10 |
to access, display or sort by the node author's role weight.
|
| 11 |
|
| 12 |
Role Weights project on drupal.org: http://drupal.org/project/role_weights
|
| 13 |
|
| 14 |
Please post issues and suggestions to the issue tracker: http://drupal.org/project/issues/role_weights
|
| 15 |
|
| 16 |
|
| 17 |
Installation
|
| 18 |
========================================
|
| 19 |
1. Upload the role_weights directory to your modules directory.
|
| 20 |
2. Enable the module under Administer -> Site building -> Modules.
|
| 21 |
3. Visit Administer -> User management -> Roles and choose the 'edit' link next to a role to change a role's weight.
|
| 22 |
|
| 23 |
|
| 24 |
Usage (with Views)
|
| 25 |
========================================
|
| 26 |
Simply create a view - you can now sort by node author's role weight under 'Sort Criteria'.
|
| 27 |
|
| 28 |
|
| 29 |
Usage (without Views)
|
| 30 |
========================================
|
| 31 |
Once installed and role weights have been set, modules and themes can make use of:
|
| 32 |
|
| 33 |
function role_weights_get_weight($role_id)
|
| 34 |
- gets the weight value for a specified role
|
| 35 |
|
| 36 |
function role_weights_get_weighted_max($roles, $weight_end)
|
| 37 |
- takes an array of role_id => role_name and returns the 'lightest' (ie closest to -infinity)
|
| 38 |
role id when $weight_end parameter is 'lightest' or the 'heaviest' (ie closest to +infinity)
|
| 39 |
role id when $weight_end is 'heaviest'
|
| 40 |
|
| 41 |
|
| 42 |
DEPRECATED in 5.x-1.3, all 6.x branches and above:
|
| 43 |
|
| 44 |
function role_weights_get_highest($roles)
|
| 45 |
- takes an array of role_id => role_name and returns the 'highest' role id
|
| 46 |
|
| 47 |
This function has been replaced by role_weights_get_weighted_max($roles, 'lightest') and
|
| 48 |
only remains as a wrapper for backwards compatibility. If your module/code relies on Role
|
| 49 |
Weights, please update accordingly. This function is deprecated and may be removed in
|
| 50 |
future versions.
|
| 51 |
|
| 52 |
|
| 53 |
Advanced settings
|
| 54 |
========================================
|
| 55 |
|
| 56 |
Once installed, site admins can enable sorting roles by weight on the Roles configuration
|
| 57 |
(/admin/user/roles) and Access Control (/admin/user/pages/access) pages by visiting the
|
| 58 |
Role Weights settings page: /admin/settings/role_weights
|
| 59 |
|
| 60 |
Caveat: currently this setting will override Drupal's default sorting (alphabetical). So,
|
| 61 |
if this variable is set and a roles all have equal weight then the sorting will be less
|
| 62 |
than satisfactory.
|
| 63 |
|
| 64 |
There is an issue for this here: http://drupal.org/node/368088
|
| 65 |
|
| 66 |
|
| 67 |
Notes
|
| 68 |
========================================
|
| 69 |
CAUTION! Do NOT allow lower-level roles to edit role weights if another module is relying
|
| 70 |
on it to control any higher-level stuff like access permissions, site settings and development
|
| 71 |
modules. I wouldn't really advise this in the first place - this module is intended for simple
|
| 72 |
selection of roles based on weights for use in, for example, theming usernames & profiles or
|
| 73 |
choosing the 'highest' from multiple roles.
|