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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

CheckboxSetField to show dataobjects on a page in ss 3.0


Go to End


1069 Views

Avatar
tee 1977

Community Member, 6 Posts

22 August 2013 at 3:21am

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