Adding Summary Fields to the MemberTableList using SilverStripe 2.4+

Posted by Gav on 7 December 2010 | 0 Comments

Tags:

Previously in SilverStripe 2.3 we used the following code in the _config.php file to add fields to the MemberTableList.

MemberTableField::addMembershipFields(array(
	"IsPaid" => "IsPaid",
	"ID" => "Invoice Number"
))

This has been depreciated in 2.4+ . Now we need to decorate the Member class. To do this, we add the following code to the _config.php file.

Object::add_extension('Member', 'MemberDecorator');

Now we need to create the MemberDecorator.php file within the mysite/code directory. Within this file, we use the updateSummaryFields function to add new fields to the MemberTableList. We can add fields or functions. Below in my example, I have added an ID field and I have also added the IsPaid function.

class MemberDecorator extends DataObjectDecorator {

	function augmentSQL(SQLQuery &$query) {}

	public function extraStatics() {
		return array(
			'db' => array(
				'Paid' => 'Boolean'
			)
		);
	}

	public function updateCMSFields(Fieldset &$fields) {		
		$fields->addFieldToTab('Root.SiteMemberDetails', new CheckboxField('Paid', 'Has the account been paid for?'));

	}

	function IsPaid() {
		return ($this->owner->Paid)?'Yes':'No';
	}

	function updateSummaryFields(Fieldset &$fields) {
		$fields['ID'] = 'ID';
		$fields['IsPaid'] = 'IsPaid';
	}
}

Another thing to take note of is that we use $this->owner to gain access to the db fields. 

Cheers

 


Post your comment

Comments

No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments