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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

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

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

ModelAdmin with Subsite?!

Go to End

4 Posts   1702 Views


Community Member, 90 Posts

26 January 2011 at 10:31am

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.



Community Member, 173 Posts

7 June 2013 at 1:24am

Same here, has anybody a solution for that?


Forum Moderator, 1899 Posts

7 June 2013 at 3:44am


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


Moderator, 4 Posts

12 September 2013 at 1:09pm

Edited: 12/09/2013 1:14pm

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.