diff --git a/core/modules/migrate/src/Plugin/migrate/destination/Entity.php b/core/modules/migrate/src/Plugin/migrate/destination/Entity.php index ddba1c0..abf2dc9 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/Entity.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/Entity.php @@ -89,20 +89,18 @@ protected static function getEntityTypeId($plugin_id) { } /** - * Set the default entity bundle from configuration. + * Gets the bundle for the row taking into account the default. * * @param \Drupal\migrate\Row $row - * The row object. + * The current row we're importing. + * + * @return string + * The bundle for this row. */ - protected function getBundle(Row $row) { + public function getBundle(Row $row) { $default_bundle = isset($this->configuration['default_bundle']) ? $this->configuration['default_bundle'] : ''; - if ($default_bundle) { - $bundle_key = $this->getKey('bundle'); - // Apply the default bundle if the bundle has not already been set. - if (empty($row->getDestinationProperty($bundle_key))) { - $row->setDestinationProperty($bundle_key, $default_bundle); - } - } + $bundle_key = $this->getKey('bundle'); + return $row->getDestinationProperty($bundle_key) ?: $default_bundle; } /** @@ -129,7 +127,10 @@ protected function getEntity(Row $row, array $old_destination_id_values) { $this->updateEntity($entity, $row); } else { - $this->getBundle($row); + // Attempt to ensure we always have a bundle. + if ($bundle = $this->getBundle($row)) { + $row->setDestinationProperty($this->getKey('bundle'), $bundle); + } // Stubs might need some required fields filled in. if ($row->isStub()) {