You are here

function pcp_form_profile2_type_form_alter in Profile Complete Percent 7

Implements hook_form_FORM_ID_alter(). Form builder; Configure PCP fields for profile2 profile types.

File

./pcp.module, line 432
Allows users with valid permissions to tag profile fields (core fields or Profile2 fields) for a users profile to be considered complete.

Code

function pcp_form_profile2_type_form_alter(&$form, &$form_state, $form_id) {
  form_load_include($form_state, 'inc', 'pcp', 'includes/pcp.admin');
  $bundle = $form['type']['#default_value'];
  $form['profile_complete'] = array(
    '#type' => 'fieldset',
    '#title' => 'Profile Complete Settings',
  );
  $form['profile_complete']['hide_block_on_complete'] = array(
    '#type' => 'checkbox',
    '#title' => 'Hide Block When Complete',
    '#default_value' => variable_get('pcp_profile2_' . $bundle . '_hide_block_on_complete', 0),
    '#description' => t('When a user reaches 100% complete of their profile, do you want the profile complete percent block to go away? If so, check this box on.'),
  );
  $options = array();
  $settings = pcp_admin_settings_form_data('profile2', $bundle);
  foreach ($settings['profile_fields_options'] as $fiid => $field_name) {
    $field_info = field_info_instance('profile2', $field_name, $bundle);
    $options[$fiid] = $field_info['label'];
  }
  $profile_fields_description = empty($options) ? t('There are no fields enabled for this profile type. Please !link', array(
    '!link' => l(t('add some profile fields'), 'admin/structure/profiles/manage/' . $bundle . '/fields'),
  )) : t('Checking a profile field below will add that field to the logic of the complete percentage.');
  $form['profile_complete']['profile_fields'] = array(
    '#title' => t('Profile Fields'),
    '#description' => filter_xss($profile_fields_description),
    '#type' => 'checkboxes',
    '#options' => $options,
    '#default_value' => array_flip($settings['default_values']),
  );
  $form['#submit'][] = 'pcp_admin_settings_submit';
  return $form;
}