You are here

function context_update_8001 in Context 8

Same name and namespace in other branches
  1. 8.4 context.install \context_update_8001()

Update all blocks reaction configuration with additional "context_id" property.

File

./context.install, line 13
Install, update and uninstall functions for the context module.

Code

function context_update_8001() {
  foreach (Drupal::service('context.manager')
    ->getContexts() as $context) {
    foreach ($context
      ->getReactions() as $reaction) {
      if ($reaction instanceof Blocks) {
        foreach ($reaction
          ->getBlocks() as $block) {
          $config = $block
            ->getConfiguration();
          if (!isset($config['context_id'])) {
            $config['context_id'] = $context
              ->id();
            $block
              ->setConfiguration($config);
            $context
              ->save();
          }
        }
      }
    }
  }
}