- Issue created by @Peacog
- @peacog opened merge request.
- Status changed to Needs review
5 months ago 3:20pm 14 June 2024 - 🇪🇸Spain Peacog
Here's an example of the custom pre-import event that uses the service in this patch.
<?php namespace Drupal\my_custom_migrate\EventSubscriber; use Drupal\migrate\Event\MigrateImportEvent; use Drupal\migrate_file_to_media\Services\DuplicateDetectionService; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Drupal\migrate\Event\MigrateEvents; /** * Custom migrate event subscriber. */ class MyCustomMigrateSubscriber implements EventSubscriberInterface { /** * The duplicate file detection service. * * @var \Drupal\migrate_file_to_media\Services\DuplicateDetectionService */ protected DuplicateDetectionService $duplicateDetectionService; /** * Constructs a MyCustomMigrateSubscriber object. * * @param \Drupal\migrate_file_to_media\Services\DuplicateDetectionService $duplicateDetectionService * The search links service. */ public function __construct(DuplicateDetectionService $duplicateDetectionService) { $this->duplicateDetectionService = $duplicateDetectionService; } /** * Run migrate:duplicate-file-detection before migrate_file_to_media * migrations. ** * @param \Drupal\migrate\Event\MigrateImportEvent $event * Response event. */ public function onPreImport(MigrateImportEvent $event) { $config = $event->getMigration()->getPluginDefinition(); if (($config['source']['plugin'] ?? '') !== 'media_entity_generator_d7') { return; } // Run the migrate:duplicate-file-detection command for the migration. $this->duplicateDetectionService->duplicateFileDetection($config['id'], [FALSE, TRUE]); } /** * {@inheritdoc} */ public static function getSubscribedEvents() { return [ MigrateEvents::PRE_IMPORT => ['onPreImport'], ]; } }