diff --git a/code/ModelAdmin.php b/code/ModelAdmin.php index bf85b5d4e..f0fe7e4ab 100644 --- a/code/ModelAdmin.php +++ b/code/ModelAdmin.php @@ -610,10 +610,10 @@ public function isManagedModel(string $modelClassOrModelTab): bool public function getModelImporters() { $importerClasses = $this->config()->get('model_importers'); + $models = $this->getManagedModels(); // fallback to all defined models if not explicitly defined if (is_null($importerClasses)) { - $models = $this->getManagedModels(); foreach ($models as $modelName => $options) { $importerClasses[$modelName] = 'SilverStripe\\Dev\\CsvBulkLoader'; } @@ -621,6 +621,9 @@ public function getModelImporters() $importers = []; foreach ($importerClasses as $modelClass => $importerClass) { + if (isset($models[$modelClass])) { + $modelClass = $models[$modelClass]['dataClass']; + } $importer = new $importerClass($modelClass); if (ClassInfo::hasMethod($importer, 'setCheckPermissions')) { $importer->setCheckPermissions(true); diff --git a/tests/php/ModelAdminTest.php b/tests/php/ModelAdminTest.php index 762469069..0d4021ce3 100644 --- a/tests/php/ModelAdminTest.php +++ b/tests/php/ModelAdminTest.php @@ -164,6 +164,15 @@ public function testGetGridField() ); } + public function testGetModelImporters() + { + $admin = new ModelAdminTest\MultiModelAdmin(); + $importers = $admin->getModelImporters(); + $this->assertCount(2, $importers); + $this->assertArrayHasKey(Contact::class, $importers); + $this->assertArrayHasKey(Player::class, $importers); + } + public function testGetManagedModels() { $admin = new ModelAdminTest\MultiModelAdmin();