You are here

function fb_user_form_alter in Drupal for Facebook 5.2

Same name and namespace in other branches
  1. 5 fb_user.module \fb_user_form_alter()
  2. 6.3 fb_user.module \fb_user_form_alter()
  3. 6.2 fb_user.module \fb_user_form_alter()
  4. 7.3 fb_user.module \fb_user_form_alter()

File

./fb_user.module, line 298
This module allows Drupal user records to be associated with Facebook user ids. It can create local user accounts when Facebook users visit an application's canvas pages.

Code

function fb_user_form_alter($form_id, &$form) {

  //drupal_set_message("fb_user_form_alter($form_id) " . dpr($form, 1));

  // Add our settings to the fb_app edit form.
  if (is_array($form['fb_app_data'])) {
    $node = $form['#node'];
    $fb_app_data = fb_app_get_data($node->fb_app);
    $fb_user_data = $fb_app_data['fb_user'];
    $form['fb_app_data']['fb_user'] = array(
      '#type' => 'fieldset',
      '#title' => t('Facebook user settings'),
      '#tree' => TRUE,
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['fb_app_data']['fb_user']['require_login'] = array(
      '#type' => 'radios',
      '#title' => t('Require Login'),
      '#description' => t('If some of your canvas pages are visible to the public at large, allow anyone.  You will have to call Facebook\'s require_login() on pages that require more information about the user.<br />Allow only logged-in users if you want Drupal for Facebook to call require_login() on every page.'),
      '#options' => array(
        FB_USER_OPTION_ALLOW_ANON => t('Allow anyone'),
        FB_USER_OPTION_REQUIRE_LOGIN => t('Allow logged-in users'),
      ),
      '#default_value' => isset($fb_user_data['require_login']) ? $fb_user_data['require_login'] : FB_USER_OPTION_ALLOW_ANON,
      '#required' => TRUE,
    );
    $form['fb_app_data']['fb_user']['create_account'] = array(
      '#type' => 'radios',
      '#title' => t('Create Local Account'),
      '#description' => t('This option will create a local account automatically and create an entry in the authmap table.  This happens whenever the user visits a canvas page, except pages whose path starts with "user/" and the landing page for anonymous users.  Choose never to use Drupal\'s built in user registration.'),
      '#options' => array(
        FB_USER_OPTION_CREATE_NEVER => t('Never (user/register page will still work)'),
        FB_USER_OPTION_CREATE_LOGIN => t('If user has logged in'),
      ),
      '#default_value' => isset($fb_user_data['create_account']) ? $fb_user_data['create_account'] : FB_USER_OPTION_CREATE_LOGIN,
      '#required' => TRUE,
    );
    $form['fb_app_data']['fb_user']['map_account'] = array(
      '#type' => 'radios',
      '#title' => t('Map Accounts'),
      '#description' => t('Mapping an account means creating an entry in the authmap table.  This entry allows Drupal to know which Facebook id corresponds to which local uid.'),
      '#options' => array(
        FB_USER_OPTION_MAP_NEVER => t('Never map accounts'),
        FB_USER_OPTION_MAP_ALWAYS => t('Map account when both local uid and Facebook id are known'),
      ),
      '#default_value' => isset($fb_user_data['map_account']) ? $fb_user_data['map_account'] : FB_USER_OPTION_MAP_ALWAYS,
      '#required' => TRUE,
    );
    $form['fb_app_data']['fb_user']['unique_account'] = array(
      '#type' => 'checkbox',
      '#title' => t('Make Account Mapping Unique (experimental, not recommended)'),
      '#description' => t('If checked, the relationship between the local uid and the Facebook id applies only to this Application.  This matters only when you host more than one application on this instance of Drupal.'),
      '#default_value' => $fb_user_data['unique_account'],
    );

    // TODO: prompt for role with a select.  Don't make user figure out id
    $form['fb_app_data']['fb_user']['new_user_rid'] = array(
      '#type' => 'select',
      '#title' => t('New user role'),
      '#options' => user_roles(1),
      '#description' => t('When the local uid is known and the user has logged in (in the Facebook sense) to the app, the user will be granted this role.'),
      '#default_value' => $fb_user_data['new_user_rid'],
    );

    // Experimental.  May be removed or drastically changed anytime
    // TODO: fix this so that it prompts for username with autocomplete, not a uid.
    $form['fb_app_data']['fb_user']['not_logged_in_uid'] = array(
      '#type' => 'textfield',
      '#title' => t('Not logged in user (uid)'),
      '#description' => t('If allowing non-logged in users, when such a user visits the site, which Drupal user should they be treated as?  Use 0 for the anonymous user (recommended - this feature is experimental and likely to disappear).'),
      '#default_value' => $fb_user_data['not_logged_in_uid'],
    );
    $form['fb_app_data']['fb_user']['logged_in_uid'] = array(
      '#type' => 'textfield',
      '#title' => t('Logged in user (uid)'),
      '#description' => t('If allowing logged in users, when such a user visits the site, and they do not have a local Drupal account, which Drupal user should they be treated as?  Use 0 for the Anonymous user (recommended - this feature is experimental and likely to disappear), or create a dedicated account for this purpose.'),
      '#default_value' => $fb_user_data['logged_in_uid'],
    );
  }
  else {
    if ($form_id == 'user_edit' && ($app = $form['#fb_app'])) {

      // Disable buttons on user/edit/app pages, nothing to submit
      unset($form['submit']);
      unset($form['delete']);
    }
  }
}