You are here

function profile2_page_menu in Profile 2 7

Same name and namespace in other branches
  1. 7.2 contrib/profile2_page.module \profile2_page_menu()

Implements hook_menu().

File

contrib/profile2_page.module, line 11
Adds separate pages for viewing and editing profiles.

Code

function profile2_page_menu() {
  $items = array();

  // Bugfix for uninstalling the module, see http://drupal.org/node/1008346.
  if (!module_exists('profile2')) {
    return;
  }
  $profile2_view_tab_count = 0;
  foreach (profile2_get_types() as $type_name => $type) {
    if (!empty($type->data['use_page'])) {
      $path = profile2_page_get_base_path($type);
      $count = count(explode('/', $path));

      // This is the menu item for opening the user's own profile page.
      $items[$path] = array(
        'title callback' => 'profile2_page_title',
        'title arguments' => array(
          $type_name,
          TRUE,
        ),
        'page callback' => 'profile2_page_own',
        'page arguments' => array(
          $path,
        ),
        'access callback' => 'user_access',
        'access arguments' => array(
          "view own {$type_name} profile",
        ),
        'file' => 'profile2_page.inc',
        'menu_name' => 'user-menu',
      );

      // This is the router item that opens the page view.
      $items[$path . '/%profile2_by_uid'] = array(
        // Title is added in profile2_page_preprocess_page().
        'page callback' => 'profile2_page_view',
        'page arguments' => array(
          $count,
        ),
        'load arguments' => array(
          $type_name,
        ),
        'access callback' => 'profile2_access',
        'access arguments' => array(
          'view',
          $count,
        ),
        'file' => 'profile2_page.inc',
        'type' => MENU_CALLBACK,
      );
      $items[$path . '/%profile2_by_uid/view'] = array(
        'title' => 'View',
        'type' => MENU_DEFAULT_LOCAL_TASK,
        'load arguments' => array(
          $type_name,
        ),
        'weight' => -10,
      );
      $items[$path . '/%profile2_by_uid/edit'] = array(
        'page callback' => 'entity_ui_get_form',
        'page arguments' => array(
          'profile2',
          $count,
        ),
        'load arguments' => array(
          $type_name,
        ),
        'access callback' => 'profile2_access',
        'access arguments' => array(
          'edit',
          $count,
        ),
        'title' => 'Edit',
        'type' => MENU_LOCAL_TASK,
        'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
        'file' => 'profile2_page.inc',
      );
      $items[$path . '/%profile2_by_uid/delete'] = array(
        'page callback' => 'drupal_get_form',
        'page arguments' => array(
          'profile2_page_delete_confirm_form',
          $count,
        ),
        'load arguments' => array(
          $type_name,
        ),
        'access callback' => 'profile2_access',
        'access arguments' => array(
          'delete',
          $count,
        ),
        'title' => 'Delete',
        'type' => MENU_LOCAL_TASK,
        'context' => MENU_CONTEXT_INLINE,
        'file' => 'profile2_page.inc',
      );

      // Devel integration.
      if (module_exists('devel')) {
        $devel_path = drupal_get_path('module', 'devel');
        $items[$path . '/%profile2_by_uid/devel'] = array(
          'title' => 'Devel',
          'page callback' => 'devel_load_object',
          'file' => 'devel.pages.inc',
          'file path' => $devel_path,
          'page arguments' => array(
            'profile2',
            $count,
          ),
          'access arguments' => array(
            'access devel information',
          ),
          'type' => MENU_LOCAL_TASK,
          'weight' => 100,
        );
        $items[$path . '/%profile2_by_uid/devel/load'] = array(
          'title' => 'Load',
          'type' => MENU_DEFAULT_LOCAL_TASK,
        );
        $items[$path . '/%profile2_by_uid/devel/render'] = array(
          'title' => 'Render',
          'page callback' => 'devel_render_object',
          'page arguments' => array(
            'profile2',
            $count,
          ),
          'access arguments' => array(
            'access devel information',
          ),
          'file' => 'devel.pages.inc',
          'file path' => $devel_path,
          'type' => MENU_LOCAL_TASK,
          'weight' => 100,
        );
      }
    }
    else {
      if (!empty($type->data['use_tab'])) {

        // Make tab(s) under user profile page.
        $items['user/%profile2_by_uid/view/' . $type_name] = array(
          'title callback' => 'profile2_page_title',
          'title arguments' => array(
            $type_name,
          ),
          'page callback' => 'profile2_page_view',
          'page arguments' => array(
            1,
          ),
          'load arguments' => array(
            $type_name,
          ),
          'access callback' => 'profile2_access',
          'access arguments' => array(
            'view',
            1,
          ),
          'type' => MENU_LOCAL_TASK,
          'file' => 'profile2_page.inc',
        );
      }
    }
    $profile2_view_tab_count++;
  }

  // If there exists at least one tab for profile2 type,
  // then we need to create default tab for user account page.
  if ($profile2_view_tab_count) {
    $items['user/%user/view/account'] = array(
      'title' => 'Account',
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'weight' => -10,
    );
  }
  return $items;
}