class AssetRoutes
Same name in other branches
- 10 core/modules/system/src/Routing/AssetRoutes.php \Drupal\system\Routing\AssetRoutes
Defines a routes' callback to register a URL for serving assets.
Hierarchy
- class \Drupal\system\Routing\AssetRoutes implements \Drupal\Core\DependencyInjection\ContainerInjectionInterface
Expanded class hierarchy of AssetRoutes
File
-
core/
modules/ system/ src/ Routing/ AssetRoutes.php, line 13
Namespace
Drupal\system\RoutingView source
class AssetRoutes implements ContainerInjectionInterface {
/**
* Constructs an asset routes object.
*
* @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $streamWrapperManager
* The stream wrapper manager service.
*/
public function __construct(StreamWrapperManagerInterface $streamWrapperManager) {
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('stream_wrapper_manager'));
}
/**
* Returns an array of route objects.
*
* @return \Symfony\Component\Routing\Route[]
* An array of route objects.
*/
public function routes() : array {
$routes = [];
// Generate assets. If clean URLs are disabled image derivatives will always
// be served through the routing system. If clean URLs are enabled and the
// image derivative already exists, PHP will be bypassed.
$directory_path = $this->streamWrapperManager
->getViaScheme('assets')
->getDirectoryPath();
$routes['system.css_asset'] = new Route('/' . $directory_path . '/css/{file_name}', [
'_controller' => 'Drupal\\system\\Controller\\CssAssetController::deliver',
], [
'_access' => 'TRUE',
]);
$routes['system.js_asset'] = new Route('/' . $directory_path . '/js/{file_name}', [
'_controller' => 'Drupal\\system\\Controller\\JsAssetController::deliver',
], [
'_access' => 'TRUE',
]);
return $routes;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
AssetRoutes::create | public static | function | Overrides ContainerInjectionInterface::create | |
AssetRoutes::routes | public | function | Returns an array of route objects. | |
AssetRoutes::__construct | public | function | Constructs an asset routes object. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.