mirror of
https://github.com/colymba/GridFieldBulkEditingTools.git
synced 2024-10-22 11:05:57 +02:00
separate cms fields fetching and populating
created new fn populateCMSDataFields used to populate fields with a record's data
This commit is contained in:
parent
5e743abeb9
commit
e6f7db2044
@ -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 )
|
||||
{
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user