A quick fix is adding the following to the machine name field in role_export_form_alter():

'#required' => !empty($form_state['values']['name']),

No extensively tested though. (I've had an issue where the rids of the anonymous and authenticated user roles changed; not sure if it was related to above mentioned fix.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Steven Brown’s picture

Priority: Normal » Critical

When re-arranging the order of the roles the default roles (anonymous, authenticated) are now assigned a new role id. I will look into the offending code base.

klausi’s picture

Status: Active » Needs review
FileSize
1.72 KB

Here is a patch that adds an exception for the anonymous and authenticated user roles to not alter them. Also fixes the role ordering form.

Please test!

Steven Brown’s picture

Status: Needs review » Active

This works for anonymous and authenticated just fine. However, the administrator role still gets a new id and we can't just simply add an OR id == 3 because administrator isn't always there. So should we do the following?

<?php
if ($role->rid == 1 || $role->rid == 2 || ($role->rid == 3 && $role->name == 'administrator')) {
  return;
}
?>
klausi’s picture

But I want my administrator role to get a role_export id! The problem is that the re-ordering triggers a role update. Maybe we can add a check to the update hook: if only the weight has changed do not generate the new id.

klausi’s picture

The problem is that we have no way to detect what was changed on the role. We could implement a custom submit callback and store the old role state in a global variable, but that would be more than ugly and could have other strange side effects.

Or we could just disallow role ordering while not all roles have a generated id.

klausi’s picture

Status: Active » Needs review
FileSize
3.25 KB

New patch: Displays a warning on the roles page if there are old roles without machine name present. Also fixes a bug for saving roles without machine names.

Steven Brown’s picture

The patch in #6 has a call to an undefined function 'role_export_role_add_form_validate' I am assuming this was just a mishap and needed to be changed to the validation function that was added for the roles form. This has been changed to 'role_export_roles_form_validate' in the provided patch. I've test and it works for me.

klausi’s picture

Ah, good catch (I experimented with other validation callbacks and obviously forgot to change it back).

You have '#required' twice in your patch, I removed the first one.

Otherwise works for me.

drakythe’s picture

Status: Needs review » Reviewed & tested by the community

Seems to work just fine.

Steven Brown’s picture

Status: Reviewed & tested by the community » Fixed

Patch from #8 has been tested and committed. http://drupalcode.org/project/role_export.git/commit/d7bff20

Status: Fixed » Closed (fixed)

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