diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 2f0bd68..5e1443d 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1170,12 +1170,13 @@ function system_schema() { * Place local actions and tasks blocks in every theme. */ function system_update_8001() { - // Nothing to do if block module is not installed. + // When block module is not installed, there is nothing that could be done + // except showing a warning. if (!\Drupal::moduleHandler()->moduleExists('block')) { return t('Block module is not enabled so local actions and tasks which have been converted to blocks, are not visible anymore.'); } $config_factory = \Drupal::configFactory(); - /** @var \Drupal\Core\Extension\ThemeHandler $theme_handler */ + /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */ $theme_handler = \Drupal::service('theme_handler'); /** @var \Drupal\Core\Config\StorageInterface $config_storage */ $config_storage = \Drupal::service('config.storage'); @@ -1204,7 +1205,6 @@ function system_update_8001() { 'max_age' => 0, ], ]; - /** @var \Drupal\Core\Extension\Extension $theme */ foreach ($theme_handler->listInfo() as $theme) { $theme_name = $theme->getName(); $block_storage = \Drupal::entityManager()->getStorage('block'); @@ -1229,15 +1229,25 @@ function system_update_8001() { // Help region has been removed so all the blocks inside has to be moved // to content region. - /* @var \Drupal\block\BlockInterface[] $help_blocks */ - $help_blocks = $block_storage->loadByProperties(['theme' => 'bartik', 'region' => 'help']); - uasort($help_blocks, array('Drupal\Component\Utility\SortArray', 'sortByWeightProperty')); $weight = -6; - foreach ($help_blocks as $block) { - $block_config = $config_factory->getEditable('block.block.' . $block->getConfigTarget()); - $block_config->set('region', 'content'); - $block_config->set('weight', $weight); - $block_config->save(); + $blocks = []; + foreach ($config_factory->listAll('block.block.') as $block_config) { + $block = $config_factory->getEditable($block_config); + if ($block->get('theme') == 'bartik' && $block->get('region') == 'help') { + $blocks[] = $block; + } + } + // Sort blocks by block weight. + uasort($blocks, function ($a, $b) { + $weight = $a->get('weight') - $b->get('weight'); + return $weight; + }); + // Move blocks to content region and set them in right order by their + // weight. + foreach ($blocks as $block) { + $block->set('region', 'content'); + $block->set('weight', $weight); + $block->save(); $weight++; } break;