function role_export_form_alter in Role Export 7
Same name and namespace in other branches
- 6 role_export.module \role_export_form_alter()
Implements hook_form_alter().
File
- ./
role_export.module, line 15 - Role Export's primary module file.
Code
function role_export_form_alter(&$form, &$form_state, $form_id) {
switch ($form_id) {
case 'user_admin_roles':
// Add the machine name to the role objects in the form.
$roles = role_export_roles();
$warning = TRUE;
foreach ($form['roles'] as $key => &$element) {
if (is_numeric($key)) {
$element['#role'] = $roles[$key];
// Show a warning if there are old roles without machine name. Ignore
// the anonymous and authenticated user roles. Display the warning
// only once and only on the form itself, not after it has been
// submitted.
if (empty($roles[$key]->machine_name) && empty($form_state['input']) && $warning && $key > 2) {
drupal_set_message(t('Warning: Reordering the roles will create the missing machine names and change the role ids which could break existing configurations.'), 'warning');
$warning = FALSE;
}
}
}
$form['#theme'] = array(
'role_export_user_admin_roles',
);
$form['#attached']['css'] = array(
drupal_get_path('module', 'role_export') . '/role_export.css',
);
$form['name']['#description'] = t('The human-readable name of this role.<br />This text will be displayed as part of the list on the <em>Roles</em> page.');
$form['machine_name'] = array(
'#type' => 'machine_name',
'#maxlength' => 255,
'#title_display' => 'invisible',
'#machine_name' => array(
'exists' => 'role_export_role_name_exists',
),
// The machine name is not required here to avoid form errors when
// re-ordering the roles.
'#required' => FALSE,
);
$form['add']['#validate'][] = 'role_export_roles_form_validate';
form_load_include($form_state, 'inc', 'role_export', 'role_export.admin');
break;
case 'user_admin_role':
$roles = role_export_roles();
$machine_name = $roles[$form['rid']['#value']]->machine_name;
// Only show the warning on the form itself, not after it has been
// submitted.
if (empty($machine_name) && empty($form_state['input'])) {
drupal_set_message(t('Warning: Saving this role will create a machine name and change the role id which could break existing configurations.'), 'warning');
}
$form['machine_name'] = array(
'#type' => 'machine_name',
'#maxlength' => 255,
'#default_value' => $machine_name,
'#description' => t('Warning: changing the machine name will also change the role id which could break existing configurations.'),
'#machine_name' => array(
'exists' => 'role_export_role_name_exists',
),
);
break;
}
}