Fix with a switch to support generate Absolute String using the Drupal 10 file_url_generator service as the function was deprecated

Created on 2 October 2023, about 1 year ago
Updated 15 October 2023, about 1 year ago

Problem/Motivation

I got this error using Drupal 10
Error: Call to undefined function file_create_url() in varbase_email_preprocess_email() (line 84 of modules/contrib/varbase_email/varbase_email.module).

Steps to reproduce

Sending an email

Proposed resolution

Functions file_create_url() and file_url_transform_relative() are deprecated.

Instead, get file_url_generatorservice injected into your service or controller from the container and call its methods.

Before -> After
file_create_url($uri) -> \Drupal::service('file_url_generator')->generateAbsoluteString($uri)
file_url_transform_relative($file_url) -> \Drupal::service('file_url_generator')->transformRelative($file_url)
file_url_transform_relative(file_create_url($uri) -> \Drupal::service('file_url_generator')->generateString($uri)
Drupal\Core\Url::fromUri(file_create_url($uri)) -> \Drupal::service('file_url_generator')->generate($uri)

The new service 'file_url_generator' is providing the following new methods:

The method generateString() which creates a root-relative web-accessible URL string;
The method generateAbsoluteString() which creates an absolute web-accessible URL string;
The method generate() which creates a root-relative web-accessible URL object;
The method transformRelative() which transforms an absolute URL of a local file to a relative URL.

Remaining tasks

  • ✅ File an issue about this project
  • ✅ Addition/Change/Update/Fix to this project
  • ✅ Testing to ensure no regression
  • ➖ Automated unit/functional testing coverage
  • ➖ Developer Documentation support on feature change/addition
  • ➖ User Guide Documentation support on feature change/addition
  • ✅ Accessibility and Readability
  • ✅ Code review from 1 Varbase core team member
  • ✅ Full testing and approval
  • ✅ Credit contributors
  • ✅ Review with the product owner
  • ✅ Update Release Notes and Update Helper on new feature change/addition
  • ❌ Release varbase-10.0.0-beta2 , varbase_email-10.0.0-rc1 , varbase-9.0.16 , varbase_email-9.0.5

Varbase update type

  • ✅ No Update
  • ➖ Optional Update
  • ➖ Forced Update
  • ➖ Forced Update if Unchanged

User interface changes

  • N/A

API changes

  • N/A

Data model changes

  • N/A

Release notes snippet

  • Issue #3390982 by YazanMajadba : Fixed with a switch to support generate Absolute String using the Drupal 10 file_url_generator service as the function was deprecated
🐛 Bug report
Status

Fixed

Version

9.0

Component

Code

Created by

🇯🇴Jordan YazanMajadba

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

Comments & Activities

Production build 0.71.5 2024