You are here

function og_ui_user_admin_roles in Organic groups 7

Menu callback: administer roles.

See also

og_user_admin_roles_validate()

og_user_admin_roles_submit()

theme_group_user_admin_new_role()

2 string references to 'og_ui_user_admin_roles'
og_ui_forms in og_ui/og_ui.module
Implement hook_forms().
og_ui_menu in og_ui/og_ui.module
Implements hook_menu().

File

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

Code

function og_ui_user_admin_roles($form, $form_state, $entity_type = '', $etid = 0, $rid = 0) {
  $gid = 0;
  if ($entity_type && ($group = og_get_group($entity_type, $etid))) {
    $gid = $group->gid;
  }
  $form['gid'] = array(
    '#type' => 'value',
    '#value' => $gid,
  );
  if ($rid) {
    if ($gid) {
      og_set_breadcrumb($entity_type, $etid, array(
        l(t('Group'), "{$entity_type}/{$etid}/group"),
      ), l(t('Roles'), "group/{$entity_type}/{$etid}/admin/people/roles"));
    }
    $group_roles = og_roles($gid);
    if (!in_array($rid, array_keys($group_roles))) {
      drupal_goto($gid ? "group/{$entity_type}, {$etid}/admin/people/roles" : 'admin/config/group/roles');
    }

    // Display the edit role form.
    $role = og_role_load($rid);
    $form['name'] = array(
      '#type' => 'textfield',
      '#title' => t('Role name'),
      '#default_value' => $role->name,
      '#size' => 30,
      '#required' => TRUE,
      '#maxlength' => 64,
      '#description' => t('The name for this role. Example: "moderator", "editorial board", "site architect".'),
    );
    $form['rid'] = array(
      '#type' => 'value',
      '#value' => $rid,
    );
    $form['actions'] = array(
      '#type' => 'actions',
    );
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save role'),
    );
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete role'),
    );
  }
  else {

    // No role ID.
    if ($gid) {
      og_set_breadcrumb($entity_type, $etid, array(
        l(t('Group'), "{$entity_type}/{$etid}/group"),
      ));
    }
    if (!$gid || !og_is_group_default_access($group->gid)) {
      $form['name'] = array(
        '#type' => 'textfield',
        '#title' => t('Name'),
        '#title_display' => 'invisible',
        '#size' => 32,
        '#maxlength' => 64,
        '#required' => TRUE,
      );
      $form['add'] = array(
        '#type' => 'submit',
        '#value' => t('Add role'),
        '#validate' => array(
          'og_ui_user_admin_roles_validate',
        ),
        '#submit' => array(
          'og_ui_user_admin_roles_submit',
        ),
      );

      // Attach the CSS to the form.
      $form['#attached'] = array(
        'css' => array(
          'type' => 'file',
          'data' => drupal_get_path('module', 'og_ui') . '/css/og_ui.css',
        ),
      );
    }
  }
  return $form;
}