You are here

function quickbar_form in Quickbar 7

Same name and namespace in other branches
  1. 6 quickbar.admin.inc \quickbar_form()
  2. 7.2 quickbar.admin.inc \quickbar_form()

Page to administer quickbar

Sets which role uses which menu for it's quickbar.

Return value

A form setting quicbar menus per role.

1 string reference to 'quickbar_form'
quickbar_menu in ./quickbar.module
Implements hook_menu().

File

./quickbar.admin.inc, line 18
Handles quickbar administration

Code

function quickbar_form() {
  $form['intro'] = array(
    '#markup' => '<p>' . t('Choose which menu should be used for each role. If a user has multiple roles they will get the menu of the higher role which has an assigned menu.') . '</p>',
  );
  $available_menus = menu_get_menus();
  $roles = user_roles();
  if (variable_get('quickbar_use_machine_names', 0)) {
    $roles = _quickbar_role_machine_names($roles);
  }
  $role_weights = variable_get('quickbar_role_weights', array());
  $stored_menus = variable_get('quickbar_role_menus', array());
  foreach ($roles as $rid => $name) {
    if (empty($role_weights[$rid])) {
      $role_weights[$rid] = 0;
    }
  }

  // Add 'None' so that the admin can choose for no menu to be assigned to a role.
  array_unshift($available_menus, 'None');
  foreach ($role_weights as $rid => $weight) {
    $form['toolbar:' . $rid] = array(
      '#weight' => $weight,
      'title' => array(
        '#markup' => $roles[$rid],
      ),
      'weight' => array(
        '#type' => 'weight',
        '#default_value' => $weight,
      ),
      'menu' => array(
        '#type' => 'select',
        '#default_value' => isset($stored_menus[$rid]) ? $stored_menus[$rid] : '',
        '#options' => $available_menus,
      ),
      // This is just to key off of in the theme function, so we don't render
      // elements that are not meant to be part of the table. There might be
      // a better way to handle this ??
      'rid' => array(
        '#type' => 'hidden',
        '#value' => $rid,
      ),
      'operations' => array(
        'configure' => array(
          '#type' => 'link',
          '#title' => t('configure'),
          '#href' => 'admin/config/user-interface/quickbar/' . $rid . '/edit',
        ),
      ),
    );
  }
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => 'Advanced Settings',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['advanced']['machine_names'] = array(
    '#title' => 'Use machine names instead of roll ids',
    '#description' => "If enabled, quickbar will store it's settings as machine names instead of roll ids.  Since machine names don't exist in drupal quickbar takes some guesses. This means that their is a remote chance that roles could possibley collide if they are named almost the same. For example 'User Role' and 'user-role' will share the same machine name.",
    '#type' => 'checkbox',
    '#default_value' => variable_get('quickbar_use_machine_names', 0),
  );
  $form['#tree'] = TRUE;
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  return $form;
}