I need to programmatically change the content of a ui configured block. I've partially figured out how to do this, ie:
$ids = \Drupal::entityQuery('block_content') ->condition('type', 'custom_block_type') ->condition('info', 'Specific block title') ->execute(); $my_block = BlockContent::load(array_values($ids)); $my_block->set('body','<h1>'.$my_processed_string.'</h1>'); $my_block->save();
This does change the content, but when I do this the block loses the Full HTML block format, and the new content in printed out verbatim as html encoded content (ie, the user literally sees '<h1>My altered value</h1>' on the screen). If I go through the ui and change the Text Format field manually to Full HTML, it renders correctly, but that doesn't really accomplish what I need to do.
How can I change the content programatically, without losing the html formatting?
$my_block->body->format = 'full_html';