2 * Implements hook_post_update_NAME().
4 function {{ machine_name }}_post_update_NAME(&$sandbox) {
5 // Example of updating some content.
6 $node = \Drupal\node\Entity\Node::load(123);
7 $node->setTitle('foo');
10 $result = t('Node %nid saved', ['%nid' => $node->id()]);
12 // Example of disabling blocks with missing condition contexts. Note: The
13 // block itself is in a state which is valid at that point.
14 // @see block_update_8001()
15 // @see block_post_update_disable_blocks_with_missing_contexts()
16 $block_update_8001 = \Drupal::keyValue('update_backup')->get('block_update_8001', []);
18 $block_ids = array_keys($block_update_8001);
19 $block_storage = \Drupal::entityManager()->getStorage('block');
20 $blocks = $block_storage->loadMultiple($block_ids);
21 /** @var $blocks \Drupal\block\BlockInterface[] */
22 foreach ($blocks as $block) {
23 // This block has had conditions removed due to an inability to resolve
24 // contexts in block_update_8001() so disable it.
26 // Disable currently enabled blocks.
27 if ($block_update_8001[$block->id()]['status']) {
28 $block->setStatus(FALSE);