mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCEMENT Allowing to override importer instances in ModelAdmin (fixes #2982)
This commit is contained in:
parent
1f01e1135d
commit
dd517c49ba
@ -246,20 +246,25 @@ abstract class ModelAdmin extends LeftAndMain {
|
||||
* with a default {@link CsvBulkLoader} class. In this case the column names of the first row
|
||||
* in the CSV file are assumed to have direct mappings to properties on the object.
|
||||
*
|
||||
* @return array
|
||||
* @return array Map of model class names to importer instances
|
||||
*/
|
||||
function getModelImporters() {
|
||||
$importers = $this->stat('model_importers');
|
||||
$importerClasses = $this->stat('model_importers');
|
||||
|
||||
// fallback to all defined models if not explicitly defined
|
||||
if(is_null($importers)) {
|
||||
if(is_null($importerClasses)) {
|
||||
$models = $this->getManagedModels();
|
||||
foreach($models as $modelName => $options) {
|
||||
if(is_numeric($modelName)) $modelName = $options;
|
||||
$importers[$modelName] = 'CsvBulkLoader';
|
||||
$importerClasses[$modelName] = 'CsvBulkLoader';
|
||||
}
|
||||
}
|
||||
|
||||
$importers = array();
|
||||
foreach($importerClasses as $modelClass => $importerClass) {
|
||||
$importers[$modelClass] = new $importerClass($modelClass);
|
||||
}
|
||||
|
||||
return $importers;
|
||||
}
|
||||
|
||||
@ -340,8 +345,7 @@ abstract class ModelAdmin extends LeftAndMain {
|
||||
}
|
||||
|
||||
$importers = $this->getModelImporters();
|
||||
$importerClass = $importers[$this->modelClass];
|
||||
$loader = new $importerClass($this->modelClass);
|
||||
$loader = $importers[$this->modelClass];
|
||||
|
||||
// File wasn't properly uploaded, show a reminder to the user
|
||||
if(
|
||||
|
Loading…
x
Reference in New Issue
Block a user