You are here

function lti_tool_provider_global_roles in LTI Tool Provider 7

Admin form for the global roles.

Parameters

array $form: The form.

array $form_state: The form state.

1 string reference to 'lti_tool_provider_global_roles'
lti_tool_provider_menu in ./lti_tool_provider.module
Implements hook_menu().

File

./lti_tool_provider.admin.inc, line 123
Admin forms for LTI Tool Provider module.

Code

function lti_tool_provider_global_roles($form, &$form_state) {
  $form['description'] = array(
    '#type' => 'item',
    '#title' => t('Map LTI Roles to Global Drupal Roles'),
    '#description' => t('Map each LTI role to a global Drupal role.'),
  );
  $select_roles = user_roles(TRUE, NULL);
  $old_role_array = variable_get('lti_tool_provider_global_role_array');
  $form['roles'] = array(
    '#tree' => TRUE,
    '#theme' => 'table',
    '#header' => array(
      t('LTI Roles'),
      t('Global Roles'),
    ),
    '#rows' => array(),
  );
  foreach (lti_tool_provider_get_lti_roles() as $role) {
    $lti_role = array(
      '#type' => 'item',
      '#title' => $role,
    );
    $global_role = array(
      '#type' => 'select',
      '#options' => $select_roles,
    );
    if (isset($old_role_array[$role]) && isset($select_roles[$old_role_array[$role]])) {
      $global_role['#default_value'] = $old_role_array[$role];
    }
    else {
      $global_role['#default_value'] = array_search(DRUPAL_AUTHENTICATED_RID, $select_roles);
    }
    $form['roles'][] = array(
      'lti_role' => &$lti_role,
      'global_role' => &$global_role,
    );
    $form['roles']['#rows'][] = array(
      array(
        'data' => &$lti_role,
      ),
      array(
        'data' => &$global_role,
      ),
    );
    unset($lti_role);
    unset($global_role);
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save Global Roles'),
    '#submit' => array(
      'lti_tool_provider_global_roles_submit',
    ),
  );
  return $form;
}