You are here

class PathProcessorBackgroundImage in Background Image 8

Same name and namespace in other branches
  1. 2.x src/PathProcessor/PathProcessorBackgroundImage.php \Drupal\background_image\PathProcessor\PathProcessorBackgroundImage
  2. 2.0.x src/PathProcessor/PathProcessorBackgroundImage.php \Drupal\background_image\PathProcessor\PathProcessorBackgroundImage

Defines a path processor to rewrite background image CSS URLs.

Hierarchy

Expanded class hierarchy of PathProcessorBackgroundImage

See also

\Drupal\image\PathProcessor\PathProcessorImageStyles

1 string reference to 'PathProcessorBackgroundImage'
background_image.services.yml in ./background_image.services.yml
background_image.services.yml
1 service uses PathProcessorBackgroundImage
path_processor.background_image in ./background_image.services.yml
Drupal\background_image\PathProcessor\PathProcessorBackgroundImage

File

src/PathProcessor/PathProcessorBackgroundImage.php, line 16

Namespace

Drupal\background_image\PathProcessor
View source
class PathProcessorBackgroundImage implements InboundPathProcessorInterface {

  /**
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

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

  /**
   * Constructs a new PathProcessorImageStyles object.
   *
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The Module Handler service.
   * @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager
   *   The Stream Wrapper Manager service.
   */
  public function __construct(ModuleHandlerInterface $module_handler, StreamWrapperManagerInterface $stream_wrapper_manager) {
    $this->moduleHandler = $module_handler;
    $this->streamWrapperManager = $stream_wrapper_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function processInbound($path, Request $request) {
    $directory_path = $this->streamWrapperManager
      ->getViaScheme('public')
      ->getDirectoryPath();

    // Immediately return if not a background image CSS path.
    if (strpos($path, '/' . $directory_path . '/background_image/css/') !== 0 && strpos($path, '/system/files/background_image/css/') !== 0) {
      return $path;
    }

    // Redirect minified CSS to non-minified CSS if site does is not able
    // to minify CSS. Note: the Background Image Manager service cannot be
    // injected because it will cause a circular reference. Instead, it must
    // be accessed during runtime.
    if (preg_match('/\\.min\\.css$/', $path) && !BackgroundImageManager::service()
      ->getCssMinifier()) {
      $path = preg_replace('/\\.min\\.css$/', '.css', $path);
    }
    return $path;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PathProcessorBackgroundImage::$moduleHandler protected property
PathProcessorBackgroundImage::$streamWrapperManager protected property The stream wrapper manager service.
PathProcessorBackgroundImage::processInbound public function Processes the inbound path. Overrides InboundPathProcessorInterface::processInbound
PathProcessorBackgroundImage::__construct public function Constructs a new PathProcessorImageStyles object.