Skip to content

Commit

Permalink
Bring session / validation calls in line with SS4b1 API, replace icon.
Browse files Browse the repository at this point in the history
  • Loading branch information
Garion Herman committed Jul 25, 2017
1 parent 438836b commit 5ec1c94
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
4 changes: 1 addition & 3 deletions code/admin/SubsiteAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
*/
class SubsiteAdmin extends ModelAdmin
{

private static $managed_models = [Subsite::class];

private static $url_segment = 'subsites';

private static $menu_title = 'Subsites';

private static $menu_icon = 'subsites/images/subsites.png';
private static $menu_icon_class = 'font-icon-tree';

public $showImportForm = false;

Expand All @@ -40,5 +39,4 @@ public function getEditForm($id = null, $fields = null)

return $form;
}

}
6 changes: 4 additions & 2 deletions code/extensions/LeftAndMainSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,15 @@ public function onBeforeInit()
// We are accessing the CMS, so we need to let Subsites know we will be using the session.
Subsite::$use_session_subsiteid = true;

$session = Controller::curr()->getRequest()->getSession();

// FIRST, check if we need to change subsites due to the URL.

// Catch forced subsite changes that need to cause CMS reloads.
if (isset($_GET['SubsiteID'])) {
// Clear current page when subsite changes (or is set for the first time)
if (!Session::get('SubsiteID') || $_GET['SubsiteID'] != Session::get('SubsiteID')) {
Session::clear("{$this->owner->class}.currentPage");
if (!$session->get('SubsiteID') || $_GET['SubsiteID'] != $session->get('SubsiteID')) {
$session->clear("{$this->owner->class}.currentPage");
}

// Update current subsite in session
Expand Down
17 changes: 5 additions & 12 deletions code/model/Subsite.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use SilverStripe\Admin\CMSMenu;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Control\Session;
use SilverStripe\Core\Convert;
Expand Down Expand Up @@ -154,7 +155,7 @@ public static function currentSubsiteID()
if (isset($_GET['SubsiteID'])) {
$id = (int)$_GET['SubsiteID'];
} elseif (Subsite::$use_session_subsiteid) {
$id = Session::get('SubsiteID');
$id = Controller::curr()->getRequest()->getSession()->get('SubsiteID');
}

if ($id === null) {
Expand Down Expand Up @@ -184,7 +185,7 @@ public static function changeSubsite($subsite)
$subsiteID = $subsite;
}

Session::set('SubsiteID', (int)$subsiteID);
Controller::curr()->getRequest()->getSession()->set('SubsiteID', (int)$subsiteID);

// Set locale
if (is_object($subsite) && $subsite->Language !== '') {
Expand Down Expand Up @@ -677,7 +678,7 @@ public function getCMSFields()
new Tab(
'Configuration',
_t('Subsite.TabTitleConfig', 'Configuration'),
new HeaderField('ConfigForSubsiteHeaderField', $this->getClassName() . ' configuration'),
new HeaderField('ConfigForSubsiteHeaderField', 'Subsite Configuration'),
new TextField('Title', $this->fieldLabel('Title'), $this->Title),

new HeaderField(
Expand Down Expand Up @@ -783,7 +784,7 @@ public function validate()
{
$result = parent::validate();
if (!$this->Title) {
$result->error(_t('Subsite.ValidateTitle', 'Please add a "Title"'));
$result->addError(_t('Subsite.ValidateTitle', 'Please add a "Title"'));
}
return $result;
}
Expand Down Expand Up @@ -855,14 +856,6 @@ public function absoluteBaseURL()
return Director::absoluteBaseURL();
}

/**
* @todo getClassName is redundant, already stored as a database field?
*/
public function getClassName()
{
return $this->class;
}

/**
* Javascript admin action to duplicate this subsite
*
Expand Down
10 changes: 7 additions & 3 deletions templates/SilverStripe/Admin/LeftAndMain_Menu.ss
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<div class="cms-menu cms-panel cms-panel-layout west" id="cms-menu" data-layout-type="border">
<div class="cms-logo-header north">
<div class="cms-mobile-menu-toggle-wrapper"></div>

<div class="fill-height cms-menu cms-panel cms-panel-layout" id="cms-menu" data-layout-type="border" aria-expanded="false">
<div class="cms-menu__header">
<% include SilverStripe\\Admin\\LeftAndMain_MenuLogo %>
<% include SilverStripe\\Admin\\LeftAndMain_MenuStatus %>

Expand All @@ -8,11 +10,13 @@
<% end_if %>
</div>

<div class="panel panel--scrollable panel--triple-toolbar cms-panel-content">
<div class="flexbox-area-grow panel--scrollable panel--triple-toolbar cms-panel-content">
<% include SilverStripe\\Admin\\LeftAndMain_MenuList %>
</div>

<div class="toolbar toolbar--south cms-panel-toggle">
<% include SilverStripe\\Admin\\LeftAndMain_MenuToggle %>
</div>
</div>

<button class="fill-height fill-width cms-menu-mobile-overlay" aria-controls="cms-menu" aria-expanded="false"></button>

0 comments on commit 5ec1c94

Please sign in to comment.