diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php b/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php index c9db0e7..ea7f75e 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php @@ -9,6 +9,8 @@ use Drupal\Component\Utility\String; use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\PluginBase; use Drupal\migrate\Entity\MigrationInterface; use Drupal\migrate\Exception\RequirementsException; @@ -16,6 +18,7 @@ use Drupal\migrate\Plugin\SourceEntityInterface; use Drupal\migrate_drupal\Plugin\MigrateLoadInterface; use Drupal\migrate_drupal\Plugin\CckFieldMigrateSourceInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Base class for entity load plugins. @@ -24,7 +27,7 @@ * * @PluginID("drupal_entity") */ -class LoadEntity extends PluginBase implements MigrateLoadInterface { +class LoadEntity extends PluginBase implements MigrateLoadInterface, ContainerFactoryPluginInterface { /** * The list of bundles being loaded. @@ -34,11 +37,28 @@ class LoadEntity extends PluginBase implements MigrateLoadInterface { protected $bundles; /** + * The module handler. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler + */ + protected $moduleHandler; + + /** + * The migration storage handler. + * + * @var \Drupal\Core\Entity\EntityStorageInterface $migrationStorage + */ + protected $migrationStorage; + + /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, MigrationInterface $migration) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, MigrationInterface $migration, ModuleHandlerInterface $module_handler, EntityStorageInterface $migration_storage) { parent::__construct($configuration, $plugin_id, $plugin_definition, $migration); $this->migration = $migration; + $this->moduleHandler = $module_handler; + $this->migrationStorage = $migration_storage; + $source_plugin = $this->migration->getSourcePlugin(); if (!$source_plugin instanceof SourceEntityInterface) { throw new MigrateException('Migrations with a load plugin using LoadEntity should have an entity as source.'); @@ -51,6 +71,20 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi /** * {@inheritdoc} */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $migration, + $container->get('module_handler'), + $container->get('entity.manager')->getStorage('migration') + ); + } + + /** + * {@inheritdoc} + */ public function load(EntityStorageInterface $storage, $sub_id) { $entities = $this->loadMultiple($storage, array($sub_id)); return isset($entities[$sub_id]) ? $entities[$sub_id] : FALSE; @@ -114,7 +148,7 @@ public function loadMultiple(EntityStorageInterface $storage, array $sub_ids = N } } - + $this->postLoad($migrations); return $migrations; } @@ -205,4 +239,26 @@ protected function processLinkField($field_name, $field_data, MigrationInterface $migration->setProcess($process); } + /** + * Attaches data to entities upon loading. + * + * @param array $entities + * Associative array of query results, keyed on the entity ID. + */ + protected function postLoad(array &$entities) { + $this->migration->postLoad($this->migrationStorage, $entities); + $entity_type_id = 'migration'; + + // Call hook_entity_load(). + foreach ($this->moduleHandler->getImplementations('entity_load') as $module) { + $function = $module . '_entity_load'; + $function($entities, $entity_type_id); + } + // Call hook_TYPE_load(). + foreach ($this->moduleHandler->getImplementations($entity_type_id . '_load') as $module) { + $function = $module . '_' . $entity_type_id . '_load'; + $function($entities); + } + } + } diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/load/d6/LoadTermNode.php b/core/modules/migrate_drupal/src/Plugin/migrate/load/d6/LoadTermNode.php index e5b3f5e..ef900ef 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/load/d6/LoadTermNode.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/load/d6/LoadTermNode.php @@ -13,6 +13,7 @@ use Drupal\migrate\MigrateMessage; use Drupal\migrate\Row; use Drupal\migrate_drupal\Plugin\migrate\load\LoadEntity; +use Drupal\Core\Extension\ModuleHandlerInterface; /** * @PluginID("d6_term_node") @@ -22,9 +23,9 @@ class LoadTermNode extends LoadEntity { /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, MigrationInterface $migration) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, MigrationInterface $migration, ModuleHandlerInterface $module_handler, EntityStorageInterface $migration_storage) { $configuration['bundle_migration'] = 'd6_taxonomy_vocabulary'; - parent::__construct($configuration, $plugin_id, $plugin_definition, $migration); + parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $module_handler, $migration_storage); } /**