I've found what seems to be a bug with ModelAdmin. I thought I'd post it here to see if anyone else has experienced the same thing before I submit a ticket (in case I'm using it wrong).
I am using a fresh SilverStripe install and the problem seems to be there in both 2.4.4 and 2.4.5.
I have created a very simple DataObject: 'Mug' with 1 field and a very simple ModelAdmin: MugAdmin to manage it (just to illustrate the problem).
The problem is that when I click the Delete action on the EditForm I get an error. The delete happens but the ResultsForm doesn't get loaded and the server returns:
500 Warning: "array_fill(): Number of elements must be positive" at line 743 of F:\...\cms\code\ModelAdmin.php
The basic DataObject (Mug):
class Mug extends DataObject {
static $db = array(
'Type' => 'Text'
);
static $searchable_fields = array(
'Type'
);
static $summary_fields = array(
'Type'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', new TextField('Type'));
return $fields;
}
}
and the ModelAdmin class:
class MugAdmin extends ModelAdmin {
static $managed_models = array(
'Mug'
);
static $url_segment = 'mugs';
static $menu_title = 'Mugs';
}
I have found the problem to be that in the doDelete method of ModelAdmin_RecordController after the delete occurs a redirect is sent to 'SearchForm?action=search'.
This gets the SearchForm and the SearchForm then handles the request.
The httpSubmission method in Form then tries to load the data from the request into the form but since no data was sent with the request all data in the form is lost. This means the ResultAssembly in the form is empty and causes an error in getResultsTable where the line:
$tf->setFieldFormatting(array_combine(array_keys($summaryFields), array_fill(0,count($summaryFields), $url)));
tries to do an array_fill() where count($summaryFields) is 0.
I have just put
$form = $this->SearchForm();
at the start of the search method and this fixes the problem.