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 /

Read-only ModelAdmin


3 Posts   472 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, 225 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