You are here

protected function ContextReaction::getReactions in Breadcrumb Manager 8

Get reactions.

Parameters

string $path: The path.

\Symfony\Component\HttpFoundation\Request $request: The Request.

Return value

\Drupal\context\ContextReactionInterface[] An array of Context reactions.

1 call to ContextReaction::getReactions()
ContextReaction::getTitle in modules/breadcrumb_manager_context/src/Plugin/BreadcrumbTitleResolver/ContextReaction.php
Get title.

File

modules/breadcrumb_manager_context/src/Plugin/BreadcrumbTitleResolver/ContextReaction.php, line 125

Class

ContextReaction
Class ContextReaction.

Namespace

Drupal\breadcrumb_manager_context\Plugin\BreadcrumbTitleResolver

Code

protected function getReactions($path, Request $request) {
  $cid = "context:{$path}";
  $cache = $this->cache
    ->get($cid);
  if (!empty($cache->data)) {
    return $cache->data;
  }
  $requestHasChanged = FALSE;
  $currentRequest = $this->requestStack
    ->getCurrentRequest();
  if ($currentRequest
    ->getPathInfo() !== $request
    ->getPathInfo()) {

    // Pop out the original Request.
    $orig = $this->requestStack
      ->pop();

    // Assign original session to the new Request.
    $request
      ->setSession($orig
      ->getSession());

    // Switch the new Request with the old one and evaluate contexts again.
    $this->requestStack
      ->push($request);
    $this->contextManager
      ->evaluateContexts();

    // Push the old Request back.
    $this->requestStack
      ->push($orig);

    // Mark Request as changed.
    $requestHasChanged = TRUE;
  }
  $reactions = $this->contextManager
    ->getActiveReactions('breadcrumb');
  $this->cache
    ->set($cid, $reactions, Cache::PERMANENT, [
    'breadcrumb_manager',
    'breadcrumb_manager_context',
  ]);

  // If Request has changed, evaluate contexts again in order to avoid wrong
  // reactions to be used.
  if ($requestHasChanged) {
    $this->contextManager
      ->evaluateContexts();
  }
  return $reactions;
}