You are here

function fboauth_field_form_alter in Facebook OAuth (FBOAuth) 7

Same name and namespace in other branches
  1. 7.2 includes/fboauth.field.inc \fboauth_field_form_alter()

Add options for Field module to the Facebook OAuth settings form.

1 call to fboauth_field_form_alter()
fboauth_settings_form in includes/fboauth.pages.inc
Menu callback; Display the settings form for Facebook OAuth.

File

includes/fboauth.field.inc, line 11
Facebook to Field module mapping.

Code

function fboauth_field_form_alter(&$form, &$form_state) {
  $form['fboauth_user_fields'] = array(
    '#type' => 'fieldset',
    '#title' => t('User field mapping'),
    '#description' => t('Each of your <a href="!url">fields that are attached to users</a> are listed below. Map each one you would like to import into your site to a Facebook data source.', array(
      '!url' => url('admin/config/people/accounts/fields'),
    )),
    '#tree' => TRUE,
    '#weight' => 5,
  );

  // Each field type can only map to certain type Facebook properties. Build a
  // list for each type that includes reasonable options.
  $properties = fboauth_user_properties(TRUE);
  $property_options = array();
  foreach ($properties as $property => $property_info) {
    if (isset($property_info['field_types'])) {
      foreach ($property_info['field_types'] as $field_type) {
        $property_options[$field_type][$property] = '[' . $property . '] ' . $property_info['label'];
      }
    }
  }
  $field_defaults = variable_get('fboauth_user_fields', array());
  $instances = field_info_instances('user', 'user');
  foreach ($instances as $field_name => $instance) {
    $field = field_info_field($instance['field_name']);
    if (isset($property_options[$field['type']])) {
      $options = array_merge(array(
        '' => t('- Do not import -'),
      ), $property_options[$field['type']]);
      $form['fboauth_user_fields'][$field_name] = array(
        '#title' => t(check_plain($instance['label'])),
        '#type' => 'select',
        '#options' => $options,
        '#default_value' => isset($field_defaults[$field_name]) ? $field_defaults[$field_name] : '',
      );
    }
    else {
      $form['fboauth_user_fields'][$field_name] = array(
        '#title' => t(check_plain($instance['label'])),
        '#type' => 'form_element',
        '#children' => '<em>' . t('No mappable Facebook properties.') . '</em>',
        '#theme_wrappers' => array(
          'form_element',
        ),
      );
    }
  }
}