Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

Uploadify and DataObjectManager patches

Go to End

8 Posts   2380 Views


Community Member, 4 Posts

13 January 2011 at 3:27am


I made some improvements on Uploadify and DataObjectManager, which might be considered for including in trunk.

1. ANSI database compatibility

2. Support for ManyMany relations. Ie. support for uploading (attaching) multiple files and reusing them on multiple pages. To use, extend File class:


class MyMultiFile extends File {
	static $belongs_many_many = array (
		'TestPage' => 'TestPage'

class TestPage extends Page {
	static $many_many = array (
		'Documents' => 'MyMultiFile',
	function getCMSFields() {
		$fields = parent::getCMSFields();
		$f = new MultipleFileUploadField('Documents','Upload several files'); 
		$fields->addFieldToTab('Root.Content.Documents', $f);
		return $fields;

3. deleteEnabled feature
As deleting files, which can be attached on multiple pages, isn't really desired behavior, I added "deleteEnabled" setting, which is false by default on MultipleFile upload field. To enable delete (as it was before patch), use for example:

		$f = new MultipleFileUploadField('Documents','Upload several files',array('deleteEnabled'=>true)); 


- there should be only one class, that extends File class. Otherwise, we get unpredictable behaviour.


1. ANSI database compatibility
2. ManyManyDataObjectManager and ManyManyFileDataObjectManager use $sourceSort for nonrelated objects.
Default sorting of non related objects was not implemented, but it is very easy to use $sourceSort setting of the field to do so.
Example using Testimonials data objects. Non related objects will be sorted by Date DESC.


SortableDataObject::add_sortable_many_many_relation("TestimonialPage", "Testimonials");

class Testimonial extends DataObject {
	static $db = array (
		'Date' => 'Date',
		'Author' => 'Text',
		'Quote' => 'HTMLText'
	static $belongs_many_many = array (
		'TestimonialPage' => 'TestimonialPage'
	public function getCMSFields_forPopup()	{
		return new FieldSet(
			new DateField('Date'),
			new TextField('Author'),
			new TextareaField('Quote')

class TestimonialPage extends Page {
	static $has_many = array (
		'Testimonials' => 'Testimonial'
	public function getCMSFields() {
		$f = parent::getCMSFields();
		$f->addFieldToTab("Root.Content.Testimonials", new DataObjectManager(
			array('Date' => 'Date','Author'=>'Author','Quote' => 'Quote'),
			'"Date" DESC'
		return $f;


- What should sorting do, when we have a sortable many_many relation? Currently, sorting is enabled on client side, but it doesn't do anything.

Regards, miiihi


Forum Moderator, 4102 Posts

13 January 2011 at 4:53am

Wow! These are some great patches. The Uploadify many_many patch has been on my list for a while, but I haven't been able to get to it. That's great.

I know MMDOM has tons of sorting issues, but does your patch break the sortable many_many functionality? That is, when using SortableDataObject::add_sortable_many_many_relation()?

Have you tested the Uploadify patch with both many_many and has_many relations?

Thanks again!

SilverStripe tips, tutorials, screencasts and more:


Community Member, 4 Posts

13 January 2011 at 11:36pm

1. MMDOM sorting. My patch doesn't break anything... or so I hope :). I just added default sorting (coming from field config options) to the end of sorting field list, so when using with Sortable many_many, we now get ORDER BY MMSort, Checked, DefaultSort. Indeed I created this fix just for the situation, where I had sortable many_many relation, but I had no control on sort order of unrelated items.

Now, about issue I have mentioned - if we can specify, how user sorting should behave on many_many relations, with Sortable on or not, I'd be happy to fix it. I'm not sure what'd be the desired behaviour (configurable?), but I know, that it is broken now. User can click on column headers, arrows change, but the rows don't...

2. Uploadify. I have done basic testing with many_many and had_many relations in MySql and in Postgres. But would recommend some more... Specially ANSI compatibility can have some hidden problems... that goes DOM too.

regards, miiihi


Community Member, 176 Posts

21 January 2011 at 2:44am

Great patch, using many_many makes including files much intuitive for users and saves uploading the same file multiple times!

Any insight when this will be included in the official Uploadify and DOM?


Community Member, 63 Posts

26 January 2011 at 5:08pm


Will miiihi's patch fix the double-upload requirement now? Just wanted to check if you think it will make it to trunk soon, if not we'll incorporate the patch in our project.

Thanks miiihi and UC!



Forum Moderator, 4102 Posts

10 March 2011 at 5:02am

@Miihi -- I still want to apply this patch. Are you on Github? Could you submit it as a pull request?


Community Member, 4 Posts

10 March 2011 at 5:21am

funny... as you are writing, I'm in the process of moving your source from my instant made git repo to a fork of your github repo. It should be ready by tomorrow and you'll pull request.



Forum Moderator, 4102 Posts

10 March 2011 at 5:30am

Actually, I just applied it. :)

Can you submit those DOM patches, though? Those were a real headache to merge. I think it was from an older version of the code.