ReinstallUserSource.php 1.4 KB

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