Description
If your ModelAdmin
uses a custom slug (as per the below example) instead of relying on the class name, any model_importers
config for that model needs to be added twice.
private static $managed_models = [
'users' => [
'title' => 'Users',
'dataClass' => Member::class
],
];
private static $model_importers = [
// Add once for the model tab (slug) and once for the model class
'users' => MemberCsvBulkLoader::class,
Member::class => MemberCsvBulkLoader::class,
];
ACs
- You only need to define EITHER modelClass (e.g.
Member::class
) OR modelTab (e.g.'users'
) - It's possible to have the SAME modelClass on different tabs use different
$model_importers
- see example below
Example below
- 'Backend people' tab using Member::class modelClass AND BackendPeopleBulkLoader::class
- 'Frontend people' tab using Member::class modelClass AND FronendPeopleBulkLoader::class
Notes
- ModelClass is the "blanket" / "fallback" - ModelTab is the optional specific thing that can be specified
Background
We have to add both the model tab reference and the class name as keys for the importers because ModelAdmin
currently checks for $importers[$modelClass]
in some places and $importers[$this->modelTab]
in others.
It should always use either the tab or the class - whichever we decide is the more appropriate canonical reference.
If it uses the class, we have to document the fact that the same importer must be used for all tabs with that class, which is a limitation we perhaps don't want to impose.
If it uses the tab name, we have to document that fact so that it's abundantly clear. This would be my preferred resolution as it allows developers to import models of the same class in different ways depending on what tab they're importing from.