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
Comments
Comment #2
keshavv commented@Cangurin limpiezas
URL::createFromRoutemethod is deprecated, UseUrl::fromRouteinstead.I have modified your code. Now it will work.
Comment #3
keshavv commented@rlmumford, Please update the deprecated code from Module page. AS mentioned above.
Comment #4
rlmumfordThanks, that is updated.
Comment #5
rlmumfordComment #6
keshavv commented