Programmatically update alt tag on image field I have a Drupal 8 site with a content type that has an image field. For existing nodes of this type, most have image files, but none have alt tags. 

I am writing an update hook where I want to set the alt tag value for existing nodes. However, I have not been able to figure out how, nor find documentation. 

This is what I have: 

$nids = \Drupal::entityQuery('node')-&gt;condition('type','sfa_social_post')-&gt;execute();
$nodes = \Drupal\node\Entity\Node::loadMultiple($nids);

foreach ( $nodes as $node ) {
  $node-&gt;field_sfa_image_file-&gt;alt = 'Image for ' . $node-&gt;getTitle();
}


Where field_sfa_image_file is the name of the image field. 

When I re-loop through the nodes, I get back the value that I set.

$nids = \Drupal::entityQuery('node')-&gt;condition('type','sfa_social_post')-&gt;execute();
$nodes = \Drupal\node\Entity\Node::loadMultiple($nids);

foreach ( $nodes as $node ) {
  drush_print('Title: ' . $node-&gt;getTitle());
  drush_print('Alt: ' . $node-&gt;field_sfa_image_file-&gt;alt);
}


Which gives me 

Title: Instagram Post ID: 1917569620391415985_3017827348
Alt: Image for Instagram Post ID: 1917569620391415985_3017827348
Title: Instagram Post ID: 1917562614863492125_3017827348
Alt: Image for Instagram Post ID: 1917562614863492125_3017827348


So all seems good. However, when I navigate to nodes, I don't see my alt text:



How do I set the alt tag for an existing image field?
As @clive suggested use $node-&gt;save();. Without node saving, alt of the image will not show up in the edit form.

$nids = \Drupal::entityQuery('node')-&gt;condition('type','sfa_social_post')-&gt;execute();
$nodes = \Drupal\node\Entity\Node::loadMultiple($nids);
foreach ($nodes as $node) {
  $node-&gt;field_sfa_image_file-&gt;alt = 'Image for ' . $node-&gt;getTitle();
  $node-&gt;save();
}