Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
I using a managed file form field to upload an image which I then want to assign to a field on a node.
I see a media image entity is created like this
$values = [
'targetEntityType' => "media",
'bundle' => "image",
'status' => true
];
$imageEntity = Media::create($values);
Now i'm stuck. Some pointers in the right direction would be excellent.
Comments
Comment #2
marcoscanoYou can see an example here: #2813025: Create Drupal8 Node Programmatically that contains two media fields
Feel free to re-open if it is not clear enough
Comment #4
slefevre1 CreditAttribution: slefevre1 as a volunteer commentedIn the example code cited, there are these lines:
How does one figure out what the bundle name is?
Comment #5
spfaffly CreditAttribution: spfaffly as a volunteer commented#2832079-4: How to create Media Entity Image programatically and assign to field on a node
You can lookup the bundle name in the "Media Upload" config page in the admin screen:
/admin/config/media/upload