You are here

private function PathContext::setContextIdentityByRequest in Acquia Lift Connector 8.3

Same name and namespace in other branches
  1. 8.4 src/Service/Context/PathContext.php \Drupal\acquia_lift\Service\Context\PathContext::setContextIdentityByRequest()

Set Path Context Identity by request stack's query parameters.

Parameters

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

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

File

src/Service/Context/PathContext.php, line 111

Class

PathContext

Namespace

Drupal\acquia_lift\Service\Context

Code

private function setContextIdentityByRequest($request_stack) {

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

  // Set cache contexts. This is done as long as the identity parameter is set.
  $identity_type_parameter = $this->identitySettings['identity_type_parameter'];
  $query_names = [
    $identity_parameter,
    $identity_type_parameter,
  ];
  $this
    ->setContextCacheByQueryNames($query_names);

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

  // 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.
  $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) && !empty($queries[$identity_type_parameter])) {
    $identityType = $queries[$identity_type_parameter];
  }
  $this
    ->setContextIdentity($identity, $identityType);
}