diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityComment.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityComment.php index c7181ad..0dac82c 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityComment.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityComment.php @@ -45,13 +45,6 @@ class EntityComment extends EntityContentBase { protected $stubCommentedEntityId; /** - * The entity type used for 'commented entity' objects in stub rows. - * - * @var string - */ - protected $stubCommentedEntityType; - - /** * Builds an comment entity destination. * * @param array $configuration @@ -116,33 +109,21 @@ public function import(Row $row, array $old_destination_id_values = array()) { */ protected function getEntity(Row $row, array $old_destination_id_values) { if ($row->stub()) { + // Try to find the entity_type in 'constants/entity_type' otherwise + // fallback to 'node'. + $stub_commented_entity_type = isset($this->migration->source['constants']['entity_type']) ? $this->migration->source['constants']['entity_type'] : 'node'; + // While parent::getEntity() fills the bundle property for stub entities // if it's still empty, here we must also make sure entity_id/entity_type // are filled (so $comment->getCommentedEntity() always returns a value). if (empty($this->stubCommentedEntityId)) { - 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) { - $constant = substr($this->migration->process['entity_type'], 10); - if (!empty($this->migration->source['constants'][$constant])) { - $this->stubCommentedEntityType = $this->migration->source['constants'][$constant]; - } - } - if (empty($this->stubCommentedEntityType)) { - // We're out of luck: a dependent migration must have imported some - // entities already but we don't know which ones. The next best - // thing is to just assume at least one node exists. - $this->stubCommentedEntityType = 'node'; - } - } - // Fill stub entity id. Any id will do, as long as it exists. - $entity_type = $this->entityManager->getDefinition($this->stubCommentedEntityType); + $entity_type = $this->entityManager->getDefinition($stub_commented_entity_type); if ($id_key = $entity_type->getKey('id')) { - $result = $this->entityQuery->getAggregate($this->stubCommentedEntityType) + $result = $this->entityQuery + ->getAggregate($stub_commented_entity_type) ->aggregate($id_key, 'MIN') ->execute(); if ($result) { @@ -151,12 +132,11 @@ protected function getEntity(Row $row, array $old_destination_id_values) { } } if (empty($this->stubCommentedEntityId)) { - throw new MigrateSkipRowException(t('Could not derive commented entity for comment %id', - array('%id' => implode(':', $row->getSourceIdValues())))); + throw new MigrateSkipRowException(t('Could not derive commented entity for comment %id', array('%id' => implode(':', $row->getSourceIdValues())))); } $row->setDestinationProperty('entity_id', $this->stubCommentedEntityId); - $row->setDestinationProperty('entity_type', $this->stubCommentedEntityType); + $row->setDestinationProperty('entity_type', $stub_commented_entity_type); } return parent::getEntity($row, $old_destination_id_values);