Reputation: 669
I'm trying to import data into a Drupal 8 everyday and I'm blocked at the point where I need to update images. So I've got a Image field which contains unlimited images.
When I first import images, I'm creating them and adding them to the node field_images field. The adding is working.
$entity = Node::create(
[...,
field_images => [$file1],
...
]);
When there's a node update, I need to replace every changed value of this node. This code is working perfectly
$node = Node::load(1);
$node->set('field_images',[$file2]);
$node->save();
Now this doesn't work when I enable translations as it edits only the default value. See this debugger image when I reload this updated node:
How could I update all translations too ?
Upvotes: 1
Views: 1511
Reputation: 146
You need to do something like this:
'field_image' =>
[
'target_id' => $values['image'][0],
'alt' => $values['title'],
],
Upvotes: 1