diff --git a/core/config/schema/core.data_types.schema.yml b/core/config/schema/core.data_types.schema.yml index 5b0b0fa..e0ba242 100644 --- a/core/config/schema/core.data_types.schema.yml +++ b/core/config/schema/core.data_types.schema.yml @@ -314,6 +314,11 @@ block_settings: provider: type: string label: 'Provider' + context_mapping: + type: sequence + label: 'Context assignments' + sequence: + type: string condition.plugin: type: mapping diff --git a/core/lib/Drupal/Core/Block/BlockBase.php b/core/lib/Drupal/Core/Block/BlockBase.php index 8a7fbfa..930d8ab 100644 --- a/core/lib/Drupal/Core/Block/BlockBase.php +++ b/core/lib/Drupal/Core/Block/BlockBase.php @@ -201,7 +201,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#options' => $period, ); - // Add context form elements. + // Add context mapping UI form elements. $contexts = $form_state->getTemporaryValue('gathered_contexts') ?: []; $form['context_mapping'] = $this->addContextAssignmentElement($this, $contexts); // Add plugin-specific settings for this block type. diff --git a/core/lib/Drupal/Core/Plugin/ContextAwarePluginAssignmentTrait.php b/core/lib/Drupal/Core/Plugin/ContextAwarePluginAssignmentTrait.php index e3ae261..c2d2dd8 100644 --- a/core/lib/Drupal/Core/Plugin/ContextAwarePluginAssignmentTrait.php +++ b/core/lib/Drupal/Core/Plugin/ContextAwarePluginAssignmentTrait.php @@ -65,7 +65,7 @@ protected function addContextAssignmentElement(ContextAwarePluginInterface $plug $assignments = $plugin->getContextMapping(); $element[$context_slot] = [ - '#title' => $definition->getLabel() ?: $context_slot, + '#title' => $definition->getLabel() ?: $this->t('Select a @context value:', ['@context' => $context_slot]), '#type' => 'select', '#options' => $options, '#required' => $definition->isRequired(), diff --git a/core/modules/block/block.services.yml b/core/modules/block/block.services.yml index ff4277d..5b6e521 100644 --- a/core/modules/block/block.services.yml +++ b/core/modules/block/block.services.yml @@ -9,4 +9,4 @@ services: - { name: event_subscriber } block.repository: class: Drupal\block\BlockRepository - arguments: ['@entity.manager', '@theme.manager', '@context.handler', '@context.repository'] + arguments: ['@entity.manager', '@theme.manager'] diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php index e8035f4..605cf40 100644 --- a/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -336,6 +336,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // Call the plugin submit handler. $block = $entity->getPlugin(); $block->submitConfigurationForm($form, $settings); + // If this block is context-aware, set the context mapping. if ($block instanceof ContextAwarePluginInterface && $block->getContextDefinitions()) { $context_mapping = $settings->getValue('context_mapping', []); $block->setContextMapping($context_mapping); diff --git a/core/modules/block/src/BlockRepository.php b/core/modules/block/src/BlockRepository.php index e9a5eb0..103557b 100644 --- a/core/modules/block/src/BlockRepository.php +++ b/core/modules/block/src/BlockRepository.php @@ -9,9 +9,6 @@ use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Plugin\Context\ContextHandlerInterface; -use Drupal\Core\Plugin\Context\ContextRepositoryInterface; -use Drupal\Core\Plugin\ContextAwarePluginInterface; use Drupal\Core\Theme\ThemeManagerInterface; /** @@ -34,36 +31,16 @@ class BlockRepository implements BlockRepositoryInterface { protected $themeManager; /** - * The context repository. - * - * @var \Drupal\Core\Plugin\Context\ContextRepositoryInterface - */ - protected $contextRepository; - - /** - * The context handler. - * - * @var \Drupal\Core\Plugin\Context\ContextHandlerInterface - */ - protected $contextHandler; - - /** * Constructs a new BlockRepository. * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. * @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager * The theme manager. - * @param \Drupal\Core\Plugin\Context\ContextHandlerInterface $context_handler - * The plugin context handler. - * @param \Drupal\Core\Plugin\Context\ContextRepositoryInterface $context_repository - * The context repository */ - public function __construct(EntityManagerInterface $entity_manager, ThemeManagerInterface $theme_manager, ContextHandlerInterface $context_handler, ContextRepositoryInterface $context_repository) { + public function __construct(EntityManagerInterface $entity_manager, ThemeManagerInterface $theme_manager) { $this->blockStorage = $entity_manager->getStorage('block'); $this->themeManager = $theme_manager; - $this->contextHandler = $context_handler; - $this->contextRepository = $context_repository; } /** @@ -77,7 +54,6 @@ public function getVisibleBlocksPerRegion(array &$cacheable_metadata = []) { $full = array(); foreach ($this->blockStorage->loadByProperties(array('theme' => $active_theme->getName())) as $block_id => $block) { /** @var \Drupal\block\BlockInterface $block */ - $access = $block->access('view', NULL, TRUE); $region = $block->getRegion(); if (!isset($cacheable_metadata[$region])) { diff --git a/core/modules/block/src/Tests/BlockUiTest.php b/core/modules/block/src/Tests/BlockUiTest.php index 47fea2e..2206158 100644 --- a/core/modules/block/src/Tests/BlockUiTest.php +++ b/core/modules/block/src/Tests/BlockUiTest.php @@ -169,10 +169,16 @@ public function testCandidateBlockList() { * Tests the behavior of context-aware blocks. */ public function testContextAwareBlocks() { + $expected_text = '