diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityComment.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityComment.php index b0e82c8..52c8c45 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityComment.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityComment.php @@ -11,7 +11,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\State\StateInterface; use Drupal\migrate\Entity\MigrationInterface; -use Drupal\migrate\Plugin\MigratePluginManager; +use Drupal\Core\Entity\Query\QueryInterface; use Drupal\migrate\MigrateSkipRowException; use Drupal\migrate\Row; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -31,6 +31,13 @@ class EntityComment extends EntityContentBase { protected $state; /** + * The entity query object. + * + * @var \Drupal\Core\Entity\Query\QueryInterface + */ + protected $entityQuery; + + /** * The entity ID used for 'commented entity' objects in stub rows. * * @var string @@ -59,16 +66,17 @@ class EntityComment extends EntityContentBase { * The storage for this entity type. * @param array $bundles * The list of bundles this entity type has. - * @param \Drupal\migrate\Plugin\MigratePluginManager $plugin_manager - * The migrate plugin manager. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager service. * @param \Drupal\Core\State\StateInterface $state * The state storage object. + * @param \Drupal\Core\Entity\Query\QueryInterface $entity_query + * The query object that can query the given entity type. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, StateInterface $state) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, StateInterface $state, QueryInterface $entity_query) { parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_manager); $this->state = $state; + $this->entityQuery = $entity_query; } /** @@ -84,7 +92,8 @@ public static function create(ContainerInterface $container, array $configuratio $container->get('entity.manager')->getStorage($entity_type), array_keys($container->get('entity.manager')->getBundleInfo($entity_type)), $container->get('entity.manager'), - $container->get('state') + $container->get('state'), + $container->get('entity.query') ); } @@ -115,14 +124,10 @@ protected function getEntity(Row $row, array $old_destination_id_values) { if (empty($this->stubCommentedEntityType)) { // Usually the migration will have defined entity_type as a constant, // in which case we can get the value: - if (isset($this->migration->process['entity_type']) - && is_string($this->migration->process['entity_type']) - && strpos($this->migration->process['entity_type'], 'constants/') - == 0) { + if (isset($this->migration->process['entity_type']) && is_string($this->migration->process['entity_type']) && strpos($this->migration->process['entity_type'], 'constants/') === 0) { $constant = substr($this->migration->process['entity_type'], 10); if (!empty($this->migration->source['constants'][$constant])) { - $this->stubCommentedEntityType = - $this->migration->source['constants'][$constant]; + $this->stubCommentedEntityType = $this->migration->source['constants'][$constant]; } } if (empty($this->stubCommentedEntityType)) { @@ -137,7 +142,7 @@ protected function getEntity(Row $row, array $old_destination_id_values) { $entity_type = $this->entityManager->getDefinition($this->stubCommentedEntityType); if ($id_key = $entity_type->getKey('id')) { - $result = \Drupal::entityQueryAggregate($this->stubCommentedEntityType) + $result = $this->entityQuery->getAggregate($this->stubCommentedEntityType) ->aggregate($id_key, 'MIN') ->execute(); if ($result) {