You are here

function og_ui_admin_roles_validate in Organic groups 7.2

Validate handler; OG roles.

1 string reference to 'og_ui_admin_roles_validate'
og_ui_admin_roles in og_ui/og_ui.admin.inc
Menu callback: administer roles.

File

og_ui/og_ui.admin.inc, line 560
Admin settings for Organic groups module.

Code

function og_ui_admin_roles_validate($form, &$form_state) {
  if (!empty($form_state['values']['name'])) {
    $group_type = $form['group_type']['#value'];
    $bundle = $form['bundle']['#value'];
    $gid = $form['gid']['#value'];
    $roles = og_roles($group_type, $bundle, $gid);
    $unique_name = TRUE;
    if (!empty($form_state['values']['rid'])) {
      $role = og_role_load($form_state['values']['rid']);
      $unique_name = $role->name != $form_state['values']['name'];
    }
    if ($unique_name && in_array($form_state['values']['name'], $roles)) {
      form_set_error('name', t('The role name %name already exists. Please choose another role name.', array(
        '%name' => $form_state['values']['name'],
      )));
    }
  }
  else {
    form_set_error('name', t('You must specify a valid role name.'));
  }
}