You are here

function context_update_8002 in Context 8

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

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

File

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

Code

function context_update_8002() {
  $context_manager = \Drupal::service('context.manager');
  foreach ($context_manager
    ->getContexts() as $context) {
    foreach ($context
      ->getReactions() as $reaction) {
      if ($reaction instanceof \Drupal\context\Plugin\ContextReaction\Blocks) {
        foreach ($reaction
          ->getBlocks() as $block) {
          $configuration = $block
            ->getConfiguration();
          if (!isset($configuration['css_class'])) {
            $configuration['css_class'] = '';

            // Update the block.
            $reaction
              ->updateBlock($configuration['uuid'], $configuration);
            $context
              ->save();
          }
        }
      }
    }
  }
}