context.install 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * Update all blocks reaction configuration with additional "context_id" property.
  4. */
  5. function context_update_8001() {
  6. foreach (Drupal::service('context.manager')->getContexts() as $context) {
  7. foreach ($context->getReactions() as $reaction) {
  8. if ($reaction instanceof Drupal\context\Plugin\ContextReaction\Blocks) {
  9. foreach ($reaction->getBlocks() as $block) {
  10. $config = $block->getConfiguration();
  11. if (!isset($config['context_id'])) {
  12. $config['context_id'] = $context->id();
  13. $block->setConfiguration($config);
  14. $context->save();
  15. }
  16. }
  17. }
  18. }
  19. }
  20. }
  21. /**
  22. * Update all blocks reaction configuration with additional "css_class" property.
  23. */
  24. function context_update_8002() {
  25. $context_manager = \Drupal::service('context.manager');
  26. foreach ($context_manager->getContexts() as $context) {
  27. foreach ($context->getReactions() as $reaction) {
  28. if ($reaction instanceof \Drupal\context\Plugin\ContextReaction\Blocks) {
  29. foreach ($reaction->getBlocks() as $block) {
  30. $configuration = $block->getConfiguration();
  31. if (!isset($configuration['css_class'])) {
  32. $configuration['css_class'] = '';
  33. // Update the block.
  34. $reaction->updateBlock($configuration['uuid'], $configuration);
  35. $context->save();
  36. }
  37. }
  38. }
  39. }
  40. }
  41. }