Skip to content

Instantly share code, notes, and snippets.

@nguyenthanhxuan
Forked from bdecarne/MY_MODULE.module
Created March 16, 2014 10:30
Show Gist options
  • Save nguyenthanhxuan/9581297 to your computer and use it in GitHub Desktop.
Save nguyenthanhxuan/9581297 to your computer and use it in GitHub Desktop.
<?php
/**
* Implements hook_menu_alter().
*/
function MY_MODULE_menu_alter(&$items) {
$items['user/%user_category/edit/profile']['access callback'] = FALSE;
}
/**
* Implements hook_form_FORM_ID_alter() for the user edit form.
* Merge the profile2 form with the user account form itself :
*/
function MY_MODULE_form_user_profile_form_alter(&$form, &$form_state) {
if (($type = profile2_get_types('profile')) && $type->userCategory) {
if (empty($form_state['profiles'])) {
$profile = profile2_load_by_user($form['#user'], 'profile');
if (empty($profile)) {
$profile = profile_create(array('type' => 'profile', 'uid' => $form['#user']->uid));
}
$form_state['profiles'][$profile->type] = $profile;
}
profile2_attach_form($form, $form_state);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment