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.

Customising the CMS /

adding other details when you upload images


Go to End
Reply


14 Posts   1979 Views

Avatar
servalman

Community Member, 211 Posts

25 March 2010 at 4:55am

Hello guys

This is where I'm at now :

1) Installed DataObject manager (with swfupload) and it went ok
2) I tried to use the code provided by Juanitou and it did something (creating table field when doing dev/build)

Waht I dont' get is taht when I upload a new file in the File&Images section of the cms it doesn't give me a chance to see the "legend" field. I can only see "name" " title" and "content"

Maybe I'm not using thi the right way

Please guide me ;)

Thanks T

Avatar
Juanitou

Community Member, 323 Posts

25 March 2010 at 9:14pm

Hi!

MyImage is a DataObject that has one Image and Page (relationship) and a Legeng (database field). You’re not giving a legend to the the Image, but to the MyImage DataObject. In other words, Legend is dependent (and modified) on the Page, not on the Image itself. In that way, you can assign a different legend for the same image shown in different pages.

It looks smart and, in my case, it was even practical, but I wasn’t looking for it: I got it when I was not able to extend the Image class itself. I think you could do better by decorating the Image class instead of creating a DataObject related to an Image.

Hope it helps,
Juan

Avatar
servalman

Community Member, 211 Posts

25 March 2010 at 9:50pm

Thank you

That's getting clearer now .

So waht I have to do now is incuded The Image Datamodel in my SS pages ?

Thanks

Avatar
Juanitou

Community Member, 323 Posts

25 March 2010 at 11:23pm

Yes, I forgot to give you the whole code. You can add these lines to your getCMSFields() function (please note that I’m using here the ImageDataObjectManager field provided by UncleCheese’s DataObjectManager module):

$fields->addFieldToTab('Root.Content.Images', new ImageDataObjectManager(
   $this,
   'Images',
   'MyImage',
   'Image',
   array(
      'Legend' => 'Legend',
      'ShowImagesTitle' => 'Show'
   ),
   'getCMSFields_forPopup'
   )

Avatar
servalman

Community Member, 211 Posts

25 March 2010 at 11:35pm

oup's I'm a bit lost now where does this go :

in MyImage.php ? let me know ?

And you think as you used it that it is better than exentiding image.
Becuse one of my problem is that te page has to be created for that

Thanks for your time

<?php
/*
** You haven't been able to extend directly Image and add the boolean field
*/
class MyImage extends DataObject {
static $db = array (
'ShowImagesTitle' => 'Boolean',
'Legend' => 'Text'
);
static $has_one = array (
'Image' => 'Image',
'Page' => 'Page'
);

$fields->addFieldToTab('Root.Content.Images', new ImageDataObjectManager(
$this,
'Images',
'MyImage',
'Image',
array(
'Legend' => 'Legend',
'ShowImagesTitle' => 'Show'
),
public function getCMSFields_forPopup() {
$myImageField = new ImageField('Image');
$myImageField->setAllowedExtensions(array('jpg','gif','png'));
return new FieldSet(
$myImageField,
new TextField('Legend'),
new CheckboxField('ShowImagesTitle', 'Show legend')
);
}
}

?>

Avatar
Juanitou

Community Member, 323 Posts

26 March 2010 at 2:43am

Add the code in Page.php.

Go to Top