public function AliasSubscriber::onRequestSetController in Mini site 8
Set Minisite delivery controller if request URI matches asset alias.
Parameters
Symfony\Component\HttpKernel\Event\GetResponseEvent $event: Event that is created to create a response for a request.
File
- src/
EventSubscriber/ AliasSubscriber.php, line 26
Class
- AliasSubscriber
- Class AliasSubscriber.
Namespace
Drupal\minisite\EventSubscriberCode
public function onRequestSetController(GetResponseEvent $event) {
// Do not alter non-master request (this is a case when an exception is
// thrown in controller).
if (!$event
->isMasterRequest()) {
return;
}
$request = $event
->getRequest();
// Load asset by the request URI which is an asset alias. This call must
// be as "lightweight" as possible as it will run before any other routes
// are considered (it is still faster to run this before all RouterListener
// processing).
$parsed_uri = UrlHelper::parse($request
->getRequestUri());
$asset = Asset::loadByAlias($parsed_uri['path']);
if ($asset) {
$request->attributes
->set('_controller', '\\Drupal\\minisite\\Controller\\AliasController::deliverAsset');
$request->attributes
->set('asset_id', $asset
->id());
// Stop further propagation as our raw URL has matched.
$event
->stopPropagation();
}
}