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.

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.

All other Modules /

Discuss all other Modules here.

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

ImageDataObjectManager


Go to End


8 Posts   5045 Views

Avatar
petebd

Community Member, 16 Posts

6 May 2009 at 10:50pm

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

Avatar
petebd

Community Member, 16 Posts

7 May 2009 at 1:30am

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

Avatar
UncleCheese

Forum Moderator, 4102 Posts

7 May 2009 at 1:42am

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.

Avatar
petebd

Community Member, 16 Posts

7 May 2009 at 6:00am

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

Avatar
UncleCheese

Forum Moderator, 4102 Posts

7 May 2009 at 6:37am

I think I see the issue. Do an SVN update.

Avatar
petebd

Community Member, 16 Posts

7 May 2009 at 7:11am

Ah now that works! Thanks UncleCheese. That makes life a lot easier.

Avatar
boombox

Community Member, 44 Posts

29 July 2009 at 1:27am

Hi Pete
Are you able to share your code snippet for this functionality at SSBits! http://ssbits.com/
Thanks !

Avatar
petebd

Community Member, 16 Posts

29 July 2009 at 2:44am

Edited: 30/07/2009 6:12am

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