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