I'm using Uploadify/DOM 521 and I'm running into an issue with using the same image for multiple purposes. It could be this is a limitation of the SS file system rather than Uploadify/DOM.
My setup: I've added a Thumbnail Image to the page class, and I'm using DOM + Uploadify to add a list of files (Downloads) to an Example. Multiple examples are displayed on a single page using the Examples page type. The Downloads / Example classes are based on the code provided on the Uploadify documentation page.
The issue I have is on adding an image as the thumbnail of a page, and then adding the same image as an Example download the Thumbnail disappears from the page. I believe this is due to the fact that the ClassName in the File table is changed from Image to Download.
Is there a way that allows multiple uses of the same file still using DOM+Uploadify?
I've included trimmed down test code below.
mysite/code/Page.php
<?php
class Page extends SiteTree {
public static $has_one = array(
'Thumbnail' => 'Image',
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Thumbnail", new FileUploadField('Thumbnail', 'Thumbnail'));
return $fields;
}
}
class Page_Controller extends ContentController {
}
mysite/code/Examples.php
<?php
class Examples extends Page {
static $has_many = array (
'Examples' => 'Example'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Examples", new DataObjectManager(
$this,
'Examples',
'Example',
array('Title' => 'Title', 'Description' => 'Description'),
'getCMSFields_forPopup'
));
return $fields;
}
}
class Examples_Controller extends Page_Controller {
}
mysite/code/Example.php
<?php
class Example extends DataObject {
static $db = array (
'Title' => 'Text',
'Description' => 'HTMLText'
);
static $has_one = array (
'ExamplesPage' => 'Examples',
'Thumbnail' => 'Image'
);
static $has_many = array (
'Downloads' => 'Download'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Downloads", new MultipleFileUploadField('Downloads','Select downloads'));
return $fields;
}
public function getCMSFields_forPopup() {
$fields = new FieldSet(
new TextField('Title','Title'),
new SimpleHTMLEditorField('Description','Description'),
new ImageUploadField('Thumbnail','Thumbnail'),
new MultipleFileUploadField('Downloads','Select download files')
);
return $fields;
}
}
mysite/code/Download.php
<?php
class Download extends File {
static $has_one = array(
'Example' => 'Example'
);
}