You are here

class BackgroundImageRoutes in Background Image 2.0.x

Same name and namespace in other branches
  1. 8 src/Routing/BackgroundImageRoutes.php \Drupal\background_image\Routing\BackgroundImageRoutes
  2. 2.x src/Routing/BackgroundImageRoutes.php \Drupal\background_image\Routing\BackgroundImageRoutes

Defines a route subscriber to register a url for serving background image CSS.

Hierarchy

Expanded class hierarchy of BackgroundImageRoutes

File

src/Routing/BackgroundImageRoutes.php, line 13

Namespace

Drupal\background_image\Routing
View source
class BackgroundImageRoutes implements ContainerInjectionInterface {

  /**
   * The stream wrapper manager service.
   *
   * @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface
   */
  protected $streamWrapperManager;

  /**
   * Constructs a new BackgroundImageRoutes object.
   *
   * @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager
   *   The stream wrapper manager service.
   */
  public function __construct(StreamWrapperManagerInterface $stream_wrapper_manager) {
    $this->streamWrapperManager = $stream_wrapper_manager;
  }

  /**
   * {@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() {
    $routes = [];

    // Generate background image CSS files. If clean URLs are disabled the
    // files will always be served through the menu system. If clean URLs are
    // enabled and the file already exists, PHP will be bypassed.
    $directory_path = $this->streamWrapperManager
      ->getViaScheme('public')
      ->getDirectoryPath();
    $routes['background_image.css'] = new Route('/' . $directory_path . '/background_image/css/{background_image}/{scheme}/{file}', [
      '_controller' => 'Drupal\\background_image\\Controller\\BackgroundImageCssController::deliver',
    ], [
      '_access' => 'TRUE',
    ]);
    return $routes;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BackgroundImageRoutes::$streamWrapperManager protected property The stream wrapper manager service.
BackgroundImageRoutes::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
BackgroundImageRoutes::routes public function Returns an array of route objects.
BackgroundImageRoutes::__construct public function Constructs a new BackgroundImageRoutes object.