Problem/Motivation
Currently the relationship between a membership_type and a Drupal role is tracked by role ID in the redhen_membership_type.role_id field. When used in Features, a membership type is mapped to a given role by role ID, which may differ from the role on the site on which the membership type was generated.
The problem has been fixed by the introduction of role machine names for Drupal 8, but meantime there is no consistent model to follow here in Drupal 7. While the problem is widely noted, each module maintainer has taken a different approach. See #2 for various examples.
Proposed resolution
At a minimum, document the issue and point to potential solutions, including:
Remaining tasks
User interface changes
none
API changes
Comments
Comment #1
levelos commentedThanks for opening the discussion @nedjo. Can you point to other projects that are following this approach? I also noticed that http://drupal.org/project/role_export might do a good job of solving this problem. Not that it helps us at the moment, but this roles have already been given a machine name in D8.
Comment #2
nedjoThere is no consistent model to follow here in Drupal 7. While the problem is widely noted, each module maintainer has taken a different approach.
Is Role export the answer? It's tempting--a fix that can fix up any other module's problems. But at a cost. My view on Role export is that It's a clever hack and useful e.g. when Features is being used as a tool for dev > staging > live deployment on a single site. But it's not a sufficient solution, particularly for use with features that are being used in distributions or apps. Problems:
If broken role export were a minor concern, perhaps it could be safely ignored--but that's far from being the case. Typically, roles are used to handle access control. Any breakage can leave a site wide open to security breaches.
So my feeling is that D7 modules should solve role export issues--in a way that prepares for D8 contrib, where it will be possible to build on core role machine names.
Comment #3
levelos commented@nedjo, thanks so much for presenting this information and explaining the options!
I do think we'll more or less stick with our current model for the time being and link memberships directly to role id's rather than change to role names. I'd be open to role_export, or at least the approach it takes, in that it adds a machine name column to the role schema and then relates that to role machine names in other places. But your're right that any 3rd party module would need to be aware of that approach / dependency for it to be successful within an ecosystem. But it will work on individual projects where all components are aware of the dependency.
Without that, I worry about what would happen if a role name changes and we lose our connection between the related role. I realize we have hook_user_role_update(), but I'm not sure that will be sufficient in all cases.
Certainly open to more thoughts and further discussion.
Comment #4
nedjoOn second thought, yeah, there's not a lot of sense in switching now to key on role name and then having to switch back for D8.
Maybe this is a documentation task. A possible approach would be, if you're trying to make a portable feature or app, manually edit the exported code to:
hook_default_redhen_membership_type_alter():Comment #5
levelos commentedThat's a great solution. I wasn't familiar with that hook, but looks really handy. If you want to add something along those lines to the README, I'll be happy to credit the commit ;)
Comment #6
nedjoFor API documentation on the hook, which is available for all entity types made exportable with Entity API, see http://drupal.org/node/999942.
Draft README patch attached.
Comment #7
nedjoComment #8
levelos commented@nedjo, you are truly me hero. Seriously, that's very awesome of you to take the time to submit a documentation patch!
Comment #9
nedjoAdapted this issue to a features handbook page, exportables and user role IDs in features.
Comment #11
arancedisicilia commentedI had this problem recently, and exporting was a headache everytime.
However, since I need to export very often in my current project, so that #4 doesn't seem to be handy (I should edit manually the code for each export, if I'm not mistaken), I came up with some "maybe dirty" but very simple workaround, that is:
- define a custom access rule in my module. It looks like this:
- in my view, define a PHP based access rule, that would be as much as this line:
return MYMODULE_access();and that should be all. It works in my case, and I don't see any drawbacks (please tell me more about it if you think I'm wrong!)
Hope this may help someone.
Comment #11.0
arancedisicilia commentedUpdated issue summary.