Unverified Commit 9d966006 authored by Alex Pott's avatar Alex Pott
Browse files

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
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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.
+2 −0
Original line number Diff line number Diff line
@@ -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
+20 −0
Original line number Diff line number Diff line
@@ -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.
   */