Skip to content

Commit

Permalink
Merge branch '3' into 4
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Extensions/LeftAndMainSubsites.php
  • Loading branch information
GuySartorelli committed Nov 14, 2024
2 parents 0080d43 + 11f4ebc commit 1a31282
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 25 deletions.
3 changes: 3 additions & 0 deletions src/Controller/SubsiteXHRController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Control\PjaxResponseNegotiator;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use SilverStripe\Subsites\Model\Subsite;
Expand Down Expand Up @@ -37,9 +38,11 @@ public function canView($member = null)

/**
* Allow access if user allowed into the CMS at all.
* @deprecated 3.4.0 Will be removed without equivalent functionality to replace it.
*/
public function canAccess()
{
Deprecation::noticeWithNoReplacment('3.4.0');
// Allow if any cms access is available
return Permission::check([
'CMS_ACCESS', // Supported by 3.1.14 and up
Expand Down
68 changes: 45 additions & 23 deletions src/Extensions/LeftAndMainSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Extension;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\HiddenField;
use SilverStripe\Model\List\ArrayList;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\SS_List;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use SilverStripe\Security\Security;
Expand All @@ -24,11 +26,12 @@
use SilverStripe\Subsites\State\SubsiteState;
use SilverStripe\Model\ArrayData;
use SilverStripe\View\Requirements;
use SilverStripe\View\TemplateGlobalProvider;

/**
* Decorator designed to add subsites support to LeftAndMain
*/
class LeftAndMainSubsites extends Extension
class LeftAndMainSubsites extends Extension implements TemplateGlobalProvider
{
private static $allowed_actions = ['CopyToSubsite'];

Expand All @@ -45,6 +48,44 @@ protected function onInit()
Requirements::javascript('silverstripe/subsites:client/dist/js/LeftAndMain_Subsites.js');
}

public static function get_template_global_variables()
{
return [
'SubsiteSwitchList',
];
}

/**
* Generates a list of subsites with the data needed to
* produce a dropdown site switcher
* @return SS_List<Subsite>
*/
public static function SubsiteSwitchList(): SS_List
{
$list = Subsite::all_accessible_sites();
$currentSubsiteID = SubsiteState::singleton()->getSubsiteId();

if ($list == null || $list->count() == 1 && $list->first()->DefaultSite == true) {
return false;
}

Requirements::javascript('silverstripe/subsites:client/dist/js/LeftAndMain_Subsites.js');

$output = ArrayList::create();

foreach ($list as $subsite) {
$currentState = $subsite->ID == $currentSubsiteID ? 'selected' : '';

$output->push(ArrayData::create([
'CurrentState' => $currentState,
'ID' => $subsite->ID,
'Title' => $subsite->Title,
]));
}

return $output;
}

/**
* Set the title of the CMS tree
*/
Expand Down Expand Up @@ -143,31 +184,12 @@ public function Subsites()
* Generates a list of subsites with the data needed to
* produce a dropdown site switcher
* @return ArrayList<Subsite>
* @deprecated 3.4.0 Will be removed without equivalent functionality to replace it.
*/
public function ListSubsites()
{
$list = $this->Subsites();
$currentSubsiteID = SubsiteState::singleton()->getSubsiteId();

if ($list == null || $list->count() == 1 && $list->first()->DefaultSite == true) {
return false;
}

Requirements::javascript('silverstripe/subsites:client/dist/js/LeftAndMain_Subsites.js');

$output = ArrayList::create();

foreach ($list as $subsite) {
$currentState = $subsite->ID == $currentSubsiteID ? 'selected' : '';

$output->push(ArrayData::create([
'CurrentState' => $currentState,
'ID' => $subsite->ID,
'Title' => $subsite->Title,
]));
}

return $output;
Deprecation::notice('3.4.0', 'Use SubsiteSwitchList() instead.');
return static::SubsiteSwitchList();
}

public function alternateMenuDisplayCheck($controllerName)
Expand Down
2 changes: 1 addition & 1 deletion templates/SilverStripe/Admin/LeftAndMain_Menu.ss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<% include SilverStripe\\Admin\\LeftAndMain_MenuLogo %>
<% include SilverStripe\\Admin\\LeftAndMain_MenuStatus %>

<% if $ListSubsites.Count > 1 %>
<% if $SubsiteSwitchList.Count > 1 %>
<% include SilverStripe\\Subsites\\Controller\\SubsiteXHRController_subsitelist %>
<% end_if %>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="cms-subsites" data-pjax-fragment="SubsiteList">
<div class="field dropdown">
<select id="SubsitesSelect">
<% loop $ListSubsites %>
<% loop $SubsiteSwitchList %>
<option value="$ID" $CurrentState>$Title</option>
<% end_loop %>
</select>
Expand Down

0 comments on commit 1a31282

Please sign in to comment.