You are here

protected function PanelsEverywhereRouteSubscriber::getRouteAndCleanup in Panels Everywhere 8.4

Retrieves relevant route and removes page-manager override if necessary.

The page_manager-route for the given variant will be removed if route-override is disabled, even if this will lead to a page not found. This is intended as it allows other variants on the page to provide the main page content.

Parameters

PageInterface $page: A page-manager page entity.

PageVariantInterface $variant: A variant on the page entity.

$collection: A collection of known routeis.

Return value

null|\Symfony\Component\Routing\Route Will return NULL if the variant route can not be found. Will return the variant route if route override is enabled. Will return the original route if route override is disabled. Will return NULL if the variant route is not overriding anything.

1 call to PanelsEverywhereRouteSubscriber::getRouteAndCleanup()
PanelsEverywhereRouteSubscriber::alterRoutes in src/Routing/PanelsEverywhereRouteSubscriber.php

File

src/Routing/PanelsEverywhereRouteSubscriber.php, line 94
Contains \Drupal\panels_everywhere\Routing\PanelsEverywhereRouteSubscriber.

Class

PanelsEverywhereRouteSubscriber
Associates a route with a Page Manager page, if it exists

Namespace

Drupal\panels_everywhere\Routing

Code

protected function getRouteAndCleanup(PageInterface $page, PageVariantInterface $variant, RouteCollection $collection) {
  $page_id = $page
    ->id();
  $variant_id = $variant
    ->id();
  $route_name = "page_manager.page_view_{$page_id}_{$variant_id}";
  $variantRoute = $this
    ->getRouteFor($page, $variant, $collection);
  if (is_null($variantRoute)) {
    return NULL;
  }
  if ($variant
    ->getVariantPlugin()
    ->isRouteOverrideEnabled()) {
    return $variantRoute;
  }
  $route_name_original = $variantRoute
    ->getDefault('overridden_route_name');
  $collection
    ->remove($route_name);
  return $collection
    ->get($route_name_original);
}