i need to make an import from one mysql table in my base.
I create node with :
$value= array(
'type' => strtolower($typeProduit),
'field_1'=>"test",
'title'=>"test",
'body' => array(
'value' => "test",
'format' => 'full_html',
),
'field_2'=>"",
'field_3'=>"",
'field_4'=>"",
);
$nodeEntity=\Drupal::entityTypeManager()
->getStorage('node')
->create($value);
$nodeEntity->save();
All node are create and if i have an image, i add it to my $value before save() :
$value['field_image_video']=array(
'target_id' => $fileImageVideo->id(),
'alt' => $catalogue->titreVideo,
'title' => $catalogue->titreVideo,
);
if i have no image, i do nothing for this field.
I need to update some node programmatically after this first step.
And when i just try to change the title like this :
$nodeEntityUpdate = \Drupal::entityTypeManager()
->getStorage('node')
->load(273);
$nodeEntityUpdate->title="blabla";
$nodeEntityUpdate->save();
if node don"t have image field set, i got this error :
PHP Fatal error: Call to a member function getFileUri()
If node has image, update work.
How can i set my image_field to null ?
i try to set my image field like that on creation :
$value['field_image_video']=array();
But that didn't work.
this image field is set to unlimited values