Skip to content

Commit

Permalink
API Deprecate API that will be removed as a result of refactoring (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Nov 14, 2024
1 parent 1c65739 commit 11f4ebc
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\Control\Controller;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\HiddenField;
use SilverStripe\ORM\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,13 +26,14 @@
use SilverStripe\Subsites\State\SubsiteState;
use SilverStripe\View\ArrayData;
use SilverStripe\View\Requirements;
use SilverStripe\View\TemplateGlobalProvider;

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

Expand All @@ -47,6 +50,44 @@ public function init()
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 @@ -145,31 +186,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 11f4ebc

Please sign in to comment.