i need to make an import from one mysql table in my base.

I create node with :

$value= array(
                'type' => strtolower($typeProduit),
                'body' => array(
                    'value' => "test",
                    'format' => 'full_html',



All node are create and if i have an image, i add it to my $value before save() :

                    '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()


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 :


But that didn't work.

this image field is set to unlimited values

1 Answer 1


i got it in the update :

i set my image_field in the update:

  $nodeEntityUpdate = \Drupal::entityTypeManager()

     $nodeEntityUpdate->field_image_video =array();

I try to set this field in the create, but that change nothing.

As i can see, we need to set image field in the update if she is empty at the creation.

  • $node->set($node->getEntityKey('label'), 'blabla')->set('field_image_video', NULL)->save(); or possibly $node->get('field_image_video')->filter(TRUE).
    – user21641
    Aug 23, 2017 at 8:47
  • yes but we need absolutly set the field_image_video ?
    – Kevin
    Aug 23, 2017 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.