Having issues saving altered value in a view pre render I am trying to remove image tags in the view prerender. I've looked through articles and StackExchange and I have set it up correctly. But when I refresh the page containing the view, all the HTML tags are now present as a string.

Here's my code. 

function mytheme_views_pre_render(Drupal\views\ViewExecutable $view) {
  if ($view-&gt;id() == "news" &amp;&amp; $view-&gt;current_display == 'block_1') {
    foreach ($view-&gt;result as $row) {
      $body = $row-&gt;_entity-&gt;body-&gt;value;
      $stripped_img = preg_replace('/&lt;img[^&gt;]+\&gt;/i', '', $body);
      if ($stripped_img != $body) {
        $row-&gt;_entity-&gt;body-&gt;setValue($stripped_img);
      }
    }
  }
}
You should set the format of body to full_html try with:

function mytheme_views_pre_render(Drupal\views\ViewExecutable $view) {
  if ($view-&gt;id() == "news" &amp;&amp; $view-&gt;current_display == 'block_1') {
    foreach ($view-&gt;result as $key =&gt; $row) {
      $body = $row-&gt;_entity-&gt;body-&gt;value;
      $stripped_img = preg_replace('/&lt;img[^&gt;]+\&gt;/i', '', $body);
      if ($stripped_img != $body) {
        $row-&gt;_entity-&gt;body-&gt;setValue($stripped_img);
        // Here set the format of body to full_html
        $row-&gt;_entity-&gt;body-&gt;format='full_html';
      }
    }
  }
}