For an entity_submenu_block issue, I had to write a little update hook to introduce a new setting with a value for existing installation to not make a breaking change [BC].
The following snippet helps to find existing instances of a block from a certain Block Plugin and set a certain setting on them:
<?php
/**
* @file
* Install / update for entity_submenu_block module.
*/
/**
* Set new setting "show_if_empty"=TRUE for all existing entity_submenu_block
* blocks to keep previous behaviour of showing empty entity_submenu_block
* blocks.
*/
function entity_submenu_block_update_8001() {
// Get all block instances of the type 'my_custom_block'.
$block_storage = \Drupal::entityTypeManager()->getStorage('block');
$block_ids = \Drupal::entityQuery('block')
->condition('plugin', 'entity_submenu_block:', 'STARTS_WITH')
->execute();
$blocks = $block_storage->loadMultiple($block_ids);
$count = 0;
/** @var \Drupal\block\BlockInterface[] $blocks */
foreach ($blocks as $block) {
$configuration = $block->get('settings');
// Set the new setting if it doesn't exist.
if (!isset($configuration['show_if_empty'])) {
$configuration['show_if_empty'] = TRUE;
$block->set('settings', $configuration);
$block->save();
$count++;
}
}
return t('Set "Show the block, even if empty" option TRUE on @count existing entity_submenu_block blocks. Adjust the setting if needed to hide these blocks entirely, if empty.', ['@count' => $count]);
}
For details see the commit: https://git.drupalcode.org/project/entity_submenu_block/-/commit/a031db…