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 /

Visual select field


Reply


2 Posts   644 Views

Avatar
JonoM

Community Member, 103 Posts

18 July 2011 at 1:27pm

Does anyone know of a way to achieve a radio group like in the attached image?

I don't think it's built in to SS but I was hoping someone might have done something like it before. I want my CMS users to be able to choose from a few different layout options within the one page type with a visual cue to what each one looks like.

Thanks

Avatar
JonoM

Community Member, 103 Posts

18 July 2011 at 2:18pm

Edited: 18/07/2011 2:22pm

So much easier than I imagined!

      $ArrayMap = array(
         '1' => '<img src="/ImgDirectory/ImageName.jpg" alt="" width="60" height = "60" /> Title 1',
         '2' => '<img src="/ImgDirectory/ImageName2.jpg" alt="" width="60" height = "60" /> Title 2'
      );
      $fields->addFieldToTab("Root.Content.Main", new OptionSetField('FieldName', 'Field Name', $ArrayMap));

Other way - creating field dynamically from data objects:

      $ArrayMap = DataObject::get('DataObjectClassName')->map("ID", "Thumb");
      $fields->addFieldToTab("Root.Content.Main", new OptionSetField('FieldName', 'Field Name', $ArrayMap));

On the relevant data object class

   static $has_one = array (
      'Image' => 'Image'
   );

   public function getThumb() {
      return $this->Image()->CroppedImage(60,60)->Tag;
   }

Probably needs some cleaning up so it doesn't crash if there's no image attached but concept works.