1 <?php
2
3 4 5
6 class DataObjectSubsites extends DataObjectDecorator {
7 function () {
8 return array(
9 'has_one' => array(
10 'Subsite' => 'Subsite',
11 )
12 );
13 }
14
15 public function updateCMSFields(FieldSet &$fields) {
16 $fields->addFieldToTab('Root.Main', new HiddenField('SubsiteID', 'SubsiteID', $this->owner->SubsiteID));
17 }
18
19 20 21
22 function augmentSQL(SQLQuery &$query) {
23 if(Subsite::$disable_subsite_filter) return;
24
25
26 $tableName = array_shift(array_keys($query->from));
27 if($tableName != $this->owner->ClassName) return;
28 $subsiteID = (int)Subsite::currentSubsiteID();
29 $query->where[] = "\"$tableName\".\"SubsiteID\" IN ($subsiteID)";
30
31 }
32
33 function onBeforeWrite() {
34 if((!is_numeric($this->owner->ID) || !$this->owner->ID) && !$this->owner->SubsiteID) $this->owner->SubsiteID = Subsite::currentSubsiteID();
35 }
36
37 38 39
40 function cacheKeyComponent() {
41 return 'subsite-'.Subsite::currentSubsiteID();
42 }
43 }
44
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-