You are here

private function PathContext::setIdentityByRequest in Acquia Lift Connector 8

Set Identity by request stack's query parameters.

Parameters

\Symfony\Component\HttpFoundation\RequestStack $request_stack: The request stack.

1 call to PathContext::setIdentityByRequest()
PathContext::__construct in src/Service/Context/PathContext.php
Constructor.

File

src/Service/Context/PathContext.php, line 116
Contains \Drupal\acquia_lift\Service\Context\PathContext.

Class

PathContext

Namespace

Drupal\acquia_lift\Service\Context

Code

private function setIdentityByRequest($request_stack) {

  // Stop, if there is no "identity parameter".
  if (empty($this->identitySettings['identity_parameter'])) {
    return;
  }

  // Find the current URL queries.
  $query_string = $request_stack
    ->getCurrentRequest()
    ->getQueryString();
  $parsed_query_string = UrlHelper::parse('?' . $query_string);
  $queries = $parsed_query_string['query'];
  $identity_parameter = $this->identitySettings['identity_parameter'];

  // Stop, if there is no or empty identity parameter in the query string.
  if (empty($queries[$identity_parameter])) {
    return;
  }

  // Gather the identity and identity type by configuration.
  $identity_type_parameter = $this->identitySettings['identity_type_parameter'];
  $default_identity_type = $this->identitySettings['default_identity_type'];
  $identity = $queries[$identity_parameter];
  $identityType = empty($default_identity_type) ? SettingsHelper::DEFAULT_IDENTITY_TYPE_DEFAULT : $default_identity_type;
  if (!empty($identity_type_parameter) && isset($queries[$identity_type_parameter])) {
    $identityType = $queries[$identity_type_parameter];
  }
  $this
    ->setIdentity($identity, $identityType);
}