You are here

function menu_block_post_update_add_expand_all_items_key in Menu Block 8

Add 'expand_all_items' values to menu_block.

File

./menu_block.post_update.php, line 34
Post update functions for Menu block.

Code

function menu_block_post_update_add_expand_all_items_key(&$sandbox = NULL) {

  // Check if the block module is enabled first.
  if (!\Drupal::moduleHandler()
    ->moduleExists('block')) {
    return;
  }

  // Set the default value of expand_all_items for existing menu_block configs.
  \Drupal::classResolver(ConfigEntityUpdater::class)
    ->update($sandbox, 'block', function (BlockInterface $block) {
    if (strpos($block
      ->getPluginId(), 'menu_block:') === 0) {
      $block_settings = $block
        ->get('settings');

      // Sets expand_all_items to value of expand.
      $block_settings['expand_all_items'] = (bool) $block_settings['expand'];

      // Removes expand.
      unset($block_settings['expand']);
      $block
        ->set('settings', $block_settings);
      return TRUE;
    }
    return FALSE;
  });
}