public function FlysystemRoutes::routes in Flysystem 8
Same name and namespace in other branches
- 3.x src/Routing/FlysystemRoutes.php \Drupal\flysystem\Routing\FlysystemRoutes::routes()
- 2.0.x src/Routing/FlysystemRoutes.php \Drupal\flysystem\Routing\FlysystemRoutes::routes()
- 3.0.x src/Routing/FlysystemRoutes.php \Drupal\flysystem\Routing\FlysystemRoutes::routes()
Returns a list of route objects.
Return value
\Symfony\Component\Routing\Route[] An array of route objects.
1 string reference to 'FlysystemRoutes::routes'
File
- src/
Routing/ FlysystemRoutes.php, line 72
Class
- FlysystemRoutes
- Defines a route subscriber to register a url for serving image styles.
Namespace
Drupal\flysystem\RoutingCode
public function routes() {
$public_directory_path = $this->streamWrapperManager
->getViaScheme('public')
->getDirectoryPath();
$routes = [];
$all_settings = Settings::get('flysystem', []);
foreach ($this->factory
->getSchemes() as $scheme) {
$settings = $all_settings[$scheme];
if ($settings['driver'] !== 'local' || empty($settings['config']['public'])) {
continue;
}
// If the root is the same as the public files directory, skip adding a
// route.
if ($settings['config']['root'] === $public_directory_path) {
continue;
}
$routes['flysystem.' . $scheme . '.serve'] = new Route('/' . $settings['config']['root'], [
'_controller' => 'Drupal\\system\\FileDownloadController::download',
'_disable_route_normalizer' => TRUE,
'scheme' => $scheme,
], [
'_access' => 'TRUE',
]);
if ($this->moduleHandler
->moduleExists('image')) {
// Public image route.
$routes['flysystem.' . $scheme . '.style_public'] = new Route('/' . $settings['config']['root'] . '/styles/{image_style}/' . $scheme, [
'_controller' => 'Drupal\\image\\Controller\\ImageStyleDownloadController::deliver',
'_disable_route_normalizer' => TRUE,
'scheme' => $scheme,
], [
'_access' => 'TRUE',
]);
}
}
if ($this->moduleHandler
->moduleExists('image')) {
// Internal image rotue.
$routes['flysystem.image_style'] = new Route('/_flysystem/styles/{image_style}/{scheme}', [
'_controller' => 'Drupal\\image\\Controller\\ImageStyleDownloadController::deliver',
'_disable_route_normalizer' => TRUE,
], [
'_access' => 'TRUE',
'scheme' => '^[a-zA-Z0-9+.-]+$',
]);
}
return $routes;
}