ReinstallUserSource.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Drupal\reinstall\Plugin\migrate\source;
  3. use Drupal\migrate\Plugin\MigrationInterface;
  4. /**
  5. * Source plugin for users from a YAML file.
  6. *
  7. * @MigrateSource(
  8. * id = "reinstall_users"
  9. * )
  10. */
  11. class ReinstallUserSource extends SimpleSource {
  12. /**
  13. * Constructor.
  14. */
  15. public function __construct(
  16. array $configuration,
  17. string $pluginId,
  18. array $pluginDefinition,
  19. MigrationInterface $migration
  20. ) {
  21. parent::__construct($configuration, $pluginId, $pluginDefinition, $migration);
  22. $rawRecords = array_map([$this, 'flattenRecord'], $this->initialParse($configuration));
  23. $rawRecords = array_filter($rawRecords, [$this, 'filter01']);
  24. $this->records = $rawRecords;
  25. }
  26. /**
  27. * Skip users 0 and 1 in imports, as they are core-provided.
  28. *
  29. * @param array $record
  30. * The description of a user entity.
  31. *
  32. * @return bool
  33. * Include it (1) or filter it (0).
  34. */
  35. protected function filter01(array $record) {
  36. return ($record['uid'] ?? 0) > 1;
  37. }
  38. }