Permalink
Browse files

ENHANCEMENT Allowing to override importer instances in ModelAdmin (fi…

…xes #2982)
  • Loading branch information...
1 parent 1f01e11 commit dd517c49baa474354a99f6d850a67e169d224c3d @chillu chillu committed Mar 9, 2012
Showing with 10 additions and 6 deletions.
  1. +10 −6 admin/code/ModelAdmin.php
View
@@ -246,19 +246,24 @@ function getManagedModels() {
* 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 @@ function import($data, $form, $request) {
}
$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(

0 comments on commit dd517c4

Please sign in to comment.