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: 1896 Views
  • servalman
    Avatar
    Community Member
    211 Posts

    adding other details when you upload images Link to this post

    Hello

    I hope this the right place to post this if not sorry

    I have to add images cms and use them later on in the website

    Waht I want to achieve is being able to add fields like Title, author or dimensions to these image then use them later on in the cms.

    Is this the way to do things or do I have to create a template.

    I don't know wich way to go and I'd like someone to help me chooese the rigt direction to achieve this.

    Thanks a lot for advice

  • Aram
    Avatar
    Community Member
    598 Posts

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

    Hi Servalman

    Have a look at the ImageDataObjectManager, which comes as part of the Data Object manager module.

    You basically create a dataobject for your image with a has_one image relationship and can add as many fields as you like. Then when you upload them through the ImageDataObjectManager, it will go through and ask for the details of each image you just uploaded.

    Here are the docs for the DOM (they are a little out of date): http://doc.silverstripe.org/doku.php?id=modules:dataobjectmanager

    Aram

    www.ssbits.com - SilversStripe tutorials, tips and other bits

  • Juanitou
    Avatar
    Community Member
    323 Posts

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

    Hi!

    I did it by creating an extension to DataObject, I didn’t manage to make it work as I wanted by extending Image class directly, don’t remember why…

    Hope it helps,
    Juan

    mysite/code/MyImage.php

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

    ?>

    mysite/code/Page.php

       // Pages can have many images (see MyImage for the other side of the relation)
       public static $has_many = array(
          'Images' => 'MyImage'
       );

    And an example of using this in a Menu2 template:

       <% if Images %>
       <div class="menu2 images">
          <% control Images %>
          <div>
             $Image.SetWidth(209)
             <% if ShowImagesTitle %><p>$Legend</p><% end_if %>
          </div>
          <% end_control %>
       </div>
       <% end_if %>

  • servalman
    Avatar
    Community Member
    211 Posts

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

    Thank you both for your answers.

    I will look at them closely.

    But if I undesrtand the process I will be able to upload images with their details then use them later or have them used by someone else in a page.

    Am I correct ?

    Thanks

  • Aram
    Avatar
    Community Member
    598 Posts

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

    What is the workflow that you want to achieve? When you say used by other people on other pages what do you mean? Are you talking about the TinyMCE content editor or some custom image manager?

    Also what do you mean by 'use them later'? If you could explain the actual use case that would be helpful.

    Aram

    www.ssbits.com - SilverStripe tutorials, tip and other bits

  • servalman
    Avatar
    Community Member
    211 Posts

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

    Thank's for your concern :

    I' going to try to be clear.

    The project is for an artist who want's to show his work.

    step 1 :
    Uploading several images with all their details title, dimensions, materials, price etc.

    step 2 :
    showing those pictures in different sections of the website (galleries, text page etc..) sometimes with all the details sometimes with just some of them.

    step 2.5 (that's an option for later on) :
    allowing the website editors to choose wich details they want to show

    Hope i'm clearer ;)

    T

  • Juanitou
    Avatar
    Community Member
    323 Posts

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

    Yes, I think you could use the code sent before for doing that. Just add more checkboxes…

  • servalman
    Avatar
    Community Member
    211 Posts

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

    Thanks for your advice
    I Will try and let you Know if it works
    T

    1896 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.