With the following code I can enable D&D sorting in the DOM, but after a save and publish all the items are back where they were:
$datamanager = new DataObjectManager(
$this, // Controller
'CoverFlows', // Source name
'CoverFlow', // Source class
array(
'Thumbnail' => 'Photo',
'Description' => 'Description',
'LinkToName' => 'LinksTo',
'Width' => 'Width',
'Height' => 'Height'
), // Headings
'getCMSFields_forPopup'// Detail fields (function name or FieldSet object)
// Filter clause
// Sort clause
// Join clause
);
class CoverFlow extends DataObject {
static $db = array (
'Description' => 'Varchar(255)',
'Width' => 'Text',
'Height' => 'Text',
'LinkToName' => 'Varchar(255)'
);
static $has_one = array(
'CoverFlowPage' => 'Page',
'LinkTo' => 'SiteTree',
'Photo' => 'Image'
);
public function getCMSFields_forPopup(){
$imageUploadField = new ImageUploadField(
'Photo',
'Photo to add:',
array(
'buttonText' => 'Upload an Image'
)
);
$imageUploadField->setuploadFolder('Images');
$imageUploadField->allowFolderSelection = false;
$siteTreeDropdown = new SimpleTreeDropdownField('LinkToID','Page to link to:','SiteTree');
$siteTreeDropdown->setEmptyString(_t('Mysite.PLEASESELECT','Please select'));
return new FieldSet(
$imageUploadField,
new TextField('Description','Description (appears with the image on page):'),
$siteTreeDropdown//,
//new TextField('Width'),
//new TextField('Height')
);
}
function Thumbnail() {
$Photo = $this->Photo();
if ( $Photo ) {
return $Photo->CMSThumbnail();
} else {
return null;
}
}
public function onBeforeWrite(){
if($this->Photo()){
$this->Width = $this->Photo()->getWidth();
$this->Height = $this->Photo()->getHeight();
if($this->LinkToID != null){
$this->LinkToName = DataObject::get_by_id('SiteTree', $this->LinkToID)->Title;
}
parent::onBeforeWrite();
}
}
public function ImagesLink(){
return DataObject::get_by_id('SiteTree',$this->LinkToID)->Link();
}
}
_config.php:
SortableDataObject::add_sortable_classes(array('CoverFlow'));