diff --git a/core/modules/aggregator/config/schema/aggregator.schema.yml b/core/modules/aggregator/config/schema/aggregator.schema.yml index 0ebe25b..7b31e16 100644 --- a/core/modules/aggregator/config/schema/aggregator.schema.yml +++ b/core/modules/aggregator/config/schema/aggregator.schema.yml @@ -51,7 +51,7 @@ block.settings.aggregator_feed_block: # This will be stored in the format of 'aggregator.feed:$uuid'. feed: type: string - label: 'Feed + label: 'Feed' field.formatter.settings.aggregator_title: type: mapping diff --git a/core/modules/aggregator/src/AggregatorServiceProvider.php b/core/modules/aggregator/src/AggregatorServiceProvider.php deleted file mode 100644 index e61d7bf..0000000 --- a/core/modules/aggregator/src/AggregatorServiceProvider.php +++ /dev/null @@ -1,33 +0,0 @@ -getParameter('container.modules'); - if (isset($modules['block'])) { - $container->register('block.aggregator_feed_context', 'Drupal\aggregator\EventSubscriber\AggregatorFeedContext') - ->addArgument(new Reference('entity.manager')) - ->addArgument(new Reference('theme.manager')) - ->addTag('event_subscriber'); - } - } - -} diff --git a/core/modules/aggregator/src/EventSubscriber/AggregatorFeedContext.php b/core/modules/aggregator/src/EventSubscriber/AggregatorFeedContext.php index 5a884e8..5dfcd58 100644 --- a/core/modules/aggregator/src/EventSubscriber/AggregatorFeedContext.php +++ b/core/modules/aggregator/src/EventSubscriber/AggregatorFeedContext.php @@ -7,18 +7,16 @@ namespace Drupal\aggregator\EventSubscriber; -use Drupal\block\Event\BlockContextEvent; -use Drupal\block\EventSubscriber\BlockContextSubscriberBase; -use Drupal\Component\Plugin\ContextAwarePluginInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Plugin\Context\Context; use Drupal\Core\Plugin\Context\ContextDefinition; +use Drupal\Core\Plugin\Context\ContextProviderInterface; use Drupal\Core\Theme\ThemeManagerInterface; /** * Provides aggregator feeds as context. */ -class AggregatorFeedContext extends BlockContextSubscriberBase { +class AggregatorFeedContext implements ContextProviderInterface { /** * The entity storage for feeds. @@ -28,13 +26,6 @@ class AggregatorFeedContext extends BlockContextSubscriberBase { protected $feedStorage; /** - * The block storage. - * - * @var \Drupal\Core\Entity\EntityStorageInterface - */ - protected $blockStorage; - - /** * The theme manager. * * @var \Drupal\Core\Theme\ThemeManagerInterface @@ -51,41 +42,37 @@ class AggregatorFeedContext extends BlockContextSubscriberBase { */ public function __construct(EntityManagerInterface $entity_manager, ThemeManagerInterface $theme_manager) { $this->feedStorage = $entity_manager->getStorage('aggregator_feed'); - $this->blockStorage = $entity_manager->getStorage('block'); $this->themeManager = $theme_manager; } /** * {@inheritdoc} */ - public function onBlockActiveContext(BlockContextEvent $event) { - foreach ($this->blockStorage->loadByProperties(['plugin' => 'aggregator_feed_block', 'theme' => $this->themeManager->getActiveTheme()->getName()]) as $block_id => $block) { - /** @var $block \Drupal\block\Entity\Block */ - $block_plugin = $block->getPlugin(); - if ($block_plugin instanceof ContextAwarePluginInterface) { - $contexts = $block_plugin->getContextMapping(); - // The context mapping is stored as aggregator.feed:uuid, so we're just - // extracting the UUID so that we can load the specific feed object. - list(, $uuid) = explode(':', $contexts['feed'], 2); - $feeds = $this->feedStorage->loadByProperties(['uuid' => $uuid]); - $feed = reset($feeds); - $context = new Context(new ContextDefinition('entity:aggregator_feed')); - $context->setContextValue($feed); - $event->setContext('aggregator.feed:' . $feed->uuid(), $context); - } + public function getRuntimeContexts(array $unqualified_context_ids) { + $ids = $this->feedStorage->getQuery() + ->condition('uuid', $unqualified_context_ids, 'IN') + ->execute(); + $contexts = []; + foreach ($this->feedStorage->loadMultiple($ids) as $feed) { + $context = new Context(new ContextDefinition('entity:aggregator_feed')); + $context->setContextValue($feed); + $contexts[$feed->uuid()] = $context; } + return $contexts; } /** * {@inheritdoc} */ - public function onBlockAdministrativeContext(BlockContextEvent $event) { + public function getAvailableContexts() { $feeds = $this->feedStorage->loadMultiple(); + $contexts = []; foreach ($feeds as $feed) { $context = new Context(new ContextDefinition('entity:aggregator_feed', $feed->label())); $context->setContextValue($feed); - $event->setContext('aggregator.feed:' . $feed->uuid(), $context); + $contexts[$feed->uuid()] = $context; } + return $contexts; } } diff --git a/core/modules/block/block.services.yml b/core/modules/block/block.services.yml index fe20e4a..a9f485b 100644 --- a/core/modules/block/block.services.yml +++ b/core/modules/block/block.services.yml @@ -9,4 +9,9 @@ services: - { name: event_subscriber } block.repository: class: Drupal\block\BlockRepository - arguments: ['@entity.manager', '@theme.manager', '@context.handler'] + arguments: ['@entity.manager', '@theme.manager', '@context.handler', '@context.repository'] + block.aggregator_feed_context: + class: Drupal\aggregator\EventSubscriber\AggregatorFeedContext + arguments: ['@entity.manager', '@theme.manager'] + tags: + - { name: context_provider }