|
@@ -8,6 +8,8 @@ use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
|
|
|
use Drupal\migrate\Plugin\MigrationInterface;
|
|
|
use Drupal\migrate\Row;
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|
|
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
|
|
use Symfony\Component\Yaml\Exception\ParseException;
|
|
|
use Symfony\Component\Yaml\Yaml;
|
|
|
|
|
@@ -18,11 +20,32 @@ abstract class SimpleSource extends SourcePluginBase implements ContainerFactory
|
|
|
use SimpleSourceTrait;
|
|
|
|
|
|
|
|
|
- * The source records. MUST be initialized in concrete classes __construct().
|
|
|
+ * The event_dispatcher service.
|
|
|
+ *
|
|
|
+ * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
|
|
|
+ */
|
|
|
+ protected $eventDispatcher;
|
|
|
+
|
|
|
+
|
|
|
+ * The source records.
|
|
|
+ *
|
|
|
+ * MAY be altered by subscribing to MigrateEvents::PRE_IMPORT.
|
|
|
*
|
|
|
* @var array
|
|
|
*/
|
|
|
- protected $records;
|
|
|
+ public $records;
|
|
|
+
|
|
|
+ public function __construct(
|
|
|
+ array $configuration,
|
|
|
+ $plugin_id,
|
|
|
+ $plugin_definition,
|
|
|
+ \Drupal\migrate\Plugin\MigrationInterface $migration,
|
|
|
+ EventDispatcherInterface $eventDispatcher
|
|
|
+ ) {
|
|
|
+ parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
|
|
|
+ $this->eventDispatcher = $eventDispatcher;
|
|
|
+ $this->records = array_map([$this, 'flattenRecord'], $this->initialParse($configuration));
|
|
|
+ }
|
|
|
|
|
|
|
|
|
* {@inheritdoc}
|
|
@@ -36,7 +59,8 @@ abstract class SimpleSource extends SourcePluginBase implements ContainerFactory
|
|
|
) {
|
|
|
$importPath = $container->getParameter('reinstall.path');
|
|
|
$configuration['importPath'] = $importPath;
|
|
|
- return new static($configuration, $pluginId, $pluginDefinition, $migration);
|
|
|
+ $dispatcher = $container->get('event_dispatcher');
|
|
|
+ return new static($configuration, $pluginId, $pluginDefinition, $migration, $dispatcher);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -111,7 +135,10 @@ abstract class SimpleSource extends SourcePluginBase implements ContainerFactory
|
|
|
* {@inheritdoc}
|
|
|
*/
|
|
|
protected function initializeIterator() {
|
|
|
- return new \ArrayIterator($this->records);
|
|
|
+ if (!isset($this->iterator)) {
|
|
|
+ $this->iterator = new \ArrayIterator($this->records);
|
|
|
+ }
|
|
|
+ return $this->iterator;
|
|
|
}
|
|
|
|
|
|
|