On a high-traffic site, we don't want to use Rules, but we still want to have something like #2392093: Add Rules Event Hook for Facebook Connect

A hook_simple_fb_connect_login() would nice for that

Comments

lesonunique created an issue. See original summary.

lesonunique’s picture

Status: Active » Needs review
StatusFileSize
new871 bytes
lesonunique’s picture

StatusFileSize
new2.75 KB

Sorry patch was malformed

lesonunique’s picture

StatusFileSize
new2.95 KB

I also needed the FB session to be able to do this:

/**
 * Implements hook_simple_fb_connect_login().
 */
function mymodule_simple_fb_connect_login($drupal_user, $fb_profile, $fb_session) {
  $save = FALSE;
  // Check user name
  if ($fb_profile->getProperty('name') != $drupal_user->user) {
    $drupal_user->name = $fb_profile->getProperty('name');
    $save = TRUE;
  }
  // Override picture if not the default one
  if (!$drupal_user->picture) {
    $fid = simple_fb_connect_get_fb_profile_pic($fb_session);
    $drupal_user->picture = file_load($fid);
    $save = TRUE;
  }
  // Save changes
  if ($save) {
    user_save($drupal_user, $edit);
  }
}

So I updated the patch

  • masipila committed ee87d8b on 7.x-2.x authored by lesonunique
    Issue #2578359 by lesonunique: DX: every Rules hook should match a...
masipila’s picture

Status: Needs review » Fixed

Hi,

thanks for the suggestion and the patch!

I modified the patch slightly before committing so lesonunique be sure to modify the hook implementation accordingly on your site.

FacebookSession and Facebook Profile ($fb_session and $fb_profile) are not arguments for the hook. The reason for this is that I don't want to add them as parameters to function simple_fb_connect_login_user. In the D8 version of this module, all FB related stuff is isolated to one class and all Drupal user management related stuff is isolated to another class. The D7 version is still old-school procedural Drupal code but I want to keep this same isolation in the D7 code base as well.

Other modules implementing the hook can easily get the FacebookSession by simply calling simple_fb_connect_get_session(). Once you have the FacebookSession,you can make whatever FB API calls you want.

Cheers,
Markus

p.s. You might want to modify your own hook implementation so that you make sure that the username is unique.

masipila’s picture

This is now part of 7.x-2.2

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

masipila’s picture

Status: Closed (fixed) » Active

I just noticed that we were missing a hook for new user creation. The earlier commit about a month ago only provided a hook for user login.

  • masipila committed 64e4a61 on 7.x-2.x
    Issue #2578359:  Added a hook for new user creation
    
masipila’s picture

Status: Active » Fixed

Now there is also a hook for new user creation (see simple_fb_connect.api.php)

This will be part of 7.x-2.3

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.