You are here

function profile2_regpath_menu in Profile2 Registration Path 7.2

Same name and namespace in other branches
  1. 7 profile2_regpath.module \profile2_regpath_menu()

Implements hook_menu().

File

./profile2_regpath.module, line 14
Attach profile2 form to registration form according to path.

Code

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

  // @todo Load profiles GROUP BY path ORDER BY weight ASC.
  $reg_paths = profile2_regpath_get_reg_paths();
  if ($reg_paths) {

    // Set menu items for each registration path.
    foreach ($reg_paths as $key => $value) {
      $path = $value->path;

      // We need to load multiple profile types here, because more than one
      // profile can be assigned to a given regpath. Profile type with lightest
      // weight is given precedence when choosing labels.
      if ($profile_types = profile2_regpath_get_profiles($path)) {

        // Add profile-specific administrative 'add user' page.
        $items['admin/people/p2rp-create/' . $path] = array(
          'title' => 'Add user (' . $profile_types[0]->label . ' profile)',
          'page callback' => '_profile2_regpath_user_register',
          'page arguments' => array(
            'profiles' => $profile_types,
          ),
          'access arguments' => array(
            'administer users',
          ),
          'type' => MENU_LOCAL_ACTION,
          'file' => 'profile2_regpath.inc',
        );

        // We will use hook_menu_alter() to deal with the 'user' path later.
        if ($path != 'user') {
          $misc = unserialize($profile_types[0]->misc);

          // Just set default values for this in the install file? I don't like checking.
          if (isset($misc['path_type']) ? $path_type = $misc['path_type'] : ($path_type = 'separate')) {
          }
          if ($path_type != 'tabs') {
            $registration_path = $path . '/register';
          }
          else {
            $registration_path = 'user/' . $path . '/register';
          }
          $items[$registration_path] = array(
            'title' => isset($misc['tab_text']) && trim($misc['tab_text']) != '' ? $misc['tab_text'] : t('Register as @profile_type', array(
              '@profile_type' => $profile_types[0]->label,
            )),
            'page callback' => '_profile2_regpath_user_register',
            'page arguments' => array(
              'profiles' => $profile_types,
            ),
            'access callback' => 'user_register_access',
            'file' => 'profile2_regpath.inc',
            'type' => MENU_LOCAL_TASK,
          );
          if ($path_type != 'tabs') {
            $items[$path] = array(
              'title' => 'Log in',
              'page callback' => '_profile2_regpath_user_login',
              'page arguments' => array(
                'profiles' => $profile_types,
              ),
              'access callback' => 'user_is_anonymous',
              'file' => 'profile2_regpath.inc',
              'menu_name' => 'user-menu',
              'type' => MENU_CALLBACK,
            );
            $items[$path . '/login'] = array(
              'title' => 'Log in',
              'page callback' => '_profile2_regpath_user_login',
              'page arguments' => array(
                'profiles' => $profile_types,
              ),
              'access callback' => 'user_is_anonymous',
              'file' => 'profile2_regpath.inc',
              'type' => MENU_DEFAULT_LOCAL_TASK,
            );
            $items[$path . '/password'] = array(
              'title' => 'Request new password',
              'type' => MENU_LOCAL_TASK,
              'page callback' => '_profile2_regpath_user_password',
              'page arguments' => array(
                'profiles' => $profile_types,
              ),
              'access callback' => 'user_is_anonymous',
              'file' => 'profile2_regpath.inc',
            );
          }
        }
      }
    }
  }
  return $items;
}