I am trying to create a cut down version of the image gallery where there is only one set of images associated with a page (rather than the set of albums each holding images which the image gallery module provides).
This is all straightforward until I tried to get the ImageDataManager to upload to a different folder than the Uploads folder. I have seen the posts in another thread about the setUploadFolder method but I cannot get that to work.
Is anyone doing this successfully?
Thanks in advance,
Pete
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
OK I got this to work by hacking apart the ImageGallery code and removing the albums. I was having problems in my handleswfupload method that was throwing user_error(). I couldn't debug into this method using XDebug for some reason but I managed to track down the problem by using the method suggested by UncleCheese here: http://silverstripe.org/all-other-modules/show/253878?start=304#post259217.
Thanks,
Pete
What was wrong with setUploadFolder? As far as I know, that's working. Also, you can use enableUploadFolderSelection() (I think that's the name of it), which will give you a folder tree to choose where the file will go.
If I change the upload folder using the following code:
function getCMSFields() {
$photoManager = new ImageDataObjectManager($this, "Photos", "FlameEventPage_Photo", "Photo", array("Title"=>"Title","Caption"=>"Caption"), "getCMSFields_forPopup");
$photoManager->setUploadFolder(str_replace('assets/','',$this->AssetFolder()->Filename));
$fields = parent::GetCMSFields();
$fields->addFieldToTab("Root.Content.EventPhotos", $photoManager);
return $fields;
}
Then I get the following error when I upload a file:
[Notice] Trying to get property of non-object
POST /SilverStripe/admin/EditForm/field/Photos/UploadForm?ctf[Photos][per_page]=10&ctf[Photos][showall]=0&ctf[Photos][sort]=Created&ctf[Photos][sort_dir]=DESC&ctf[Photos][search]=&ctf[Photos][filter]=&ctf[Photos][view]=grid&ctf[Photos][imagesize]=100
Line 317 in D:\wamp\www\silverstripe\dataobject_manager\code\FileDataObjectManager.php
Source
308 protected function getChildDataObj()
309 {
310 $class = $this->sourceClass();
311 return new $class();
312 }
313
314 public function getPreviewFieldFor($fileObject, $size = 150)
315 {
316 if($fileObject instanceof Image) {
317 $URL = $fileObject->SetHeight($size)->URL;
318 return new LiteralField("icon",
319 "<div class='current-image'><img src='$URL' alt='' /><h3>$fileObject->Filename</h3></div>"
320 );
321 }
322 else {
323 $URL = $fileObject->Icon();
Trace
* FileDataObjectManager->getPreviewFieldFor(Image)
Line 353 of FileDataObjectManager.php
* FileDataObjectManager->EditUploadedForm()
Line 303 of FileDataObjectManager.php
* FileDataObjectManager->saveUploadForm(Array,ImageDataObjectManager_Popup,HTTPRequest)
Line 228 of Form.php
* Form->httpSubmission(HTTPRequest)
Line 107 of RequestHandler.php
* RequestHandler->handleRequest(HTTPRequest)
Line 121 of RequestHandler.php
* RequestHandler->handleRequest(HTTPRequest)
Line 121 of RequestHandler.php
* RequestHandler->handleRequest(HTTPRequest)
Line 121 of RequestHandler.php
* RequestHandler->handleRequest(HTTPRequest)
Line 122 of Controller.php
* Controller->handleRequest(HTTPRequest)
Line 277 of Director.php
* Director::handleRequest(HTTPRequest,Session)
Line 121 of Director.php
* Director::direct(/admin/EditForm/field/Photos/UploadForm)
Line 115 of main.php
The $fileObject is not initialized properly. It has only one field which is ID and this has value 0.
It appears that file was uploaded to the correct folder on the file system but that also an new folder has been created at the same place as the image (called new-folder).
What is the reason that you are not using this method in your Image Gallery module?
Cheers,
Pete
I think I see the issue. Do an SVN update.
Ah now that works! Thanks UncleCheese. That makes life a lot easier.
Hi Pete
Are you able to share your code snippet for this functionality at SSBits! http://ssbits.com/
Thanks !
Here are the required modules:
Associated Folder Module - associate a filesystem folder with a Page.
http://github.com/petebacondarwin/SilverStripe-Associated-Folder-Module/tree/master
Photo Album Module - upload and display images on a single page.
http://github.com/petebacondarwin/SilverStripe-Photo-Album-Module/tree/master
The associated folder module is very useful in a number of contexts: whenever you are uploading files associated with a page, such as press releases, photos, blog attachments and so on. The module is clever enough to keep the folder tree in synch with the page tree and helps to keep your files more easily maintained.
The photo album uses the associated folder module to store the photos in a folder that is linked to the page, but also requires the DataObject Manager and SWFUpload modules for the backend.
Enjoy! Any feedback would be most welcome.
Pete