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.

Archive

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

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

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


Reply

62 Posts   104204 Views

Avatar
banal

16 September 2008 at 11:01pm Community Member, 901 Posts

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

17 September 2008 at 1:08am 4085 Posts

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

17 September 2008 at 10:33am (Last edited: 17 September 2008 10:45am), Community Member, 11 Posts

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:
[URL=http://images40.fotosik.pl/11/5630b582e1b7792e.png][/URL]
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

23 September 2008 at 3:10am Community Member, 18 Posts

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
banal

23 September 2008 at 7:14pm Community Member, 901 Posts

@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:
[url]http://open.silverstripe.com/ticket/2719[/url]
[url]http://open.silverstripe.com/ticket/2712[/url]

Cheers

Avatar
Hamish

24 September 2008 at 5:05pm Community Member, 712 Posts

This extension rules... thanks!

Avatar
Double-A-Ron

25 September 2008 at 2:16pm Community Member, 604 Posts

This extension kicks ass. Subscribing for future discussion.

Avatar
Ingo

25 September 2008 at 10:20pm Forum Moderator, 801 Posts

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.