I try to run Facebook Login on my Drupal 8 site. I run it by Social API module and with Simple FB Connect, but both module generate user name from first and last name on Facebook. My user will not be happy with using real name, but I don't want to give them options to change username whenever they want.

For code examples I use Simple FB Connect, but the same logic is in Social API modules.

User go to path user/simple-fb-connect and is redirected by Drupal\simple_fb_connect\Controller\SimpleFbConnectController->redirectToFb(), and when he is back, go to user/simple-fb-connect/return which is handle by Drupal\simple_fb_connect\Controller\SimpleFbConnectController->returnFromFb().

It checks permissions, get data from FB and then if email not exist in DB, registers user:

    // If there was no existing user, try to create a new user.
    $fbid = $fb_profile->getField('id');
    $fb_profile_pic = $this->fbManager->getFbProfilePic();
    if ($drupal_user = $this->userManager->createUser($fb_profile->getField('name'), $email, $fbid, $fb_profile_pic)) {

The main question is: How I can replace $fb_profile->getField('name') with custom, provided by user string ? I think about:

  1. Replace simple link on login with form contains textfield and submit button, which send POST/GET data to user/simple-fb-connect. There store it Session, and use on returnFromFb() function to create user.

But I can't always show an additional field (eg. on homepage), and I don't know if user want to register or just login. It kills idea, just click, and get account.

  1. After back from FB, show users one-time form, which they can't skip, and access page, before they fill it, like post-login registration in normal FB integrations, on which they can fill additional data, but only once per account.

But there I have no idea how to even start. Maybe I can replace function returnFromFb() code creating new user with register form, and after submit create user. Or leave module code in peace and base it on events from the module. But how I can lock page for user who don't fill this and secure it to be fill just one time (maybe boolean field on user entity?).

  1. The simplest way, just leave it as it is, use display name and hide login, but I don't want to store user names and last names in database.

Thanks for help!

PS. I tried to ask the creators, but it looks like the modules work like they should work.

1 Answer 1


Provided that you're using v8.3 or higher of the module, a possible solution would be to create a form where the user decides which values are stored according to his/her needs and your requirements of course.
Then, using the provided events in the module, you can redirect the user to this form which will accept the $user object and apply the changes accordingly.
You should add an EventSubscriber service which listens to simple_fb_connect.user_created event as per the module documentation linked above. Thus you're only showing this form to the user once after the account has been created and not with every login.
Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.