It would be great if we could use the Social Login icons as a Block and be able to put it anywhere we like.

I've made an attempt to expose the Social Login icons as a Block, but I did not succeed yet.
People that have code suggestions for that:
have a look at http://drupal.org/sandbox/s1l/1315560
you can easily add it to the function rpx_extras_socialloginicons_contents() and you're set.
(might save some time testing).
Once it's tested I suggest we commit it to the Janrain Engage module.

btw, using these as a block this is probably not the best solution for putting the icons on the registration page
#1207816: Include sign-in icons on the registration page
or for attaching it to the comments, but it would depend on your usecase I guess.

CommentFileSizeAuthor
social-login-icons-block.jpg22.63 KBsilkogelman

Comments

Sk1Zy’s picture

I want to second this, would really like this feature as well.

Mihai Chiriac’s picture

Ad these lines to the end of rpx_widgets.module file.

It practically takes the code from _rpx_user_login_form_alter() and embed it into a block named "RPX Block Icons".

/**
 * Implements hook_block_info().
 *
 * This hook declares what blocks are provided by the module.
 */
function rpx_widgets_block_info() {

  $blocks['rpx_block_icons'] = array(
    'info' => t('RPX Block Icons'),
    'status' => TRUE,
    'region' => 'sidebar_first',  // Not usually provided.
  );

  return $blocks;
}


/**
 * Implements hook_block_view().
 *
 * This hook generates the contents of the blocks themselves.
 */
function rpx_widgets_block_view($delta = '') {
  //The $delta parameter tells us which block is being requested.
    $block = array();
  switch ($delta) {
    case 'rpx_block_icons':
      $block['subject'] = t('RPX Block Icons');
      $block['content'] = _rpx_widgets_create_block();
      break;
  }
  return $block;
}



function _rpx_widgets_create_block () {
  rpx_js();
  $items = array();
  $realm = variable_get('rpx_realm', '');
  $realm_scheme = variable_get('rpx_realm_scheme', 'http');
  $sign_in_url = "$realm_scheme://$realm/openid/v2/signin";
  $token_url = _rpx_token_url();
  $providers = _rpx_providers();

  // These options are common for all providers.
  $options_template = array(
    'query' => array('token_url' => $token_url),
    'html' => TRUE,
    'attributes' => array(
      'class' => 'rpxnow',
      'onclick' => 'return false;',
      'onmousedown' => 'delete RPXNOW.default_provider;',
    ),
  );

  $icons = '';
  foreach ($providers as $provider_name => $provider_title) {
    $options = $options_template;
    // If it's the first Engage sign-in for the user, this will take them
    // directly to the provider's dialog.
    // @see https://rpxnow.com/docs#sign-in_default_provider
    $options['attributes']['onmousedown'] = "RPXNOW.default_provider = '" . $provider_name . "';";
    $icons .= l(theme('rpx_icon', array('provider' => $provider_name, 'size' => variable_get('rpx_login_icons_size', 'small'))), $sign_in_url, $options);
  }
  $items[] = array(
    'data' => l((variable_get('rpx_signin_string', RPX_SIGNIN_STRING) == '') ? RPX_SIGNIN_STRING : variable_get('rpx_signin_string', RPX_SIGNIN_STRING), $sign_in_url, $options_template) . '<br />' . $icons,
    'class' => array ('rpx-link'),
  );

  $form['rpx_links'] = array(
    '#theme' => 'item_list',
    '#items' => $items,
    '#attributes' => array('class' => array('rpx-links')),
    '#weight' => variable_get('rpx_login_links_weight', 150),
  );

  return $form;    
}
elBradford’s picture

This works for me, but the icons are so TINY. As a workaround I'm using a block with custom PHP that just uses the Engage widgets from their website (script with div). This module really needs some work in terms of block building / ui flexibility. Something like a function that accepts a few arguments and returns some basic html that developers can style with CSS would be just fine with me. Drop that in a block with PHP input style and customize it any way you want.

bulat’s picture

It will be really cool if login_form_alter was turned into a separate block as it was done in the code example by Necropsique.
login_form_alter should be done by developers outside the module.

Code above seems to work fine for us.

Max_Headroom’s picture

I don't know where the above code comes from because I can't find it or the original function ( _rpx_user_login_form_alter() ) in module.
Maybe this was D6?

Anyway, all you need is this code to be put in a custom block or render with the block callback

<?php
rpx_js();
?>
<div class="foo" id ="janrainEngageEmbed"></div>

Just a note, you can only have one "janrainEngageEmbed" ID per page, otherwise nothing shows. So, if you have normal login as well, make sure you disable Jainrain for it in settings.

saltednut’s picture

@Necropsique - I would suggest posting a patch so its easier for the maintainer to commit your code and people will be able to test it out.