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.

General Questions

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

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

ModelAdmin with Subsite?!


4 Posts   731 Views


26 January 2011 at 10:31am Community Member, 90 Posts

Hey, guys

Currently, i am working on a project that requires using subsite moudel and modeladmin.

I just wonder is that possible to only see the current subsite data in module admin tab.

The logic is:
one subsite admin(not global admin) login to their own subsite, and click on MyModelAdmin Tab on the top CMS navigation, then it will be able to generate the data of managed_models with in current Subsite.

I have looked in ModelAdmin.php, but not sure how could i add the subsite restriction code in?!
Any ideas?

Thanks in advanced.



7 June 2013 at 1:24am Community Member, 168 Posts

Same here, has anybody a solution for that?


7 June 2013 at 3:44am Forum Moderator, 1796 Posts


I don't have an out of the box solution, however I'd advise that you do something akin to translatable.

1) decorate all your dataobjects to have the (hidden) field for the relevant subsite
2) agument all SQL to get those relevant to the current subsite
3) do somethign like to the Model admin

Hope this helps


12 September 2013 at 1:09pm (Last edited: 12 September 2013 1:14pm), Moderator, 3 Posts

This works for me:

On the model(s)

private static $has_one = array(


public function getCMSFields() {
      $fields = parent::getCMSFields();
      $fields->push(new HiddenField('SubsiteID','SubsiteID', Subsite::currentSubsiteID()));
      return $fields;

On the ModelAdmin:

public function getEditForm($id = null, $fields = null){
      $form = parent::getEditForm($id, $fields);
      $gridField = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass));
      $list = $gridField->getList()->filter(array('SubsiteID'=>Subsite::currentSubsiteID()));

      return $form;

There might be edge cases I haven't tested for though. And it should probably check for the existence of subsites.