Bring session / validation calls in line with SS4b1 API, replace icon.

This commit is contained in:
Garion Herman 2017-07-25 14:25:58 +12:00
parent 438836bfcc
commit 5ec1c94410
4 changed files with 17 additions and 20 deletions

View File

@ -15,14 +15,13 @@ use SilverStripe\Subsites\Model\Subsite;
*/ */
class SubsiteAdmin extends ModelAdmin class SubsiteAdmin extends ModelAdmin
{ {
private static $managed_models = [Subsite::class]; private static $managed_models = [Subsite::class];
private static $url_segment = 'subsites'; private static $url_segment = 'subsites';
private static $menu_title = '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; public $showImportForm = false;
@ -40,5 +39,4 @@ class SubsiteAdmin extends ModelAdmin
return $form; return $form;
} }
} }

View File

@ -257,13 +257,15 @@ class LeftAndMainSubsites extends Extension
// We are accessing the CMS, so we need to let Subsites know we will be using the session. // We are accessing the CMS, so we need to let Subsites know we will be using the session.
Subsite::$use_session_subsiteid = true; Subsite::$use_session_subsiteid = true;
$session = Controller::curr()->getRequest()->getSession();
// FIRST, check if we need to change subsites due to the URL. // FIRST, check if we need to change subsites due to the URL.
// Catch forced subsite changes that need to cause CMS reloads. // Catch forced subsite changes that need to cause CMS reloads.
if (isset($_GET['SubsiteID'])) { if (isset($_GET['SubsiteID'])) {
// Clear current page when subsite changes (or is set for the first time) // Clear current page when subsite changes (or is set for the first time)
if (!Session::get('SubsiteID') || $_GET['SubsiteID'] != Session::get('SubsiteID')) { if (!$session->get('SubsiteID') || $_GET['SubsiteID'] != $session->get('SubsiteID')) {
Session::clear("{$this->owner->class}.currentPage"); $session->clear("{$this->owner->class}.currentPage");
} }
// Update current subsite in session // Update current subsite in session

View File

@ -4,6 +4,7 @@ namespace SilverStripe\Subsites\Model;
use SilverStripe\Admin\CMSMenu; use SilverStripe\Admin\CMSMenu;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
use SilverStripe\Control\Session; use SilverStripe\Control\Session;
use SilverStripe\Core\Convert; use SilverStripe\Core\Convert;
@ -154,7 +155,7 @@ class Subsite extends DataObject
if (isset($_GET['SubsiteID'])) { if (isset($_GET['SubsiteID'])) {
$id = (int)$_GET['SubsiteID']; $id = (int)$_GET['SubsiteID'];
} elseif (Subsite::$use_session_subsiteid) { } elseif (Subsite::$use_session_subsiteid) {
$id = Session::get('SubsiteID'); $id = Controller::curr()->getRequest()->getSession()->get('SubsiteID');
} }
if ($id === null) { if ($id === null) {
@ -184,7 +185,7 @@ class Subsite extends DataObject
$subsiteID = $subsite; $subsiteID = $subsite;
} }
Session::set('SubsiteID', (int)$subsiteID); Controller::curr()->getRequest()->getSession()->set('SubsiteID', (int)$subsiteID);
// Set locale // Set locale
if (is_object($subsite) && $subsite->Language !== '') { if (is_object($subsite) && $subsite->Language !== '') {
@ -677,7 +678,7 @@ class Subsite extends DataObject
new Tab( new Tab(
'Configuration', 'Configuration',
_t('Subsite.TabTitleConfig', '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 TextField('Title', $this->fieldLabel('Title'), $this->Title),
new HeaderField( new HeaderField(
@ -783,7 +784,7 @@ class Subsite extends DataObject
{ {
$result = parent::validate(); $result = parent::validate();
if (!$this->Title) { if (!$this->Title) {
$result->error(_t('Subsite.ValidateTitle', 'Please add a "Title"')); $result->addError(_t('Subsite.ValidateTitle', 'Please add a "Title"'));
} }
return $result; return $result;
} }
@ -855,14 +856,6 @@ class Subsite extends DataObject
return Director::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 * Javascript admin action to duplicate this subsite
* *

View File

@ -1,5 +1,7 @@
<div class="cms-menu cms-panel cms-panel-layout west" id="cms-menu" data-layout-type="border"> <div class="cms-mobile-menu-toggle-wrapper"></div>
<div class="cms-logo-header north">
<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_MenuLogo %>
<% include SilverStripe\\Admin\\LeftAndMain_MenuStatus %> <% include SilverStripe\\Admin\\LeftAndMain_MenuStatus %>
@ -8,7 +10,7 @@
<% end_if %> <% end_if %>
</div> </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 %> <% include SilverStripe\\Admin\\LeftAndMain_MenuList %>
</div> </div>
@ -16,3 +18,5 @@
<% include SilverStripe\\Admin\\LeftAndMain_MenuToggle %> <% include SilverStripe\\Admin\\LeftAndMain_MenuToggle %>
</div> </div>
</div> </div>
<button class="fill-height fill-width cms-menu-mobile-overlay" aria-controls="cms-menu" aria-expanded="false"></button>