diff --git a/core/lib/Drupal/Core/Extension/module.api.php b/core/lib/Drupal/Core/Extension/module.api.php index af77c19..3c1c228 100644 --- a/core/lib/Drupal/Core/Extension/module.api.php +++ b/core/lib/Drupal/Core/Extension/module.api.php @@ -700,21 +700,27 @@ function hook_post_update_NAME(&$sandbox) { $result = t('Node %nid saved', ['%nid' => $node->id()]); - // Example of updating an existing configuration entity. - // This example disables the frontpage view. - $view = \Drupal\views\Entity\View::load('frontpage'); - $view->setStatus(FALSE); - $view->save(); - - // Example of a usecase where some values of views plugins changes. - $view = \Drupal\views\Entity\View::load('frontpage'); - $display = &$view->getDisplay('default'); - // In this example we convert from %1 tokens to twig tokens, see - // https://www.drupal.org/node/2492839 - $display['display_options']['title'] = str_replace('%1', '{{ arguments.1 }}', $display['display_options']['title']); - $view->save(); - - $result .= t('View %view_id saved', [$view->id()]); + // Example of disabling blocks with missing condition contexts. Note: The + // block itself is in a state which is valid at that point. + // @see block_update_8001() + // @see block_post_update_disable_blocks_with_missing_contexts() + $block_update_8001 = \Drupal::keyValue('update_backup')->get('block_update_8001', []); + + $block_ids = array_keys($block_update_8001); + $block_storage = \Drupal::entityManager()->getStorage('block'); + $blocks = $block_storage->loadMultiple($block_ids); + /** @var $blocks \Drupal\block\BlockInterface[] */ + foreach ($blocks as $block) { + // This block will have an invalid context mapping service and must be + // disabled in order to prevent information disclosure. + + // Disable currently enabled blocks. + if ($block_update_8001[$block->id()]['status']) { + $block->setStatus(FALSE); + $block->save(); + } + } + return $result; }