diff --git a/core/modules/block/block.services.yml b/core/modules/block/block.services.yml index fe20e4a..5674443 100644 --- a/core/modules/block/block.services.yml +++ b/core/modules/block/block.services.yml @@ -10,3 +10,8 @@ services: block.repository: class: Drupal\block\BlockRepository arguments: ['@entity.manager', '@theme.manager', '@context.handler'] + block.main_content_context: + class: Drupal\block\ContextProvider\MainContentContext + arguments: ['@current_route_match'] + tags: + - { name: 'context_provider' } diff --git a/core/modules/block/src/ContextProvider/MainContentContext.php b/core/modules/block/src/ContextProvider/MainContentContext.php new file mode 100644 index 0000000..547b812 --- /dev/null +++ b/core/modules/block/src/ContextProvider/MainContentContext.php @@ -0,0 +1,53 @@ +routeMatch = $route_match; + } + + /** + * {@inheritdoc} + */ + public function getRuntimeContexts(array $unqualified_context_ids) { + $context = new Context(new ContextDefinition('boolean'), TRUE); + $context->addCacheableDependency((new CacheableMetadata())->setCacheContexts(['route'])); + return ['main_content_context' => $context]; + } + + /** + * {@inheritdoc} + */ + public function getAvailableContexts() { + $contexts = []; + if (in_array($this->routeMatch->getRouteName(), ['block.admin_add', 'block.admin_library'])) { + $contexts['main_content_context'] = new Context(new ContextDefinition('boolean')); + } + return $contexts; + } + +} diff --git a/core/modules/system/src/Plugin/Block/SystemMainBlock.php b/core/modules/block/src/Plugin/Block/SystemMainBlock.php similarity index 78% rename from core/modules/system/src/Plugin/Block/SystemMainBlock.php rename to core/modules/block/src/Plugin/Block/SystemMainBlock.php index beba38d..6316cd8 100644 --- a/core/modules/system/src/Plugin/Block/SystemMainBlock.php +++ b/core/modules/block/src/Plugin/Block/SystemMainBlock.php @@ -1,6 +1,6 @@ array(), 'weight' => 0, ); + + // Enable the main content block to be mapped correctly. + if ($plugin_id === 'system_main_block') { + $settings['context_mapping']['main_content_context'] = '@block.main_content_context:main_content_context'; + } + $values = []; foreach (array('region', 'id', 'theme', 'plugin', 'weight', 'visibility') as $key) { $values[$key] = $settings[$key];