silverstripe-subsites/code/forms/SubsitesTreeDropdownField.php
Werner M. Krauß a4a1ab6a78 formatting code
2017-06-01 15:57:53 +02:00

59 lines
1.2 KiB
PHP

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