You are here

public function SimpleFbConnectFbManager::getFbLoginUrl in Simple FB Connect 8.3

Same name and namespace in other branches
  1. 8.2 src/SimpleFbConnectFbManager.php \Drupal\simple_fb_connect\SimpleFbConnectFbManager::getFbLoginUrl()

Returns the Facebook login URL where user will be redirected.

Return value

string Absolute Facebook login URL where user will be redirected

File

src/SimpleFbConnectFbManager.php, line 66

Class

SimpleFbConnectFbManager
Contains all Simple FB Connect logic that is related to Facebook interaction.

Namespace

Drupal\simple_fb_connect

Code

public function getFbLoginUrl() {
  $login_helper = $this->facebook
    ->getRedirectLoginHelper();

  // Define the URL where Facebook should return the user.
  $return_url = $this->urlGenerator
    ->generateFromRoute('simple_fb_connect.return_from_fb', [], [
    'absolute' => TRUE,
  ]);

  // Define the initial array of Facebook permissions.
  $scope = [
    'public_profile',
    'email',
  ];

  // Dispatch an event so that other modules can modify the permission scope.
  // Set the scope twice on the event: as the main subject but also in the
  // list of arguments.
  $e = new GenericEvent($scope, [
    'scope' => $scope,
  ]);
  $event = $this->eventDispatcher
    ->dispatch('simple_fb_connect.scope', $e);
  $final_scope = $event
    ->getArgument('scope');

  // Generate and return the URL where we should redirect the user.
  return $login_helper
    ->getLoginUrl($return_url, $final_scope);
}