function fb_connect_form_alter in Drupal for Facebook 6.2
Same name and namespace in other branches
- 5.2 fb_connect.module \fb_connect_form_alter()
- 6.3 fb_connect.module \fb_connect_form_alter()
- 7.3 fb_connect.module \fb_connect_form_alter()
File
- ./
fb_connect.module, line 636 - Support for Facebook Connect features
Code
function fb_connect_form_alter(&$form, &$form_state, $form_id) {
// Add our settings to the fb_app edit form.
if (isset($form['fb_app_data'])) {
$fb_app = $form['#fb_app'];
$fb_app_data = fb_get_app_data($fb_app);
$fb_connect_data = $fb_app_data['fb_connect'];
$form['fb_app_data']['fb_connect'] = array(
'#type' => 'fieldset',
'#title' => 'Facebook Connect',
'#tree' => TRUE,
'#collapsible' => TRUE,
'#collapsed' => $node->label ? TRUE : FALSE,
);
// "Primary" will be initialized on every non-canvas page.
$primary_label = variable_get(FB_CONNECT_VAR_PRIMARY, NULL);
$form['fb_app_data']['fb_connect']['primary'] = array(
'#type' => 'checkbox',
'#title' => t('Primary'),
'#description' => t('Initialize fbConnect javascript on all (non-canvas) pages. If this site supports multiple Facebook Apps, this may be checked for at most one.'),
'#default_value' => isset($fb_app->label) && $primary_label == $fb_app->label,
);
if ($primary_label && $primary_label != $fb_app->label) {
$form['fb_app_data']['fb_connect']['primary']['#description'] .= '<br/>' . t('Note that checking this will replace %app as the primary Facebook Connect app.', array(
'%app' => $primary_label,
));
}
$form['#submit'][] = 'fb_connect_app_submit';
}
// Add button to login form.
if (($form_id == 'user_login_block' || $form_id == 'user_login') && !fb_is_fbml_canvas()) {
if ($app_label = variable_get(FB_CONNECT_VAR_LOGIN, NULL)) {
$fb_app = fb_get_app(array(
'label' => $app_label,
));
// Render connect link if not connected already.
if ($fb = fb_connect_app_init($fb_app) && !fb_facebook_user($fb)) {
// Ensure that facebook javascript is in the page closure.
fb_connect_require_feature('XFBML', $fb_app);
fb_connect_init_option('ifUserConnected', "{FB_Connect.on_connected}", $fb_app);
fb_connect_init_option('ifUserNotConnected', "{FB_Connect.on_not_connected}", $fb_app);
// Add button to the form.
// @TODO - make markup customizable.
$form['fb_connect_button'] = array(
'#type' => 'markup',
'#value' => '<fb:login-button v="2"><fb:intl>Connect with Facebook</fb:intl></fb:login-button>',
'#prefix' => '<div class="form-item" id="fb-connect-button">',
'#suffix' => '</div>',
'#weight' => 4,
);
}
}
if ($form_id == 'user_login') {
// On login, we must leave the user/login page or else get access denied.
drupal_add_js(array(
'fb_connect' => array(
'destination' => url('user'),
),
), 'setting');
}
}
}