Chris@0: = 8002 && !\Drupal::state()->get('block_update_8002_placeholder', FALSE)) { Chris@0: return; Chris@0: } Chris@0: Chris@0: // Cleanup the state entry as its no longer needed. Chris@0: \Drupal::state()->delete('block_update_8002'); Chris@0: Chris@0: $block_update_8001 = \Drupal::keyValue('update_backup')->get('block_update_8001', []); Chris@0: Chris@0: $block_ids = array_keys($block_update_8001); Chris@0: $block_storage = \Drupal::entityManager()->getStorage('block'); Chris@0: $blocks = $block_storage->loadMultiple($block_ids); Chris@0: /** @var $blocks \Drupal\block\BlockInterface[] */ Chris@0: foreach ($blocks as $block) { Chris@0: // This block has had conditions removed due to an inability to resolve Chris@0: // contexts in block_update_8001() so disable it. Chris@0: Chris@0: // Disable currently enabled blocks. Chris@0: if ($block_update_8001[$block->id()]['status']) { Chris@0: $block->setStatus(FALSE); Chris@0: $block->save(); Chris@0: } Chris@0: } Chris@0: Chris@0: // Provides a list of plugin labels, keyed by plugin ID. Chris@0: $condition_plugin_id_label_map = array_column(\Drupal::service('plugin.manager.condition')->getDefinitions(), 'label', 'id'); Chris@0: Chris@0: // Override with the UI labels we are aware of. Sadly they are not machine Chris@0: // accessible, see Chris@0: // \Drupal\node\Plugin\Condition\NodeType::buildConfigurationForm(). Chris@0: $condition_plugin_id_label_map['node_type'] = t('Content types'); Chris@0: $condition_plugin_id_label_map['request_path'] = t('Pages'); Chris@0: $condition_plugin_id_label_map['user_role'] = t('Roles'); Chris@0: Chris@0: if (count($block_ids) > 0) { Chris@0: $message = t('Encountered an unknown context mapping key coming probably from a contributed or custom module: One or more mappings could not be updated. Please manually review your visibility settings for the following blocks, which are disabled now:'); Chris@0: $message .= ''; Chris@0: Chris@0: return $message; Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Disable blocks that are placed into the "disabled" region. Chris@0: */ Chris@0: function block_post_update_disabled_region_update() { Chris@0: // An empty update will flush caches, forcing block_rebuild() to run. Chris@0: } Chris@0: Chris@0: /** Chris@0: * Fix invalid 'negate' values in block visibility conditions. Chris@0: */ Chris@0: function block_post_update_fix_negate_in_conditions() { Chris@0: $block_storage = \Drupal::entityTypeManager()->getStorage('block'); Chris@0: /** @var \Drupal\block\BlockInterface[] $blocks */ Chris@0: $blocks = $block_storage->loadMultiple(); Chris@0: foreach ($blocks as $block) { Chris@0: $block_needs_saving = FALSE; Chris@0: // Check each visibility condition for an invalid negate value, and fix it. Chris@0: foreach ($block->getVisibilityConditions() as $condition_id => $condition) { Chris@0: $configuration = $condition->getConfiguration(); Chris@0: if (array_key_exists('negate', $configuration) && !is_bool($configuration['negate'])) { Chris@0: $configuration['negate'] = (bool) $configuration['negate']; Chris@0: $condition->setConfiguration($configuration); Chris@0: $block_needs_saving = TRUE; Chris@0: } Chris@0: } Chris@0: if ($block_needs_saving) { Chris@0: $block->save(); Chris@0: } Chris@0: } Chris@0: }