You are here

function template_preprocess_oa_user_badge in Open Atrium Toolbar 7.2

Preprocess function for the oa_user_badge block.

File

./oa_toolbar.module, line 570
Provides hook implementations and functionality for oa_toolbar.

Code

function template_preprocess_oa_user_badge(&$vars) {
  global $user;
  $vars['oa_toolbar_btn_class'] = variable_get('oa_toolbar_style', 0) ? '' : 'btn-inverse';
  if ($user->uid) {
    $user = user_load($user->uid);
    if (module_exists('oa_users')) {
      $vars = array_merge($vars, oa_users_build_user_details($user));
      $links = array();

      // Build list of user tasks for the current user
      $user_pages = explode("\n", variable_get('oa_user_config_pages', ''));
      foreach ($user_pages as $path) {
        if (strpos(trim($path), 'user/*/') === 0) {
          $new_path = str_replace('user/*/', 'user/' . $user->uid . '/', trim($path));
          if (drupal_valid_path($new_path)) {
            $router = menu_get_item(trim($new_path));
            $link = array(
              'title' => $router['title'],
              'href' => $new_path,
            );
            $links[] = $link;
          }
        }
      }
      $vars['other_links'] = theme('links', array(
        'links' => $links,
        'attributes' => array(
          'class' => array(
            'oa-user-links',
          ),
        ),
      ));

      // Turn the links from oa_users_build_user_details() into a proper render
      // array so that it can be modified.
      $paths = $vars['links'];
      $vars['links'] = array(
        '#theme' => 'links',
        '#links' => array(
          'dashboard' => array(
            'title' => t('Dashboard'),
            'href' => $paths['dashboard'],
            'weight' => -10,
          ),
          'edit_profile' => array(
            'title' => t('Edit profile'),
            'href' => $paths['edit_profile'],
            'weight' => -9,
          ),
          'logout' => array(
            'title' => t('Log out'),
            'href' => $paths['logout'],
            'weight' => 50,
          ),
        ),
      );
    }
  }
  else {
    $vars['login'] = url('user/login');
  }
}