Jump to:

23483 Posts in 18976 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » CheckboxSetField to show dataobjects on a page in ss 3.0

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 244 Views
  • tee 1977
    Avatar
    Community Member
    6 Posts

    CheckboxSetField to show dataobjects on a page in ss 3.0 Link to this post

    On a previous site using silverstripe 2.4 i followed a tutorial to allow team profiles to be administered in the model admin which then allowed me to go into the admin and select the profiles per page via a checkbox: http://www.balbus.tk/many-many-checkboxsetfield/

    Because dataobject manager is deprecated i cant seem to replicate this in SS3.0. I can get the dataobjects to view in Model Admin but cant get the admin page to view on the relevent page to show all the profiles with checkboxes.

    The code i have so far is:

    <?php
    class TeamProfile extends Page {

       public static $db = array(
          
          
          
          
       );

       public static $has_one = array(
       
          
          
          
       );
       
       public static $many_many = array(

           'TheTeams' => 'TheTeam'
    );
       static $has_many = array(
          
          
       );
       
       
       function getCMSFields() {
          $fields = parent::getCMSFields();
          
          $fields->removeFieldFromTab("Root.Main", 'Content');
          
          /*$fields->addFieldToTab('Root.Content.Banner', new ImageField('BannerImage','Banner Image'));*/
          
          
          
           $gridFieldConfig = GridFieldConfig::create()->addComponents(
    new GridFieldToolbarHeader(),
    new GridFieldAddNewButton('toolbar-header-right'),
    new GridFieldSortableHeader(),
    new GridFieldDataColumns(),
    new GridFieldPaginator(10),
    new GridFieldEditButton(),
    new GridFieldDeleteAction(),
    new GridFieldDetailForm()
    );
       

          $config = GridFieldConfig_RelationEditor::create();
          $config->addComponent(new GridFieldSortableRows('SortOrder'));
    $config->addComponent(new GridFieldBulkEditingTools());
    $config->addComponent(new GridFieldBulkImageUpload());
          
             
       $theteams= DataObject::get('TheTeam');

    if (!empty($theteams)) {

    // create an array('ID'=>'Name')
    $map = $theteams->toDropdownMap('ID', 'SpecialistName');

    // create a Checkbox group based on the array
    $fields->addFieldToTab('Root.Content.TheTeams',
    new CheckboxSetField(
    $boxname = "TheTeams",
    $title = "Select Team Members",
    $source = $map
    ));

             
             

              return $fields;
             
       
          }
          
          
          

       }
       
       

    }
    class TeamProfile_Controller extends Page_Controller {
       
       
    }

    Please help, Im hoping its just a case of amending the dataobject code at the bottom

    Tamara

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