mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
BUGFIX: Session var for active subsite out of sync with current subsite. Refs silverstripe/silverstripe-subsites#93.
This commit is contained in:
parent
ac507ddc7b
commit
7bf6e89320
@ -9,6 +9,10 @@ class LeftAndMainSubsites extends Extension {
|
||||
private static $allowed_actions = array('CopyToSubsite');
|
||||
|
||||
function init() {
|
||||
|
||||
//Use the session variable for current subsite in the CMS only
|
||||
Subsite::$use_session_subsiteid = true;
|
||||
|
||||
Requirements::css('subsites/css/LeftAndMain_Subsites.css');
|
||||
Requirements::javascript('subsites/javascript/LeftAndMain_Subsites.js');
|
||||
Requirements::javascript('subsites/javascript/VirtualPage_Subsites.js');
|
||||
|
@ -198,19 +198,9 @@ class SiteTreeSubsites extends DataExtension {
|
||||
* Called by ContentController::init();
|
||||
*/
|
||||
static function contentcontrollerInit($controller) {
|
||||
// Need to set the SubsiteID to null incase we've been in the CMS
|
||||
Session::set('SubsiteID', null);
|
||||
$subsite = Subsite::currentSubsite();
|
||||
if($subsite && $subsite->Theme) SSViewer::set_theme(Subsite::currentSubsite()->Theme);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by ModelAsController::init();
|
||||
*/
|
||||
static function modelascontrollerInit($controller) {
|
||||
// Need to set the SubsiteID to null incase we've been in the CMS
|
||||
Session::set('SubsiteID', null);
|
||||
}
|
||||
|
||||
function alternateAbsoluteLink() {
|
||||
// Generate the existing absolute URL and replace the domain with the subsite domain.
|
||||
|
@ -7,6 +7,15 @@
|
||||
*/
|
||||
class Subsite extends DataObject implements PermissionProvider {
|
||||
|
||||
/**
|
||||
* @var $use_session_subsiteid Boolean Set to TRUE when using the CMS and FALSE
|
||||
* when browsing the frontend of a website.
|
||||
*
|
||||
* @todo Remove flag once the Subsite CMS works without session state,
|
||||
* similarly to the Translatable module.
|
||||
*/
|
||||
public static $use_session_subsiteid = false;
|
||||
|
||||
/**
|
||||
* @var boolean $disable_subsite_filter If enabled, bypasses the query decoration
|
||||
* to limit DataObject::get*() calls to a specific subsite. Useful for debugging.
|
||||
@ -286,19 +295,25 @@ JS;
|
||||
* @return int ID of the current subsite instance
|
||||
*/
|
||||
static function currentSubsiteID() {
|
||||
if(isset($_GET['SubsiteID'])) $id = (int)$_GET['SubsiteID'];
|
||||
else $id = Session::get('SubsiteID');
|
||||
$id = NULL;
|
||||
|
||||
if(isset($_GET['SubsiteID'])) {
|
||||
$id = (int)$_GET['SubsiteID'];
|
||||
}
|
||||
else if (Subsite::$use_session_subsiteid) {
|
||||
$id = Session::get('SubsiteID');
|
||||
}
|
||||
|
||||
if($id === NULL) {
|
||||
$id = self::getSubsiteIDForDomain();
|
||||
Session::set('SubsiteID', $id);
|
||||
}
|
||||
|
||||
return (int)$id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch to another subsite.
|
||||
* Switch to another subsite through storing the subsite identifier in the current PHP session.
|
||||
* Only takes effect when {@link Subsite::$use_session_subsiteid} is set to TRUE.
|
||||
*
|
||||
* @param int|Subsite $subsite Either the ID of the subsite, or the subsite object itself
|
||||
*/
|
||||
|
@ -1,5 +1,12 @@
|
||||
<?php
|
||||
class BaseSubsiteTest extends SapphireTest {
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
Subsite::$use_session_subsiteid = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Avoid subsites filtering on fixture fetching.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user