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