Issue #3335269 by Niklan: Entity stubs doesn't follows fallback logic from entities and leads to a broken migration
parent
93f9149c8d
commit
6d4a6d6a46
|
@ -338,9 +338,10 @@ class EntityContentBase extends Entity implements HighestIdInterface, MigrateVal
|
|||
$row->setDestinationProperty($bundle_key, reset($this->bundles));
|
||||
}
|
||||
|
||||
$bundle = $row->getDestinationProperty($bundle_key) ?? $this->storage->getEntityTypeId();
|
||||
// Populate any required fields not already populated.
|
||||
$fields = $this->entityFieldManager
|
||||
->getFieldDefinitions($this->storage->getEntityTypeId(), $row->getDestinationProperty($bundle_key));
|
||||
->getFieldDefinitions($this->storage->getEntityTypeId(), $bundle);
|
||||
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,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\Core\Entity\EntityFieldManager;
|
||||
use Drupal\entity_test\Entity\EntityTestMul;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
@ -10,6 +11,7 @@ use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
|
|||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Tests\StubTestTrait;
|
||||
use Drupal\migrate_entity_test\Entity\StringIdEntityTest;
|
||||
|
||||
/**
|
||||
|
@ -19,6 +21,8 @@ use Drupal\migrate_entity_test\Entity\StringIdEntityTest;
|
|||
*/
|
||||
class MigrateEntityContentBaseTest extends KernelTestBase {
|
||||
|
||||
use StubTestTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
|
@ -304,4 +308,48 @@ class MigrateEntityContentBaseTest extends KernelTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests bundle is properly provided for stubs without bundle support.
|
||||
*
|
||||
* @todo Remove this test in when native PHP type-hints will be added for
|
||||
* EntityFieldManagerInterface::getFieldDefinitions(). See
|
||||
* https://www.drupal.org/project/drupal/issues/3050720.
|
||||
*/
|
||||
public function testBundleFallbackForStub(): void {
|
||||
$this->enableModules(['migrate_entity_test']);
|
||||
$this->installEntitySchema('migrate_string_id_entity_test');
|
||||
|
||||
$entity_type_manager = $this->container->get('entity_type.manager');
|
||||
$entity_type_bundle_info = $this->container->get('entity_type.bundle.info');
|
||||
$entity_display_repository = $this
|
||||
->container
|
||||
->get('entity_display.repository');
|
||||
$typed_data_manager = $this->container->get('typed_data_manager');
|
||||
$language_manager = $this->container->get('language_manager');
|
||||
$keyvalue = $this->container->get('keyvalue');
|
||||
$module_handler = $this->container->get('module_handler');
|
||||
$cache_discovery = $this->container->get('cache.discovery');
|
||||
$entity_last_installed_schema_repository = $this
|
||||
->container
|
||||
->get('entity.last_installed_schema.repository');
|
||||
|
||||
$decorated_entity_field_manager = new class ($entity_type_manager, $entity_type_bundle_info, $entity_display_repository, $typed_data_manager, $language_manager, $keyvalue, $module_handler, $cache_discovery, $entity_last_installed_schema_repository) extends EntityFieldManager {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldDefinitions($entity_type_id, $bundle) {
|
||||
if (\is_null($bundle)) {
|
||||
throw new \Exception("Bundle value shouldn't be NULL.");
|
||||
}
|
||||
|
||||
return parent::getFieldDefinitions($entity_type_id, $bundle);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$this->container->set('entity_field.manager', $decorated_entity_field_manager);
|
||||
$this->createEntityStub('migrate_string_id_entity_test');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue