Loading core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php +1 −1 Original line number Diff line number Diff line Loading @@ -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. Loading core/modules/migrate/tests/modules/migrate_stub_test/migrations/sample_stubbing_migration.yml +2 −0 Original line number Diff line number Diff line Loading @@ -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 Loading core/modules/migrate/tests/src/Kernel/MigrateStubTest.php +20 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\Tests\migrate\Kernel; use Drupal\field\Entity\FieldConfig; use Drupal\Tests\node\Traits\ContentTypeCreationTrait; /** Loading @@ -21,6 +22,7 @@ class MigrateStubTest extends MigrateTestBase { 'field', 'user', 'text', 'filter', 'migrate_stub_test', ]; Loading Loading @@ -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. */ Loading Loading
core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php +1 −1 Original line number Diff line number Diff line Loading @@ -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. Loading
core/modules/migrate/tests/modules/migrate_stub_test/migrations/sample_stubbing_migration.yml +2 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
core/modules/migrate/tests/src/Kernel/MigrateStubTest.php +20 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\Tests\migrate\Kernel; use Drupal\field\Entity\FieldConfig; use Drupal\Tests\node\Traits\ContentTypeCreationTrait; /** Loading @@ -21,6 +22,7 @@ class MigrateStubTest extends MigrateTestBase { 'field', 'user', 'text', 'filter', 'migrate_stub_test', ]; Loading Loading @@ -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. */ Loading