function AssetRoutes::routes

Same name and namespace in other branches
  1. 10 core/modules/system/src/Routing/AssetRoutes.php \Drupal\system\Routing\AssetRoutes::routes()

Returns an array of route objects.

Return value

\Symfony\Component\Routing\Route[] An array of route objects.

1 string reference to 'AssetRoutes::routes'
system.routing.yml in core/modules/system/system.routing.yml
core/modules/system/system.routing.yml

File

core/modules/system/src/Routing/AssetRoutes.php, line 40

Class

AssetRoutes
Defines a routes' callback to register a URL for serving assets.

Namespace

Drupal\system\Routing

Code

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.