Hi
I'm having trouble with something and it's just occurred to me that it may be impossible to implement.
I want to create an imagefield that only allows the user to select existing images. I'm currently trying to implement a dropdown of images but I'm having trouble.
Here's what I've got so far.
$images = DataObject::get("Image", "ParentID = 5");
$images->toDropdownMap("ID", "Image", $emptyString = "--select--");
$imageField = new DropdownField('Photo', 'Choose an image', $images);
I tried a treedropdownfield but I need a thumbnail of the image, not just the title.
I also tried this.
class OneFolderImageField extends ImageField {
function __construct($name, $title, $value = null, $form = null, $rightTitle = null, $folderName = null) {
$folder = Folder::findOrMake($folderName);
$this->folderName = $folderName;
parent::__construct($name, $title, $value = null, $form = null, $rightTitle = null, $folder->Name);
}
public function EditFileForm() {
$filter = create_function(
'$item', '
$folder = Folder::findOrMake(\''.$this->folderName.'\');
return
(in_array("Image", ClassInfo::ancestry($item->ClassName)) && $item->ParentID == $folder->ID)
||
(in_array("Folder", ClassInfo::ancestry($item->ClassName)) && $item->ID == $folder->ID)
;');
$form = parent::EditFileForm();
$form->dataFieldByName('ExistingFile')->setFilterFunction($filter);
return $form;
}
}
$imageField = new OfferImageField('Photo', 'Photo', 'Photo', $this, 'Test', $folderName);
But that didn't work as I thought it would.
Thanks in advance.