SimpleFbConnectPostLoginManager.php in Simple FB Connect 8.2
File
src/SimpleFbConnectPostLoginManager.php
View source
<?php
namespace Drupal\simple_fb_connect;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Routing\RequestContext;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Drupal\Core\Path\PathValidatorInterface;
use Drupal\user\Entity\User;
class SimpleFbConnectPostLoginManager {
protected $configFactory;
protected $requestContext;
protected $session;
protected $pathValidator;
public function __construct(ConfigFactoryInterface $config_factory, SessionInterface $session, RequestContext $request_context, PathValidatorInterface $path_validator) {
$this->configFactory = $config_factory;
$this->requestContext = $request_context;
$this->session = $session;
$this->pathValidator = $path_validator;
}
public function getPostLoginPathFromRequest() {
if ($query_string = $this->requestContext
->getQueryString()) {
parse_str($query_string, $query_params);
if (isset($query_params['postLoginPath'])) {
return $query_params['postLoginPath'];
}
}
return FALSE;
}
public function savePostLoginPathToSession($post_login_path) {
if (!is_null($post_login_path)) {
$this->session
->set('simple_fb_connect_post_login_path', $post_login_path);
}
}
public function getPostLoginPath() {
$post_login_path = $this->session
->get('simple_fb_connect_post_login_path');
if ($post_login_path) {
if ($valid_path = $this
->validateInternalPath($post_login_path)) {
return $valid_path;
}
}
$post_login_path = $this
->getPostLoginPathSetting();
if ($valid_path = $this
->validateInternalPath($post_login_path)) {
return $valid_path;
}
$post_login_path = 'user';
return $this
->validateInternalPath($post_login_path);
}
public function getRedirectNewUsersToUserFormSetting() {
return $this->configFactory
->get('simple_fb_connect.settings')
->get('redirect_user_form');
}
public function getPathToUserForm(User $drupal_user) {
$uid = $drupal_user
->id();
$post_login_path = 'user/' . $uid . '/edit';
$url = $this->pathValidator
->getUrlIfValid($post_login_path);
return $url
->toString();
}
protected function getPostLoginPathSetting() {
return $this->configFactory
->get('simple_fb_connect.settings')
->get('post_login_path');
}
protected function validateInternalPath($path) {
$url = $this->pathValidator
->getUrlIfValid($path);
if ($url !== FALSE && $url
->isExternal() === FALSE) {
return $url
->toString();
}
return FALSE;
}
}