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.

Archive /

Our old forums are still available as a read-only archive.

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

HasManyFileManager: New CMS module/extension. Testers/review needed


Go to End


62 Posts   109893 Views

Avatar
bummzack

Community Member, 904 Posts

16 September 2008 at 11:01pm

Oh wow. So many views on that Topic...

Somehow i missed the last few replies from you guys. Sorry! I was totally busy with finishing my diploma. I hope i'll be able to further improve the HasManyFileManager in the near future. Maybe turn it into a real Module for SilverStripe too. If possible i'd like to put it into the silverstripe repository, instead of my own svn repo.

@UncleCheese:
Adding more fields to a file shouldn't be a Problem (did that already). You'll have to create a custom DataObjectDecorator for the File class. Here's a simple example

<?php
class MyFile extends DataObjectDecorator
{
	public function extraDBFields() {
		return array(
			'db' => array(
				'someFlag' => 'Boolean'
			)
		);
	}

	public function getCMSFields(){
		return new FieldSet(
			new TextField('Title', _t('AssetAdmin.TITLE'), $this->owner->Title),
			new DropdownField('someFlag', 'Has Flag?', array(1=> 'Yes', 0 => 'No'), $this->owner->someFlag)
		);
	}
}

This decorator adds a new Boolean-Field "someFlag" to the database and allows editing using a DropdownField. You could extend this to any kind of input of course, but be careful with field types that require special JavaScript functionality (you'll have to load the JS code in the iframe too. This is supported, but a bit tricky to do).

To make this whole thing work, you'll have to add another line to your _config.php File:

DataObject::add_extension('File', 'MyFile');

I hope that helps. If it doesn't then i probably didn't put my latest sources up for download ;)
Cheers -- banal

Avatar
UncleCheese

Forum Moderator, 4102 Posts

17 September 2008 at 1:08am

Awesome! Thanks for the reply, banal.. I've been so jazzed about this thing ever since I saw it. Definitely keep us posted about progress. There's a lot of interest here!

Avatar
jjeziorski

Community Member, 11 Posts

17 September 2008 at 10:33am

Edited: 17/09/2008 10:45am

First of all great work. That's what i was looking for.

However, I have some problems/errors (possibly due to my ignorance).
There's a snapshot of an error that i get upon installation of module. I have followed your guides and created an ImagePage and also an ImageFile extension of DataObjectDecorator with following code:

class ImageFile extends DataObjectDecorator
{
   public function extraDBFields() {
      return array(
         'db' => array(
            'Description' => 'Text'
         )
      );
   }

   public function getCMSFields(){
      return new FieldSet(
         new TextField('Title', _t('AssetAdmin.TITLE'), $this->owner->Title),
         new TextareaField('Description', _t('AssetAdmin.DESCRIPTION'), $this->owner->Description)
      );
   }
} 

It was also included in module _config.php file

Problems encountered:

1. error seen on image - commenting out line 231: "$file->update($data);" stopped triggering an error, though even before all data seemed to save properly.
2. I don't get any images on published site: used template code from demo
3. additional data "Description" seem to fail to save.

Any help will be most welcome
Thanks,
Jake

Avatar
Bo_Einzeller

Community Member, 18 Posts

23 September 2008 at 3:10am

Hy Banal
Great work! I already used your filemanager for 2 websites and in this way, i fixed some errors.
The most of them occured when i tried to implement it in the newest draft-Version of SS.

So, here's a shortcut what i've fixed:
- getCMSFields is implemented in the draft-Version so it can't be decorated. I renamed it to getMyCMSFields

- Cause Form-Handling has Changed in the draft-Version, the director Link should always have the item-ID attached. Otherwise we run in several errors

- Uploads with the same filename are messed up every second time. So i upload the file directly in its SubFolder:
$newId = $folder->addUploadToFolder($data['Upload']);

- Formated Images aren't deleted with the main-Image, so i wrote my own deleteFormattedImages Function.

I've Attached the whole Code.

@ jjeziorski:
I had this Problem with a draft-Version of Silverstripe. I think you can solve it by replace
Line 231 ($file->update($data);)
with
foreach($data as $k => $v) {
if($v && isset($file->$k)) $file->$k = $v;
}

Cheers

Avatar
bummzack

Community Member, 904 Posts

23 September 2008 at 7:14pm

@Bo_Einzeller

Great! Thanks for looking into it and fixing stuff. I wasn't able to test the filemanager with the CVS Version of SilverStripe as of now.

It's funny that we stumbled upon the same problems. You mentioned the formatted images and the upload folder problem. I discovered these too while i was developing the module and filed two bugs/requests:
http://open.silverstripe.com/ticket/2719
http://open.silverstripe.com/ticket/2712

Cheers

Avatar
Hamish

Community Member, 712 Posts

24 September 2008 at 5:05pm

This extension rules... thanks!

Avatar
Double-A-Ron

Community Member, 607 Posts

25 September 2008 at 2:16pm

This extension kicks ass. Subscribing for future discussion.

Avatar
Ingo

Forum Moderator, 801 Posts

25 September 2008 at 10:20pm

Hey banal, had a quick browse through the code, solid work!
Are you interested in hosting your module on svn.silverstripe.com?
This would mean you get free bugtracking, a more structured release process, and a unified place for your users to look for new versions and cutting-edge development.