$file = File::create([ 'uri' => $data['image']['url'], ]); $file->save(); $media = Media::create([ 'bundle' => 'image', 'field_origin_id' => $data['image']['id'], 'field_fecha' => time(), 'field_media_image' => [ 'target_id' => $file->id(), 'title' => $data['image']['title']['es'], 'alt' => $data['image']['alt']['es'], ], ]); $media->save(); $node->field_ref_image = $media; $node->save();
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter