You are here

function menu_block_update_8102 in Menu Block 8

Add default config.

File

./menu_block.install, line 21
Install, update and uninstall functions for the Menu Block module.

Code

function menu_block_update_8102() {
  $config_factory = \Drupal::configFactory();
  foreach ($config_factory
    ->listAll('block.block.') as $block_config_name) {
    $block = $config_factory
      ->getEditable($block_config_name);
    $settings = $block
      ->get('settings');

    // Only update system_menu_block config.
    if (strpos($settings['id'], 'system_menu_block:') === 0) {

      // Set default config for existing menu block config.
      $settings['label_link'] ?? FALSE;
      $settings['label_type'] ?? MenuBlock::LABEL_BLOCK;
      $block
        ->set('settings', $settings)
        ->save(TRUE);
    }
  }
}