21309 Posts in 5738 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 159 Views |
-
Image Map

19 September 2012 at 8:48pm Last edited: 20 September 2012 2:44am
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.
-
Re: Image Map

20 September 2012 at 2:43am Last edited: 20 September 2012 2:43am
Correction
After many long hours of trying many different convoluted methods it turns out all I need to do to get rid of the upload from computer option was this.
$imageField->setCanUploadNewFile(false);
I found it buried here http://api.silverstripe.org/2.4/forms/fields-files/FileIFrameField.html#methodsetCanUploadNewFile
Works in 2.4.7
| 159 Views | ||
|
Page:
1
|
Go to Top |

