UserPreImport.php 994 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace Drupal\reinstall\EventSubscriber;
  3. use Drupal\migrate\Event\MigrateEvents;
  4. use Drupal\migrate\Event\MigrateImportEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class UserPreImport implements EventSubscriberInterface {
  7. public static function getSubscribedEvents() {
  8. return [
  9. MigrateEvents::PRE_IMPORT => 'onPreImport',
  10. ];
  11. }
  12. public function onPreImport(MigrateImportEvent $event) {
  13. /** @var \Drupal\reinstall\Plugin\migrate\source\ReinstallUserSource $plugin */
  14. $plugin = $event->getMigration()->getSourcePlugin();
  15. $plugin->records = array_filter($plugin->records, [$this, 'filter01']);
  16. return;
  17. }
  18. /**
  19. * Skip users 0 and 1 in imports, as they are core-provided.
  20. *
  21. * @param array $record
  22. * The description of a user entity.
  23. *
  24. * @return bool
  25. * Include it (1) or filter it (0).
  26. */
  27. public function filter01(array $record) {
  28. $ret = ($record['uid'] ?? 0) > 1;
  29. return $ret;
  30. }
  31. }