update node field Programmatically I want to learn to alter node fields after a migration. I have a custom module and inside is a .inc file I use as a script that I will run once using drush eval module_load_include. I want to learn a simple task like replacing text inside all nodes body field. First I load all nodes, then search the body fields for all nodes for the word "red" than I want to replace that word with "blue" How would I write this? This is my starting point

&lt;?php

use Drupal\Component\Utility\Html;
use \Drupal\node\Entity\Node;

function _update_node() {

// load nodes  
foreach($nids as $nid) {
    $node = Node::load($nid);

// do the work  here

  $node-&gt;save();

}


Then I want to run this script once. My module name is create_content. So I can run the command. 

drush eval "module_load_include('inc', 'create_content', 'create_content'); _update_node();" &gt; debug.txt
Here is how to update body field :

$nodes = Node::loadMultiple();
foreach($nodes as $node){
  $html = $node-&gt;body-&gt;value;
  $html = str_replace('blue','red',$html);  
  $node-&gt;set('body', [
          'summary' =&gt; 'the summary',
          'value' =&gt; $html,
          'format' =&gt; 'full_html', // probably, 
          /**
           * Correspond with format you need in admin/config/content/formats
           */
   ]);
   $node-&gt;save();
}