Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / hook / post_update_NAME.twig
1 /**
2  * Implements hook_post_update_NAME().
3  */
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');
8   $node->save();
9
10   $result = t('Node %nid saved', ['%nid' => $node->id()]);
11
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', []);
17
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.
25
26     // Disable currently enabled blocks.
27     if ($block_update_8001[$block->id()]['status']) {
28       $block->setStatus(FALSE);
29       $block->save();
30     }
31   }
32
33   return $result;
34 }