diff --git a/src/Controller/SubsiteXHRController.php b/src/Controller/SubsiteXHRController.php index db344dcb..04840749 100644 --- a/src/Controller/SubsiteXHRController.php +++ b/src/Controller/SubsiteXHRController.php @@ -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; @@ -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 diff --git a/src/Extensions/LeftAndMainSubsites.php b/src/Extensions/LeftAndMainSubsites.php index c6a1b74a..08cf0daa 100644 --- a/src/Extensions/LeftAndMainSubsites.php +++ b/src/Extensions/LeftAndMainSubsites.php @@ -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; @@ -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']; @@ -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 + */ + 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 */ @@ -143,31 +184,12 @@ public function Subsites() * Generates a list of subsites with the data needed to * produce a dropdown site switcher * @return ArrayList + * @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) diff --git a/templates/SilverStripe/Admin/LeftAndMain_Menu.ss b/templates/SilverStripe/Admin/LeftAndMain_Menu.ss index 33be0ea1..095ce918 100644 --- a/templates/SilverStripe/Admin/LeftAndMain_Menu.ss +++ b/templates/SilverStripe/Admin/LeftAndMain_Menu.ss @@ -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 %> diff --git a/templates/SilverStripe/Subsites/Controller/Includes/SubsiteXHRController_subsitelist.ss b/templates/SilverStripe/Subsites/Controller/Includes/SubsiteXHRController_subsitelist.ss index 3b3960f6..8bf6693f 100644 --- a/templates/SilverStripe/Subsites/Controller/Includes/SubsiteXHRController_subsitelist.ss +++ b/templates/SilverStripe/Subsites/Controller/Includes/SubsiteXHRController_subsitelist.ss @@ -1,7 +1,7 @@