You are here

onepageprofile.module in One page profile 5.2

Same filename and directory in other branches
  1. 6 onepageprofile.module
  2. 7 onepageprofile.module

File

onepageprofile.module
View source
<?php

/**
 * Implementation of hook_user()
 *
 * Here we rebuild the user's account edit form by adding all
 * the other categories. As we are bypassing the security
 * at the menu layer, we need to make sure user has permission
 * to do all these things.
 */
function onepageprofile_user($op, &$edit, &$user, $category = NULL) {
  switch ($op) {
    case 'form':
      if ($category == 'account') {
        $categories = profile_categories();
        $form = array();
        foreach ($categories as $category) {
          if (_onepageprofile_check_access($user, $category)) {
            $form += profile_form_profile($edit, $user, $category['name'], FALSE);
          }
        }
        return $form;
      }
      break;
    case 'update':
      if (isset($edit['form_build_id'])) {
        $categories = profile_categories();
        foreach ($categories as $category) {
          profile_save_profile($edit, $user, $category['name']);
        }
      }
      break;
  }
}

/**
 * Implementation of hook_menu_alter()
 *
 * Here we remove the sub-navigation on the account edit page
 */
function onepageprofile_menu_alter(&$items) {
  $categories = profile_categories();
  foreach ($categories as $key => $category) {
    unset($items['user/%user_category/edit/' . $category['name']]);
  }
}

/**
 * Check if access is allowed to this category by the user
 *
 * We need to do this, instead of profile_category_access(),
 * because we want integration with the profile_roles module.
 */
function _onepageprofile_check_access($account, $category) {
  $map = array(
    'user',
    $account,
    'edit',
    $category['name'],
  );

  // Check access by pretending our category is a menu item
  $category['access_callback'] = $category['access callback'];
  $category['access_arguments'] = serialize($category['access arguments']);
  _menu_check_access($category, $map);

  // Integrate with the profile_role module
  $menu['access'] = true;
  if (function_exists('profile_role_access_category')) {
    $menu['access'] = profile_role_access_category($account, $category['name']);
  }
  return $menu['access'] && $category['access'];
}

Functions

Namesort descending Description
onepageprofile_menu_alter Implementation of hook_menu_alter()
onepageprofile_user Implementation of hook_user()
_onepageprofile_check_access Check if access is allowed to this category by the user