silverstripe-subsites/code/forms/SubsitesTreeDropdownField.php
2016-09-23 09:34:23 +01:00

49 lines
1.0 KiB
PHP

<?php
use SilverStripe\View\Requirements;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\Session;
use SilverStripe\Forms\TreeDropdownField;
/**
* Wraps around a TreedropdownField to add ability for temporary
* switching of subsite sessions.
*
* @package subsites
*/
class SubsitesTreeDropdownField extends TreeDropdownField {
private static $allowed_actions = array(
'tree'
);
protected $subsiteID = 0;
protected $extraClasses = array('SubsitesTreeDropdownField');
function Field($properties = array()) {
$html = parent::Field($properties);
Requirements::javascript('subsites/javascript/SubsitesTreeDropdownField.js');
return $html;
}
function setSubsiteID($id) {
$this->subsiteID = $id;
}
function getSubsiteID() {
return $this->subsiteID;
}
function tree(HTTPRequest $request) {
$oldSubsiteID = Session::get('SubsiteID');
Session::set('SubsiteID', $this->subsiteID);
$results = parent::tree($request);
Session::set('SubsiteID', $oldSubsiteID);
return $results;
}
}