Unverified Commit 9d966006 authored by alexpott's avatar alexpott

Issue #2954982 by Matroskeen, abramm, Rob230: Incorrect bundle/bundle key...

Issue #2954982 by Matroskeen, abramm, Rob230: Incorrect bundle/bundle key handling in EntityContentBase::processStubRow()
parent c4d6699d
......@@ -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.
......
......@@ -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
......
......@@ -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.
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment