you have requested a non-existent service "file_url_generator"

Created on 14 December 2023, about 1 year ago
Updated 28 February 2024, 10 months ago

Problem/Motivation

I'm using Drupal 9.2.21.

After saving the node, the error is thrown.

 You have requested a non-existent service "file_url_generator"

Steps to reproduce

  • Use Drupal version older than 9.3
  • Install the latest release of Minisite.
  • Add minisite field to content type.
  • Upload files and save the node.
  • The error will be thrown.

Proposed resolution

The file_url_generator service is added Drupal 9.3 version. So the older versions will get this error.

Either make minisite 2.0.0 compatible with only Drupal 9.3 and newer versions.

OR
Use something like to support older versions of Drupal 9.

 if (\Drupal::hasService('file_url_generator')) {
       $generator = \Drupal::service('file_url_generator');
        $file_url = $generator->transformRelative($generator->generateAbsoluteString($file->getFileUri()));
      } else {
        $file_url = file_create_url($file->getFileUri());
      }

Reference:- https://www.drupal.org/node/2940031

🐛 Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

🇮🇳India omkar-pd

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

Comments & Activities

Production build 0.71.5 2024