You are here

function profile2_page_menu in Profile 2 7.2

Same name and namespace in other branches
  1. 7 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' => 'profile2_page_access',
        'access arguments' => array(
          'view',
          $type_name,
        ),
        'file' => 'profile2_page.inc',
        'type' => MENU_NORMAL_ITEM,
        'menu_name' => 'user-menu',
        'weight' => $type->weight,
      );

      // 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,
        '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_CALLBACK,
        'file' => 'profile2_page.inc',
      );

      // Menu items for revisions in page mode.
      if (module_exists('profile2_diff')) {
        $page_callback = 'profile2_diff_diffs_overview';
        $module = 'profile2_diff';
        $file = 'profile2_diff.pages.inc';
      }
      else {
        $page_callback = 'profile2_revision_overview';
        $module = NULL;
        $file = NULL;
      }
      $items[$path . '/%profile2_by_uid/revisions'] = array(
        'title' => 'Revisions',
        'page callback' => $page_callback,
        'page arguments' => array(
          $count,
        ),
        'load arguments' => array(
          $type_name,
        ),
        'access callback' => '_profile2_revision_access',
        'access arguments' => array(
          $count,
          array(
            'view own profile revisions',
            'view any profile revisions',
          ),
        ),
        'type' => MENU_LOCAL_TASK,
        'module' => $module,
        'file' => $file,
      );

      // This provides a hidden parent for the view operation (as well as diff),
      // enabling breadcrumbs to work but without creating sub-tabs.
      $items[$path . '/%profile2_by_uid/revisions/ops'] = array(
        'type' => MENU_DEFAULT_LOCAL_TASK,
      );
      $items[$path . '/%profile2_by_uid/revisions/ops/view'] = array(
        'title' => 'View revision',
        'page callback' => 'profile2_profile_revision_view',
        'page arguments' => array(
          $count,
          $count + 4,
        ),
        'access callback' => '_profile2_revision_access',
        'access arguments' => array(
          $count,
          array(
            'view own profile revisions',
            'view any profile revisions',
          ),
        ),
        'type' => MENU_LOCAL_TASK,
      );
      $items[$path . '/%profile2_by_uid/revisions/ops/%/revert'] = array(
        'title' => 'Revert to earlier revision',
        'load arguments' => array(
          $type_name,
        ),
        'page callback' => 'drupal_get_form',
        'page arguments' => array(
          'profile2_revision_revert_confirm',
          $count,
        ),
        'access callback' => '_profile2_revision_access',
        'access arguments' => array(
          $count,
          array(
            'revert own profile revisions',
            'revert any profile revisions',
          ),
        ),
        'type' => MENU_CALLBACK,
      );
      $items[$path . '/%profile2_by_uid/revisions/ops/%/delete'] = array(
        'title' => 'Delete earlier revision',
        'load arguments' => array(
          $type_name,
        ),
        'page callback' => 'drupal_get_form',
        'page arguments' => array(
          'profile2_revision_delete_confirm',
          $count,
        ),
        'access callback' => '_profile2_revision_access',
        'access arguments' => array(
          1,
          array(
            'delete own profile revisions',
            'delete any profile revisions',
          ),
        ),
        'type' => MENU_CALLBACK,
      );

      // 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;
}