Error downloading CSS on sites without the Language module

Created on 27 June 2023, over 1 year ago
Updated 7 November 2023, about 1 year ago

Problem/Motivation

When trying to get the dynamically generated CSS on a site without the language module installed I get:

The website encountered an unexpected error. Please try again later.<br /><em class="placeholder">TypeError</em>: Drupal\background_image\Controller\BackgroundImageCssController::deliver(): Argument #4 ($language) must be of type Drupal\Core\Language\Language, string given 

This happens because the function expects a Language entity to be passed in, which it does not exist.

Proposed resolution

This is essentially a hidden dependency on the language module. In order to not force the sites to install it if it is not needed otherwise I'd suggest that we accept a string parameter instead.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇸🇮Slovenia slashrsm

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @slashrsm
  • Status changed to Needs review over 1 year ago
  • 🇬🇧United Kingdom gMaximus

    I've tested this on the dev branch.

    I also had to change line 206 of the controller to $css_minifier->addLicense($data, preg_replace('/\.min\.css$/', '.css', \Drupal::service('file_url_generator')->generateAbsoluteString($uri)));

    Otherwise I was getting this error:

    Error: Call to undefined function Drupal\background_image\Controller\file_create_url() in Drupal\background_image\Controller\BackgroundImageCssController->buildCss() (line 206 of \background_image\src\Controller\BackgroundImageCssController.php).

    The file_create_url() method is deprecated. See this: https://www.drupal.org/node/2940031

    Thanks for your patch. I've been stuck on this for a couple of days.

  • Status changed to Fixed about 1 year ago
  • 🇦🇺Australia Nigel Cunningham Geelong

    Thanks for the report.

    I saw this too today and have committed the same change; it is working for me now on the dev branch. I hope to make a new release shortly. If you have any further issues, please let me know.

    Thanks again!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024