Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\image\Routing;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
Chris@0
|
6 use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
|
Chris@0
|
7 use Symfony\Component\DependencyInjection\ContainerInterface;
|
Chris@0
|
8 use Symfony\Component\Routing\Route;
|
Chris@0
|
9
|
Chris@0
|
10 /**
|
Chris@0
|
11 * Defines a route subscriber to register a url for serving image styles.
|
Chris@0
|
12 */
|
Chris@0
|
13 class ImageStyleRoutes implements ContainerInjectionInterface {
|
Chris@0
|
14
|
Chris@0
|
15 /**
|
Chris@0
|
16 * The stream wrapper manager service.
|
Chris@0
|
17 *
|
Chris@0
|
18 * @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface
|
Chris@0
|
19 */
|
Chris@0
|
20 protected $streamWrapperManager;
|
Chris@0
|
21
|
Chris@0
|
22 /**
|
Chris@16
|
23 * Constructs a new ImageStyleRoutes object.
|
Chris@0
|
24 *
|
Chris@0
|
25 * @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager
|
Chris@0
|
26 * The stream wrapper manager service.
|
Chris@0
|
27 */
|
Chris@0
|
28 public function __construct(StreamWrapperManagerInterface $stream_wrapper_manager) {
|
Chris@0
|
29 $this->streamWrapperManager = $stream_wrapper_manager;
|
Chris@0
|
30 }
|
Chris@0
|
31
|
Chris@0
|
32 /**
|
Chris@0
|
33 * {@inheritdoc}
|
Chris@0
|
34 */
|
Chris@0
|
35 public static function create(ContainerInterface $container) {
|
Chris@0
|
36 return new static(
|
Chris@0
|
37 $container->get('stream_wrapper_manager')
|
Chris@0
|
38 );
|
Chris@0
|
39 }
|
Chris@0
|
40
|
Chris@0
|
41 /**
|
Chris@0
|
42 * Returns an array of route objects.
|
Chris@0
|
43 *
|
Chris@0
|
44 * @return \Symfony\Component\Routing\Route[]
|
Chris@0
|
45 * An array of route objects.
|
Chris@0
|
46 */
|
Chris@0
|
47 public function routes() {
|
Chris@0
|
48 $routes = [];
|
Chris@0
|
49 // Generate image derivatives of publicly available files. If clean URLs are
|
Chris@0
|
50 // disabled image derivatives will always be served through the menu system.
|
Chris@0
|
51 // If clean URLs are enabled and the image derivative already exists, PHP
|
Chris@0
|
52 // will be bypassed.
|
Chris@0
|
53 $directory_path = $this->streamWrapperManager->getViaScheme('public')->getDirectoryPath();
|
Chris@0
|
54
|
Chris@0
|
55 $routes['image.style_public'] = new Route(
|
Chris@0
|
56 '/' . $directory_path . '/styles/{image_style}/{scheme}',
|
Chris@0
|
57 [
|
Chris@0
|
58 '_controller' => 'Drupal\image\Controller\ImageStyleDownloadController::deliver',
|
Chris@0
|
59 ],
|
Chris@0
|
60 [
|
Chris@0
|
61 '_access' => 'TRUE',
|
Chris@0
|
62 ]
|
Chris@0
|
63 );
|
Chris@0
|
64 return $routes;
|
Chris@0
|
65 }
|
Chris@0
|
66
|
Chris@0
|
67 }
|