I have a situation where I want to change the content of a block on certain conditions, but not permanently.
I'm using a theme_preprocess_block()
hook to change the content of the block, but it's not carrying through to the page render:
function MYTHEME_preprocess_block(&$variables) {
if ( $variables['base_plugin_id'] == 'block_content'
&& $variables['attributes']['id'] == 'block-mycustomfooterblock' ) {
$variables['content']['#block_content']->set('body', [[
'value' => 'New Content',
'format' => 'full_html',
]]);
Even after clearing caches, the block content doesn't get replaced with "New Content".
I added this line
$variables['content']['#block_content']->save();
However, that permanently saved the change to the block, which I don't want.
How can I alter the block content just for the page render?