logo

Get error undefined method File::url() in Drupal 9

21
September

Get error undefined method File::url() in Drupal 9
By: Anonymous | Published On: Thu, 09/21/2023 - 16:44

I was trying to create a custom banner based on user uploaded image in node then I got following error in Drupal 9 but it was workiing in Drupal 8

 

Following code I was using

$img_url = $file->url();

Getting this error

Error: Call to undefined method Drupal\file\Entity\File::url() in theme_preprocess_page() 

I found the solution its working fine in simply use createFileUrl(); instead of url();

 

Need Help ?