You are here

function content_profile_registration_form_alter in Content Profile 6

Implementation of hook_form_alter().

File

modules/content_profile_registration.module, line 11
Allows exposure and processing of content_profile node fields at user registration

Code

function content_profile_registration_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_register') {
    require_once drupal_get_path('module', 'node') . '/node.pages.inc';

    // Allow other modules to customize the used profile types, so modules
    // can easily customize the registration form.
    $default_types = content_profile_get_types('names', arg(0) == 'admin' ? 'admin_user_create_use' : 'registration_use');
    $form += array(
      '#content_profile_registration_use_types' => $default_types,
    );
    foreach ($form['#content_profile_registration_use_types'] as $type => $typename) {
      content_profile_registration_add_profile_form($type, $form, $form_state);
    }
  }
  elseif ($form_id == 'content_profile_admin_settings') {
    $type = $form_state['type'];

    // Let other modules add registration child elements before us!
    $form += array(
      'registration' => array(),
    );
    $form['registration'] += array(
      '#type' => 'fieldset',
      '#title' => t('User Registration'),
      '#description' => t('Customize how this content profile shows up on the user registration page.'),
      '#collapsible' => TRUE,
    );
    $form['registration']['registration_use'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use on Registration'),
      '#description' => t('Use this content type on the user registration page'),
      '#default_value' => content_profile_get_settings($type, 'registration_use'),
    );
    $form['registration']['admin_user_create_use'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use on administrative user creation form'),
      '#description' => t('Use this content type when an administrative user creates a new user'),
      '#default_value' => content_profile_get_settings($type, 'admin_user_create_use'),
    );
    $form['registration']['registration_hide'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Hide form fields'),
      '#description' => t('Hide fields from the user registration form. Required fields cannot be hidden and are not shown here.'),
      '#options' => _content_profile_registration_get_field_select($type),
      '#default_value' => content_profile_get_settings($type, 'registration_hide'),
    );
    array_unshift($form['#submit'], 'content_profile_registration_admin_form_submit');
  }
}