diff --git a/src/Controller/BackgroundImageCssController.php b/src/Controller/BackgroundImageCssController.php index 2be46ca..6555e32 100644 --- a/src/Controller/BackgroundImageCssController.php +++ b/src/Controller/BackgroundImageCssController.php @@ -8,6 +8,7 @@ use Drupal\Core\File\Exception\FileException; use Drupal\Core\File\Exception\FileWriteException; use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Image\ImageFactory; +use Drupal\Core\Language\Language; use Drupal\Core\Lock\LockBackendInterface; use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface; use Drupal\Core\Theme\ThemeManagerInterface; @@ -326,6 +327,8 @@ class BackgroundImageCssController extends FileDownloadController { * The background image entity. * @param string $scheme * The file scheme, defaults to 'private'. + * @param \Drupal\Core\Language\Language $language; + * The language to load the background image entity in. * @param string $file * The file name to generate. * @@ -337,14 +340,19 @@ class BackgroundImageCssController extends FileDownloadController { * @throws \Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException * Thrown when the file is still being generated. */ - public function deliver(Request $request, BackgroundImageInterface $background_image, $scheme, $file = NULL) { + public function deliver(Request $request, BackgroundImageInterface $background_image, $scheme, Language $language, $file = NULL) { // Ensure this is a valid background image, scheme and user has permission. $valid = !empty($background_image) && $this->streamWrapperManager->isValidScheme($scheme) && $background_image->access('view'); if (!$valid) { throw new AccessDeniedHttpException(); } - $uri = "$scheme://background_image/css/{$background_image->id()}/$scheme/$file"; + // Make sure to work with the correct translation. + if ($background_image->isTranslatable() && $background_image->hasTranslation($language->getId())) { + $background_image = $background_image->getTranslation($language->getId()); + } + + $uri = "$scheme://background_image/css/{$background_image->id()}/$scheme/{$language->getId()}/$file"; // If using the private scheme, let other modules provide headers and // control access to the file. diff --git a/src/Entity/BackgroundImage.php b/src/Entity/BackgroundImage.php index ad59f93..b4e0698 100644 --- a/src/Entity/BackgroundImage.php +++ b/src/Entity/BackgroundImage.php @@ -316,7 +316,7 @@ class BackgroundImage extends ContentEntityBase implements BackgroundImageInterf public function getCssUri() { $default_scheme = \Drupal::config('system.file')->get('default_scheme'); $min = $this->getBackgroundImageManager()->useMinifiedCssUri() ? '.min' : ''; - return "$default_scheme://background_image/css/{$this->id()}/$default_scheme/{$this->getImageHash()}$min.css"; + return "$default_scheme://background_image/css/{$this->id()}/$default_scheme/{$this->language()->getId()}/{$this->getImageHash()}$min.css"; } /** diff --git a/src/Routing/BackgroundImageRoutes.php b/src/Routing/BackgroundImageRoutes.php index 962ea81..1b5ef32 100644 --- a/src/Routing/BackgroundImageRoutes.php +++ b/src/Routing/BackgroundImageRoutes.php @@ -52,12 +52,19 @@ class BackgroundImageRoutes implements ContainerInjectionInterface { $directory_path = $this->streamWrapperManager->getViaScheme('public')->getDirectoryPath(); $routes['background_image.css'] = new Route( - '/' . $directory_path . '/background_image/css/{background_image}/{scheme}/{file}', + '/' . $directory_path . '/background_image/css/{background_image}/{scheme}/{language}/{file}', [ '_controller' => 'Drupal\background_image\Controller\BackgroundImageCssController::deliver', ], [ '_access' => 'TRUE', + ], + [ + 'parameters' => [ + 'language' => [ + 'type' => 'language', + ], + ], ] ); return $routes;