Skip to content

Instantly share code, notes, and snippets.

@mdeltito
Created December 17, 2013 21:10
Show Gist options
  • Save mdeltito/8012687 to your computer and use it in GitHub Desktop.
Save mdeltito/8012687 to your computer and use it in GitHub Desktop.
adding profile2 entity form fields to a node form
<?php
/**
* implements hook_form_FORM_ID_alter
*/
function report_form_node_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'report_node_form') {
// the node author's uid is always available here
$account = user_load($form['#node']->uid);
if (empty($form_state['profiles']['personal'])) {
$profile = profile2_load_by_user($account, 'personal');
if ($profile) {
$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