You are here

function theme_fb_login_button in Drupal for Facebook 7.3

Same name and namespace in other branches
  1. 6.3 fb.theme.inc \theme_fb_login_button()
  2. 7.4 fb.theme.inc \theme_fb_login_button()

Theme a Facebook Connect button.

Uses a link with onclick="FB.login()", because this works much better than fb:login-button on Firefox when third-party cookies disabled.

5 theme calls to theme_fb_login_button()
fb_devel_info in ./fb_devel.module
fb_invite_invite_form in contrib/fb_invite.module
fb_permission_access_perms in contrib/fb_permission.module
fb_user_form_alter in ./fb_user.module
Implements hook_form_alter().
fb_user_form_user_profile_form_alter in ./fb_user.module
Implements hook_form_user_profile_form_alter.

File

./fb.theme.inc, line 44

Code

function theme_fb_login_button($params) {
  $text = isset($params['text']) ? $params['text'] : '';
  $options = isset($params['options']) ? $params['options'] : array();

  // Merge in defaults
  $options += array(
    'attributes' => array(),
    'connected_markup' => NULL,
  );
  $options['attributes'] += array(
    'class' => 'fb_login_button_wrapper fb_button_style',
  );
  if ($text === NULL) {
    $text = t('Connect');
  }

  // For compatibility, pass in scope as an attribute.
  if (!isset($options['attributes']['scope'])) {

    // Which permissions to prompt for?
    $perms = array();
    drupal_alter('fb_required_perms', $perms);
    $options['attributes']['scope'] = implode(',', $perms);
  }
  $scope = $options['attributes']['scope'];
  unset($options['attributes']['scope']);

  // New markup does not need this attr.
  if ($text) {
    $markup = '<div ' . drupal_attributes($options['attributes']) . '><a href="#" onclick="FB.login(function(){}, {scope : \'' . $scope . '\'}); return false;"><div><span>' . $text . '</span></div></a></div>';
  }
  else {

    // No text, use default image.
    $markup = '<div class="fb_login_button_wrapper"><a href="#" onclick="FB.login(function(){}, {scope : \'' . $scope . '\'}); return false;"><span><img src="//www.facebook.com/images/fbconnect/login-buttons/connect_light_medium_short.gif" alt="fb connect" /></span></a></div>';
  }
  if ($options['connected_markup']) {
    $markup = '<div class="fb_not_connected">' . $markup . '</div>' . '<div class="fb_connected">' . $options['connected_markup'] . '</div>';
  }
  return $markup;
}