Issue #2954982 by Matroskeen, abramm, Rob230: Incorrect bundle/bundle key handling in EntityContentBase::processStubRow()

merge-requests/4973/head
Alex Pott 2021-02-10 09:31:10 +00:00
parent c4d6699d96
commit 9d96600683
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
3 changed files with 23 additions and 1 deletions

View File

@ -311,7 +311,7 @@ class EntityContentBase extends Entity implements HighestIdInterface, MigrateVal
// 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.

View File

@ -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

View File

@ -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 @@ class MigrateStubTest extends MigrateTestBase {
$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.
*/