Version: current

     1 <?php
     2 /**
     3  * Wraps around a TreedropdownField to add ability for temporary
     4  * switching of subsite sessions.
     5  *
     6  * @package subsites
     7  */
     8 class SubsitesTreeDropdownField extends TreeDropdownField {
     9
    10     protected $subsiteID = 0;
    11
    12     protected $extraClasses = array('SubsitesTreeDropdownField');
    13
    14     function Field() {
    15         $html = parent::Field();
    16
    17         Requirements::javascript('subsites/javascript/SubsitesTreeDropdownField.js');
    18
    19         return $html;
    20     }
    21
    22     function setSubsiteID($id) {
    23         $this->subsiteID = $id;
    24     }
    25
    26     function getSubsiteID() {
    27         return $this->subsiteID;
    28     }
    29
    30     function gettree(SS_HTTPRequest $request) {
    31         $oldSubsiteID = Session::get('SubsiteID');
    32         Session::set('SubsiteID', $this->subsiteID);
    33
    34         $results = parent::tree($request);
    35
    36         Session::set('SubsiteID', $oldSubsiteID);
    37
    38         return $results;
    39     }
    40
    41     function getsubtree() {
    42         $oldSubsiteID = Session::get('SubsiteID');
    43         Session::set('SubsiteID', $this->subsiteID);
    44
    45         $results = parent::getsubtree();
    46
    47         Session::set('SubsiteID', $oldSubsiteID);
    48
    49         return $results;
    50     }
    51 }
    52 ?>

[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. -