2012-03-25 18:35:01 +02:00
|
|
|
<?php
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2017-05-24 12:32:05 +02:00
|
|
|
namespace SilverStripe\Subsites\Forms;
|
|
|
|
|
|
|
|
|
2016-09-22 16:38:29 +02:00
|
|
|
use SilverStripe\View\Requirements;
|
|
|
|
use SilverStripe\Control\HTTPRequest;
|
|
|
|
use SilverStripe\Control\Session;
|
|
|
|
use SilverStripe\Forms\TreeDropdownField;
|
2017-05-24 12:32:05 +02:00
|
|
|
|
|
|
|
|
2012-03-25 18:35:01 +02:00
|
|
|
/**
|
|
|
|
* Wraps around a TreedropdownField to add ability for temporary
|
|
|
|
* switching of subsite sessions.
|
|
|
|
*
|
|
|
|
* @package subsites
|
|
|
|
*/
|
|
|
|
class SubsitesTreeDropdownField extends TreeDropdownField {
|
2013-07-10 15:31:39 +02:00
|
|
|
|
|
|
|
private static $allowed_actions = array(
|
|
|
|
'tree'
|
|
|
|
);
|
2012-03-25 18:35:01 +02:00
|
|
|
|
|
|
|
protected $subsiteID = 0;
|
|
|
|
|
|
|
|
protected $extraClasses = array('SubsitesTreeDropdownField');
|
|
|
|
|
2012-07-11 15:32:10 +02:00
|
|
|
function Field($properties = array()) {
|
|
|
|
$html = parent::Field($properties);
|
2012-03-25 18:35:01 +02:00
|
|
|
|
|
|
|
Requirements::javascript('subsites/javascript/SubsitesTreeDropdownField.js');
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setSubsiteID($id) {
|
|
|
|
$this->subsiteID = $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSubsiteID() {
|
|
|
|
return $this->subsiteID;
|
|
|
|
}
|
|
|
|
|
2016-09-22 16:38:29 +02:00
|
|
|
function tree(HTTPRequest $request) {
|
2012-03-25 18:35:01 +02:00
|
|
|
$oldSubsiteID = Session::get('SubsiteID');
|
|
|
|
Session::set('SubsiteID', $this->subsiteID);
|
|
|
|
|
|
|
|
$results = parent::tree($request);
|
|
|
|
|
|
|
|
Session::set('SubsiteID', $oldSubsiteID);
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
}
|