Call to undefined method Drupal\\Core\\Url::createFromRoute()

Created on 19 August 2023, over 1 year ago
Updated 21 August 2023, over 1 year ago

Problem/Motivation

Hi , i try to use this snippet in my custom module, with PDF Tools enabled and get this error.

// Convert an entity to a PDF file.
$generator = \Drupal::service('pdf_tools.generator');
$uri = $generator->generateFromUrl(
Url::createFromRoute(
'entity.node.canonical',
[
'node' => entity_load('node', 1),
],
[
'absolute' => TRUE,
]
)->toString(),
$options
);

Error

[Sat Aug 19 20:03:11.256582 2023] [php:notice] [pid 18354] [client ::1:58706] Uncaught PHP Exception Error: "Call to undefined method Drupal\\Core\\Url::createFromRoute()" at /var/www/html/drupal---n/drupal---/web/modules/custom/customPdf/customPdf.module line 39, referer: http://localhost/---/---/web/admin/config/development/performance

thanks

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇪🇸Spain Cangurin limpiezas Zaragoza

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

Comments & Activities

Production build 0.71.5 2024