diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php index 65d6ae9ba1f982f21a45e3405731c948b5de0757..ba8eae2b723ab5b3092426afbc96658523da71f1 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php @@ -311,7 +311,7 @@ protected function processStubRow(Row $row) { // Populate any required fields not already populated. $fields = $this->entityFieldManager - ->getFieldDefinitions($this->storage->getEntityTypeId(), $bundle_key); + ->getFieldDefinitions($this->storage->getEntityTypeId(), $row->getDestinationProperty($bundle_key)); foreach ($fields as $field_name => $field_definition) { if ($field_definition->isRequired() && is_null($row->getDestinationProperty($field_name))) { // Use the configured default value for this specific field, if any. diff --git a/core/modules/migrate/tests/modules/migrate_stub_test/migrations/sample_stubbing_migration.yml b/core/modules/migrate/tests/modules/migrate_stub_test/migrations/sample_stubbing_migration.yml index 8d86ee435c0569f5e644c0eab248411eeb75cb52..f3e693ba3db9fe7a9e2a384f82e2255f597d36fe 100644 --- a/core/modules/migrate/tests/modules/migrate_stub_test/migrations/sample_stubbing_migration.yml +++ b/core/modules/migrate/tests/modules/migrate_stub_test/migrations/sample_stubbing_migration.yml @@ -11,6 +11,8 @@ source: title: "Sample 2" bodyvalue: "This is the body for ID 25" bodyformat: "plain_text" + - id: 33 + title: "Sample 3" ids: id: type: integer diff --git a/core/modules/migrate/tests/src/Kernel/MigrateStubTest.php b/core/modules/migrate/tests/src/Kernel/MigrateStubTest.php index 817e54ba5be4ea6685ccf3c415da57c3f5f7e5cf..da494ed53e4a442c324a07617442bf5c03927ff6 100644 --- a/core/modules/migrate/tests/src/Kernel/MigrateStubTest.php +++ b/core/modules/migrate/tests/src/Kernel/MigrateStubTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\migrate\Kernel; +use Drupal\field\Entity\FieldConfig; use Drupal\Tests\node\Traits\ContentTypeCreationTrait; /** @@ -21,6 +22,7 @@ class MigrateStubTest extends MigrateTestBase { 'field', 'user', 'text', + 'filter', 'migrate_stub_test', ]; @@ -99,6 +101,24 @@ public function testStubWithDefaultValues() { $this->assertSame("Sample 1", $node->label()); } + /** + * Tests stub creation with bundle fields. + */ + public function testStubWithBundleFields() { + $this->createContentType(['type' => 'node_stub']); + // Make "Body" field required to make stubbing populate field value. + $body_field = FieldConfig::loadByName('node', 'node_stub', 'body'); + $body_field->setRequired(TRUE)->save(); + + $this->assertSame([], $this->migrateLookup->lookup('sample_stubbing_migration', [33])); + $ids = $this->migrateStub->createStub('sample_stubbing_migration', [33], []); + $this->assertSame([$ids], $this->migrateLookup->lookup('sample_stubbing_migration', [33])); + $node = \Drupal::entityTypeManager()->getStorage('node')->load($ids['nid']); + $this->assertNotNull($node); + // Make sure the "Body" field value was populated. + $this->assertNotEmpty($node->get('body')->value); + } + /** * Test invalid source id count. */