Skip to content

Commit

Permalink
Merge branch '1.13' into 1
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Feb 3, 2024
2 parents 6749a84 + 725a9a1 commit c998e1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion code/ModelAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,17 +610,20 @@ 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';
}
}

$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);
Expand Down
9 changes: 9 additions & 0 deletions tests/php/ModelAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c998e1a

Please sign in to comment.