You are here

class S3fsImageStyleRoutes in S3 File System 8.3

Same name and namespace in other branches
  1. 4.0.x src/Routing/S3fsImageStyleRoutes.php \Drupal\s3fs\Routing\S3fsImageStyleRoutes

Defines a route subscriber to register a url for serving image styles.

Hierarchy

Expanded class hierarchy of S3fsImageStyleRoutes

File

src/Routing/S3fsImageStyleRoutes.php, line 13

Namespace

Drupal\s3fs\Routing
View source
class S3fsImageStyleRoutes implements ContainerInjectionInterface {

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * Constructs a new S3fsImageStyleRoutes object.
   *
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   */
  public function __construct(ModuleHandlerInterface $module_handler) {
    $this->moduleHandler = $module_handler;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('module_handler'));
  }

  /**
   * Returns an array of route objects.
   *
   * @return \Symfony\Component\Routing\Route[]
   *   An array of route objects.
   */
  public function routes() {
    $routes = [];

    // Only add route for image styles if image module is enabled.
    if ($this->moduleHandler
      ->moduleExists('image')) {
      $routes['s3fs.image_styles'] = new Route('/s3/files/styles/{image_style}/{scheme}', [
        '_controller' => 'Drupal\\s3fs\\Controller\\S3fsImageStyleDownloadController::deliver',
      ], [
        '_access' => 'TRUE',
      ]);

      // @see \Drupal\redirect\Routing\RouteSubscriber::alterRoutes()
      if ($this->moduleHandler
        ->moduleExists('redirect')) {
        $routes['s3fs.image_styles']
          ->setDefault('_disable_route_normalizer', TRUE);
      }
    }
    return $routes;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
S3fsImageStyleRoutes::$moduleHandler protected property The module handler.
S3fsImageStyleRoutes::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
S3fsImageStyleRoutes::routes public function Returns an array of route objects.
S3fsImageStyleRoutes::__construct public function Constructs a new S3fsImageStyleRoutes object.