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.

Data Model Questions /

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

Why don't my chosen fields in $summary_fields show?


Go to End


4 Posts   2565 Views

Avatar
Spaghetti

Community Member, 32 Posts

21 March 2013 at 11:40pm

I'm almost there with my staff/departments page, I just can't seem to get the summary fields that I want to be displayed, displayed. Which is odd because they were working a while ago, complete with a proper thumbnail image, which also seems to be broken now. I've tried rebuilding and flushing.

Here's the code:

<?php

class StaffPage extends Page {

	public static $has_many = array(
    	'StaffMembers' => 'StaffMember',
    	'Departments' => 'Department'
  	);
		
	public function getCMSFields() {
   		$fields = parent::getCMSFields();
		
		//Configures the editor for adding and removing staff.
		$gridFieldConfig =$gridFieldConfig = GridFieldConfig_RecordEditor::create();
		$gridfield = new GridField("StaffMembers", "StaffMember", $this->StaffMembers(), $gridFieldConfig);
		$dataColumns = $gridfield->getConfig()->getComponentByType('GridFieldDataColumns');
    	$dataColumns->setDisplayFields(array(
			'Name'=>'Name',				
			'Image' => 'Image',			
			));
		$fields->addFieldToTab('Root.Staff', $gridfield);

		//Configures the editor for adding and removing Departments.
		$gridFieldConfig2 =$gridFieldConfig = GridFieldConfig_RecordEditor::create();
		$gridfield2 = new GridField("Departments", "Department", $this->Departments(), $gridFieldConfig2);
		$dataColumns2 = $gridfield2->getConfig()->getComponentByType('GridFieldDataColumns');
    	$dataColumns2->setDisplayFields(array(
			'Name'=>'Name',
			));
		$fields->addFieldToTab('Root.Departments', $gridfield2);

		return $fields;
	}
}

class StaffPage_Controller extends Page_Controller {	
}




<?php

class StaffMember extends DataObject { 

	static $db = array(
		'Name'=>'Varchar',	
		'Details'=>'HTMLText'
	);

	static $has_one = array(
		'Image' => 'Image',		
		'Department' => 'Department',
		"Parent" => "StaffPage"
	);

	static $summary_fields = array( 		
		'Name',
		'Thumbnail',
		'Department.Name'
	);

	function getThumbnail() { 
		return $this->Image()->CMSThumbnail();
	}

	function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->removeByName('ParentID');
		return $fields;
	}
}

StaffMember seems to show the Name and Image summary fields, in that order, no matter what I put there, which suggests to me that it's ignoring my choice entirely.

Any ideas? Much appreciated...

Avatar
kinglozzer

Community Member, 187 Posts

22 March 2013 at 12:00am

You've specified the fields to be displayed in your getCMSFields() function:

$dataColumns->setDisplayFields(array( 
         'Name'=>'Name',
         'Image' => 'Image'
));

Either update that section of code to match what fields you want, or just remove it.

Avatar
Spaghetti

Community Member, 32 Posts

22 March 2013 at 12:01am

Gah... you're right. :) 'Target fixation'.

Thanks again.

Avatar
Spaghetti

Community Member, 32 Posts

22 March 2013 at 12:57am

Actually, it's displaying properly on the live site now but in the cms not all of my staff are showing.

There's two main tabs on the staff page, departments and staff.

If I add staff via the staff tab they show up in that main tab okay but if I add them via the departments->members sub-tab, they don't show up in the main staff tab, yet they seem to be correctly linked to the department and show on the site correctly.