diff --git a/code/GridFieldBulkEditingHelper.php b/code/GridFieldBulkEditingHelper.php index 84ec6e4..5985bf3 100644 --- a/code/GridFieldBulkEditingHelper.php +++ b/code/GridFieldBulkEditingHelper.php @@ -13,26 +13,24 @@ class GridFieldBulkEditingHelper { public static function getModelCMSDataFields ( $config, $modelClass, $recordID = null ) { - if ( $recordID == null ) $cmsFields = singleton($modelClass)->getCMSFields(); - else $cmsFields = DataObject::get_by_id($modelClass, $recordID)->getCMSFields(); + $cmsFields = singleton($modelClass)->getCMSFields(); $cmsDataFields = $cmsFields->dataFields(); $cmsDataFields = GridFieldBulkEditingHelper::filterNonEditableRecordsFields($config, $cmsDataFields); - // populate fields with record's values -> must some easier way to do this - // @TODO: can we handle has_one/has_many/many_many relations - if ( $recordID != null ) - { - $record = DataObject::get_by_id($modelClass, $recordID); - foreach ( $cmsDataFields as $name => $f ) - { - $cmsDataFields[$name]->setValue( $record->getField($name) ); - } - } - return $cmsDataFields; } + public static function populateCMSDataFields ( $cmsDataFields, $modelClass, $recordID ) + { + // @TODO: can we handle has_one/has_many/many_many relations + $record = DataObject::get_by_id($modelClass, $recordID); + foreach ( $cmsDataFields as $name => $f ) + { + $cmsDataFields[$name]->setValue( $record->getField($name) ); + } + return $cmsDataFields; + } public static function filterNonEditableRecordsFields ( $config, $dataFields ) { diff --git a/code/GridFieldBulkManager_Request.php b/code/GridFieldBulkManager_Request.php index dea2a09..47f3058 100644 --- a/code/GridFieldBulkManager_Request.php +++ b/code/GridFieldBulkManager_Request.php @@ -107,8 +107,9 @@ class GridFieldBulkManager_Request extends RequestHandler { foreach ( $recordList as $id ) { - $recordCMSDataFields = GridFieldBulkEditingHelper::getModelCMSDataFields( $config, $this->gridField->list->dataClass, $id ); + $recordCMSDataFields = GridFieldBulkEditingHelper::getModelCMSDataFields( $config, $this->gridField->list->dataClass ); $recordCMSDataFields = GridFieldBulkEditingHelper::getModelFilteredDataFields($config, $recordCMSDataFields); + $recordCMSDataFields = GridFieldBulkEditingHelper::populateCMSDataFields( $recordCMSDataFields, $this->gridField->list->dataClass, $id ); $recordCMSDataFields = GridFieldBulkEditingHelper::escapeFormFieldsName( $recordCMSDataFields, $id ); $editedRecordList->push(