You are here

public function RequestPreparer::prepareForRequest in Tome 8

Prepares Drupal for a new request.

File

modules/tome_static/src/RequestPreparer.php, line 94

Class

RequestPreparer
Utility class to prepare Drupal for new requests.

Namespace

Drupal\tome_static

Code

public function prepareForRequest() {

  // Some access control handlers, like block's, determine entity access
  // based on the route (via conditions, in this case).
  foreach ($this->entityTypeManager
    ->getDefinitions() as $definition) {
    $this->entityTypeManager
      ->getAccessControlHandler($definition
      ->id())
      ->resetCache();
  }

  // Some contrib modules, like metatag, statically cache route data.
  drupal_static_reset();

  // The context repository caches all context values in memory.
  $this->contextRepository
    ->resetCache();

  // The front page route is statically cached.
  $this->pathMatcher
    ->resetCache();

  // Persist cached active trail information cache as if the request ended.
  if ($this->menuActiveTrail instanceof DestructableInterface) {
    $this->menuActiveTrail
      ->destruct();
  }

  // Reset active trail cache.
  if ($this->menuActiveTrail instanceof CacheCollectorInterface) {
    $this->menuActiveTrail
      ->reset();
  }

  // Reset the language manager.
  $this->languageManager
    ->reset();

  // Allow module-specific code to prepare as well.
  $this->eventDispatcher
    ->dispatch(TomeStaticEvents::REQUEST_PREPARE);

  // Reset unique HTML IDs.
  Html::resetSeenIds();
}