/[drupal]/contributions/modules/onepageprofile/onepageprofile.module
ViewVC logotype

Diff of /contributions/modules/onepageprofile/onepageprofile.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.7, Sun Sep 27 08:56:05 2009 UTC revision 1.8, Sat Nov 7 21:47:25 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: onepageprofile.module,v 1.6 2009/09/27 07:43:07 aidan Exp $  // $Id: onepageprofile.module,v 1.7 2009/09/27 08:56:05 aidan Exp $
3    
4  /**  /**
5   * Implementation of hook_user()   * 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.  
6   */   */
7  function onepageprofile_user($op, &$edit, &$user, $category = NULL) {  function onepageprofile_user($op, &$edit, &$user, $category = NULL) {
8    switch($op) {    switch ($op) {
9      case 'form':      case 'form':
10        if ($category == 'account') {        if ($category == 'account') {
11          $categories = profile_categories();          $categories = profile_categories();
12          $form = array();          $form = array();
13          foreach ($categories as $category) {          foreach ($categories as $category) {
14            if (_onepageprofile_check_access($user, $category)) {            $profile_form = profile_form_profile($edit, $user, $category['name'], FALSE);
15              $form += profile_form_profile($edit, $user, $category['name'], FALSE);            if (!empty($profile_form)) {
16                $form += $profile_form;
17            }            }
18          }          }
   
19          return $form;          return $form;
20        }        }
21        break;        break;
22    
23      case 'update':      case 'update':
24        if (isset($edit['form_build_id'])) {        if (arg(0) == 'user' && arg(2) == 'edit') {
25          $categories = profile_categories();          $categories = profile_categories();
26          foreach ($categories as $category) {          foreach ($categories as $category) {
27            profile_save_profile($edit, $user, $category['name']);            profile_save_profile($edit, $user, $category['name']);
28          }          }
29        }        }
30        break;        break;
31    }    }
32  }  }
33    
   
 /**  
  * 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'];  
 }  

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.2