How can I programatically change the content of a block and keep Full HTML formatting
The body field has at least two properties, value and format. To replace the complete field content, you have to use an array:

$my_block-&gt;set('body', [[
  'value' =&gt; '&lt;h1&gt;' . $my_processed_string . '&lt;/h1&gt;',
  'format' =&gt; 'full_html',
]]);


Normally you don't need to do this. Set only the value property:

$my_block-&gt;body-&gt;value = '&lt;h1&gt;' . $my_processed_string . '&lt;/h1&gt;';


So that you don't overwrite properties you don't want to change.