Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » adding other details when you upload images

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

Page: 1 2
Go to End
Author Topic: 1894 Views
  • servalman
    Avatar
    Community Member
    211 Posts

    Re: adding other details when you upload images Link to this post

    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

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: adding other details when you upload images Link to this post

    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

  • servalman
    Avatar
    Community Member
    211 Posts

    Re: adding other details when you upload images Link to this post

    Thank you

    That's getting clearer now .

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

    Thanks

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: adding other details when you upload images Link to this post

    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'
       )

  • servalman
    Avatar
    Community Member
    211 Posts

    Re: adding other details when you upload images Link to this post

    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')
    );
    }
    }

    ?>

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: adding other details when you upload images Link to this post

    Add the code in Page.php.

    1894 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.