Jump to:

5513 Posts in 1732 Topics by 1218 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Visual select field

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

Page: 1
Go to End
Author Topic: 593 Views
  • JonoM
    Avatar
    Community Member
    103 Posts

    Visual select field Link to this post

    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

  • JonoM
    Avatar
    Community Member
    103 Posts

    Re: Visual select field Link to this post

    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.

    593 Views
Page: 1
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.