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   1929 Views

Avatar
servalman

Community Member, 211 Posts

24 March 2010 at 4:56am

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

Avatar
Carbon Crayon

Community Member, 598 Posts

24 March 2010 at 5:57am

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

Avatar
Juanitou

Community Member, 323 Posts

24 March 2010 at 5:59am

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 %>

Avatar
servalman

Community Member, 211 Posts

24 March 2010 at 6:03am

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

Avatar
Carbon Crayon

Community Member, 598 Posts

24 March 2010 at 6:15am

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

Avatar
servalman

Community Member, 211 Posts

24 March 2010 at 6:24am

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

Avatar
Juanitou

Community Member, 323 Posts

24 March 2010 at 9:14am

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

Avatar
servalman

Community Member, 211 Posts

24 March 2010 at 10:23am

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

Go to Top