I am using Drupal 9.3.13 on localhost. I generate successfully a QR Code based on the .SVG format and store that image on public://
I have created various field types, one of which is a Field type with a machine name: field_file_svg
The goal is to attach that existing Image that lives inside public:// and attach it to field_file_svg
I am using hook_entity_presave() for this. The QR Code is generated and stored successfully, but on node it displays nothing.
In /admin/reports/dblog/ it throws the following error.
Warning: Creating default object from empty value in urlist_entity_presave() (line 83
Here is my Source Code for this matter.
$qrcode = (new QRCode($options))->render("$output"); $file_data = file_get_contents($qrcode); $file = file_save_data($file_data, 'public://t10.svg', FileSystemInterface::EXISTS_REPLACE); if (!empty($file)) { $file_arr = array( "target_id" => $file->id(), "alt" => "Alt1", "title" => "Title1" ); $node->field_file_svg = $file_arr;