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.

Customising the CMS /

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

Read-only ModelAdmin

Go to End

4 Posts   1964 Views


Community Member, 9 Posts

11 February 2014 at 9:06pm


I have a simple dataobject like this:

class MyObject extends DataObject {

    static $db = array(
        'Creation' => 'Date'

I'd like to have two Model-Admins for the same dataobject.
One should be a normal ModelAdmin alll objects where Creation is in the future.
Another should all objects where Creation is in the past and it should show them as read-only.

I know I can set permission on the MyObject, but that would not solve my problem to be able to have read-only and read-write ModelAdmin.

How is the approach in silverstripe for such cases ?


Community Member, 343 Posts

12 February 2014 at 1:13am

Edited: 12/02/2014 1:38am

You need to overwrite ModelAdmin->getEditForm()

class ReadonlyAdmin extends ModelAdmin {
	public static $managed_models = array(

	public function getEditForm($id = null, $fields = null) {
		$form = parent::getEditForm($id, $fields);

		// get gridfield
		$gridfield = $form->Fields()

		$gridfieldConfig = $gridfield->getConfig();

		// remove delete & edit buttons

		// add a view button
				->addComponent(new GridFieldViewButton());

		return $form;

However, this is not really secure. You still need to set proper permissions in your DataObject.


Community Member, 9 Posts

22 March 2014 at 9:38pm

Thanks a lot. That was what I was looking for


Community Member, 13 Posts

8 April 2016 at 12:04am

Edited: 08/04/2016 12:34am

I have a question for Delvin.
I also have a simple dataobject:

class Documents extends DataObject {

	private static $db = array(
		'DocType' => 'Text',
		'ApprovalDate' => 'Date',
		'PublicationDate' => 'Date',
		'DocNumber' => 'Text',
		'DocTitle' => 'Text',
		'KeyWords' => 'Text'

	private static $has_one = array(
		'Member' => 'Member'

Give me please any idea how to customize my ModelAdmin so, that all users could only view all objects, and only owner (user with ID == MemberID) could edit and delete his objects?
As the result I should like to see such picture: [img=" "]
I try to use such code
if (!(Member::currentUserID() ==  $Value_of_MemberID_Field   )) {
		// add a view button
				->addComponent(new GridFieldViewButton());

How can I get $Value_of_MemberID_Field in the row of GridField?