silverstripe-subsites/src/Forms/SubsitesTreeDropdownField.php

88 lines
2.0 KiB
PHP
Raw Normal View History

BUG: Modifying the module to work with SS 3.0 Replaced deprecated DataObjectDecorator with DataExtension Fixed hard crashes in the cms Updated to support new LeftAndMain template structure Made the subsites model admin functional Moved the LeftAndMain_Menu template up a directory so it overrides the core Fixed some errors caused by changes to the framework Re-organized the code folder Fixed permission issue causing to default to first subsite regardless if it is the default or not Fixed crashes on the subsite virtual page when creating/editing Removed toDropdownMap() calls replacing with map() Fixed the URLSegment field on subsites Fixed error when detecting subsite for a domain Improved styles on the subsite dropdown Updated LeftAndMain_Subsites.js to work with jQuery entwine Started porting the SubsitesTreeDropdownField.js to use jQuery entwine and work with the new TreeDropdownField.js Fixed issue causing crash when viewing a page who is linked to by a subsite virtual page Removed unused methods on SubsitesTreeDropdownField.js Re-added classes that were moved Fixed hard crash after saving caused by the many_many definition on SiteTreeSubsites Replaced deprecated DataObjectSet creation with ArrayList Compatibility fixes with SS 3.0 beta 2 Fixed crash in cms caused by no parameter being passed to the SubsiteReportWrapper constructor Proper fix for report wrapper Removed table list field in favor of a basic grid field Fixed updateCMSFields() for file subsites Migrated translations to yml Fixed issue causing the current page to not get cleared when changing subsites in the cms Fixed virtual page icon Fixed language files issue
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;
use SilverStripe\Control\Controller;
2016-09-22 16:38:29 +02:00
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Forms\TreeDropdownField;
use SilverStripe\Subsites\Model\Subsite;
2017-05-24 15:26:28 +02:00
use SilverStripe\View\Requirements;
use SilverStripe\Subsites\State\SubsiteState;
2017-05-24 12:32:05 +02:00
BUG: Modifying the module to work with SS 3.0 Replaced deprecated DataObjectDecorator with DataExtension Fixed hard crashes in the cms Updated to support new LeftAndMain template structure Made the subsites model admin functional Moved the LeftAndMain_Menu template up a directory so it overrides the core Fixed some errors caused by changes to the framework Re-organized the code folder Fixed permission issue causing to default to first subsite regardless if it is the default or not Fixed crashes on the subsite virtual page when creating/editing Removed toDropdownMap() calls replacing with map() Fixed the URLSegment field on subsites Fixed error when detecting subsite for a domain Improved styles on the subsite dropdown Updated LeftAndMain_Subsites.js to work with jQuery entwine Started porting the SubsitesTreeDropdownField.js to use jQuery entwine and work with the new TreeDropdownField.js Fixed issue causing crash when viewing a page who is linked to by a subsite virtual page Removed unused methods on SubsitesTreeDropdownField.js Re-added classes that were moved Fixed hard crash after saving caused by the many_many definition on SiteTreeSubsites Replaced deprecated DataObjectSet creation with ArrayList Compatibility fixes with SS 3.0 beta 2 Fixed crash in cms caused by no parameter being passed to the SubsiteReportWrapper constructor Proper fix for report wrapper Removed table list field in favor of a basic grid field Fixed updateCMSFields() for file subsites Migrated translations to yml Fixed issue causing the current page to not get cleared when changing subsites in the cms Fixed virtual page icon Fixed language files issue
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
*
BUG: Modifying the module to work with SS 3.0 Replaced deprecated DataObjectDecorator with DataExtension Fixed hard crashes in the cms Updated to support new LeftAndMain template structure Made the subsites model admin functional Moved the LeftAndMain_Menu template up a directory so it overrides the core Fixed some errors caused by changes to the framework Re-organized the code folder Fixed permission issue causing to default to first subsite regardless if it is the default or not Fixed crashes on the subsite virtual page when creating/editing Removed toDropdownMap() calls replacing with map() Fixed the URLSegment field on subsites Fixed error when detecting subsite for a domain Improved styles on the subsite dropdown Updated LeftAndMain_Subsites.js to work with jQuery entwine Started porting the SubsitesTreeDropdownField.js to use jQuery entwine and work with the new TreeDropdownField.js Fixed issue causing crash when viewing a page who is linked to by a subsite virtual page Removed unused methods on SubsitesTreeDropdownField.js Re-added classes that were moved Fixed hard crash after saving caused by the many_many definition on SiteTreeSubsites Replaced deprecated DataObjectSet creation with ArrayList Compatibility fixes with SS 3.0 beta 2 Fixed crash in cms caused by no parameter being passed to the SubsiteReportWrapper constructor Proper fix for report wrapper Removed table list field in favor of a basic grid field Fixed updateCMSFields() for file subsites Migrated translations to yml Fixed issue causing the current page to not get cleared when changing subsites in the cms Fixed virtual page icon Fixed language files issue
2012-03-25 18:35:01 +02:00
* @package subsites
*/
2017-05-24 15:26:28 +02:00
class SubsitesTreeDropdownField extends TreeDropdownField
{
2017-06-01 15:57:53 +02:00
private static $allowed_actions = [
2017-05-24 15:26:28 +02:00
'tree'
2017-06-01 15:57:53 +02:00
];
2017-05-24 13:36:04 +02:00
/**
* @var int
*/
protected $subsiteId = 0;
2017-05-24 13:36:04 +02:00
2017-09-07 07:01:49 +02:00
/**
* Extra HTML classes
*
* @skipUpgrade
* @var string[]
*/
2017-06-01 15:57:53 +02:00
protected $extraClasses = ['SubsitesTreeDropdownField'];
2017-05-24 13:36:04 +02:00
2017-06-01 15:57:53 +02:00
public function Field($properties = [])
2017-05-24 15:26:28 +02:00
{
$html = parent::Field($properties);
2017-05-24 13:36:04 +02:00
2022-07-19 08:35:15 +02:00
Requirements::javascript('silverstripe/subsites:client/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
/**
* Sets the subsite ID to use when generating the tree
*
* @param int $id
* @return $this
*/
public function setSubsiteId($id)
2017-05-24 15:26:28 +02:00
{
$this->subsiteId = $id;
return $this;
2017-05-24 15:26:28 +02:00
}
2017-05-24 13:36:04 +02:00
/**
* Get the subsite ID to use when generating the tree
*
* @return int
*/
public function getSubsiteId()
2017-05-24 15:26:28 +02:00
{
return $this->subsiteId;
2017-05-24 15:26:28 +02:00
}
2017-05-24 13:36:04 +02:00
/**
* Get the CMS tree with the provided subsite ID applied to the state
*
* {@inheritDoc}
*/
2017-05-29 13:42:42 +02:00
public function tree(HTTPRequest $request)
2017-05-24 15:26:28 +02:00
{
// Detect subsite ID from the request
if ($request->getVar($this->getName() . '_SubsiteID')) {
$this->setSubsiteId($request->getVar($this->getName() . '_SubsiteID'));
}
$results = SubsiteState::singleton()->withState(function (SubsiteState $newState) use ($request) {
$newState->setSubsiteId($this->getSubsiteId());
return parent::tree($request);
});
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
}