- πΊπΈUnited States joewhitsitt Iowa
Our group invested in a solution for this, but because we think it goes against the nature of what this module is doing, we didn't write a patch for this module. In our situation, our customer had a jobs feed in addition to news feeds. Unlike storing a aggregate of news items, the customer wanted the expired job postings to no longer display.
Instead we created a boolean "purge items" field on the aggregator feed entity (admin/config/services/aggregator/fields) and then used a service decorator to plug into the aggregator.items.importer service. That way each feed source can be configured to use this feature or not.
Using a service decorator, hopefully the code footprint is smaller and we don't have to recreate the rest of what the importer is doing. Hope this can be of help to others.
in mymodule.services.yml:
mymodule.custom_items_import: class: Drupal\mymodule\ItemsImporterOverride decorates: aggregator.items.importer decoration_priority: 9 public: false arguments: ['@mymodule.custom_items_import.inner', '@config.factory', '@plugin.manager.aggregator.fetcher', '@plugin.manager.aggregator.parser', '@plugin.manager.aggregator.processor', '@logger.channel.aggregator', '@keyvalue.aggregator']
in mymodule/src/ItemsImporterOverride:
<?php namespace Drupal\mymodule; use Drupal\aggregator\FeedInterface; use Drupal\aggregator\ItemsImporter; use Drupal\aggregator\Plugin\AggregatorPluginManager; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\KeyValueStore\KeyValueFactoryInterface; use Psr\Log\LoggerInterface; /** * Modify the Aggregator ItemsImporter with a custom refresh. */ class ItemsImporterOverride extends ItemsImporter { /** * Original service object. * * @var \Drupal\aggregator\ItemsImporter */ protected $itemsImporter; /** * {@inheritdoc} */ public function __construct( ItemsImporter $itemsImporter, ConfigFactoryInterface $configFactory, AggregatorPluginManager $fetcherManager, AggregatorPluginManager $parserManager, AggregatorPluginManager $processorManager, LoggerInterface $logger, KeyValueFactoryInterface $keyValue, ) { $this->itemsImporter = $itemsImporter; parent::__construct($configFactory, $fetcherManager, $parserManager, $processorManager, $logger, $keyValue); } /** * {@inheritdoc} */ public function refresh(FeedInterface $feed) { $purgeItems = $feed->get('field_aggregator_purge_items')?->value; if ($purgeItems) { $feed->deleteItems(); } parent::refresh($feed); } }