Created
September 6, 2012 08:27
-
-
Save hannesl/3653037 to your computer and use it in GitHub Desktop.
Check user Drupal role id for Features sanity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Implements hook_requirements(). | |
| */ | |
| function mymodule_requirements($phase) { | |
| $requirements = array(); | |
| // Ensure translations don't break at install time | |
| $t = get_t(); | |
| if (defined('MYMODULE_RID')) { | |
| // Test role ID, make sure it equals MYMODULE_RID. | |
| $roles = user_roles(); | |
| $rid = array_search('member', $roles); | |
| $requirements['member_role'] = array( | |
| 'title' => $t('Member role ID'), | |
| 'value' => $rid, | |
| ); | |
| if ($rid != MYMODULE_RID) { | |
| $requirements['member_role']['description'] = $t('The X role has an incorrect ID. It needs to be <code>!rid</code>.', array('!rid' => MYMODULE_RID)); | |
| $requirements['member_role']['severity'] = REQUIREMENT_ERROR; | |
| } | |
| } | |
| return $requirements; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Various exportables use the
ridwhen referring to a user role, but exported roles are defined by their name only. There are no guarantees that theridwill be the same on your dev, staging and production sites. Thishook_requirements()implementation warns admins if theridis incorrect.MYMODULE_RIDneeds to be defined obviously, or you can hard-code it if you feel lazy.