2013-10-16 02:20:54 +02:00
|
|
|
<?php
|
|
|
|
|
2017-05-24 12:32:05 +02:00
|
|
|
namespace SilverStripe\Subsites\Controller;
|
|
|
|
|
2016-09-22 16:38:29 +02:00
|
|
|
use SilverStripe\Admin\LeftAndMain;
|
2017-09-07 06:20:01 +02:00
|
|
|
use SilverStripe\Security\Member;
|
2017-05-29 13:44:19 +02:00
|
|
|
use SilverStripe\Security\Permission;
|
2017-05-24 12:32:05 +02:00
|
|
|
use SilverStripe\Subsites\Model\Subsite;
|
|
|
|
|
2013-10-16 02:20:54 +02:00
|
|
|
/**
|
|
|
|
* Section-agnostic PJAX controller.
|
|
|
|
*/
|
2017-05-24 15:26:28 +02:00
|
|
|
class SubsiteXHRController extends LeftAndMain
|
|
|
|
{
|
2017-06-04 04:30:51 +02:00
|
|
|
private static $url_segment = 'subsite_xhr';
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2017-08-30 05:29:13 +02:00
|
|
|
private static $ignore_menuitem = true;
|
|
|
|
|
2017-05-24 15:26:28 +02:00
|
|
|
/**
|
|
|
|
* Relax the access permissions, so anyone who has access to any CMS subsite can access this controller.
|
2017-09-07 06:20:01 +02:00
|
|
|
* @param Member|null $member
|
2017-06-01 15:10:07 +02:00
|
|
|
* @return bool
|
2017-05-24 15:26:28 +02:00
|
|
|
*/
|
|
|
|
public function canView($member = null)
|
|
|
|
{
|
2017-08-30 05:29:13 +02:00
|
|
|
if (parent::canView($member)) {
|
2017-05-24 15:26:28 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Subsite::all_accessible_sites()->count() > 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-05-29 13:44:19 +02:00
|
|
|
* Allow access if user allowed into the CMS at all.
|
2017-05-24 15:26:28 +02:00
|
|
|
*/
|
|
|
|
public function canAccess()
|
|
|
|
{
|
2017-06-01 15:57:53 +02:00
|
|
|
// Allow if any cms access is available
|
|
|
|
return Permission::check([
|
|
|
|
'CMS_ACCESS', // Supported by 3.1.14 and up
|
|
|
|
'CMS_ACCESS_LeftAndMain'
|
|
|
|
]);
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getResponseNegotiator()
|
|
|
|
{
|
|
|
|
$negotiator = parent::getResponseNegotiator();
|
|
|
|
|
|
|
|
// Register a new callback
|
2017-08-30 05:29:13 +02:00
|
|
|
$negotiator->setCallback('SubsiteList', function () {
|
|
|
|
return $this->SubsiteList();
|
2017-05-24 15:26:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
return $negotiator;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provide the list of available subsites as a cms-section-agnostic PJAX handler.
|
|
|
|
*/
|
|
|
|
public function SubsiteList()
|
|
|
|
{
|
2017-09-07 06:20:01 +02:00
|
|
|
return $this->renderWith(['type' => 'Includes', self::class . '_subsitelist']);
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
2013-10-16 02:20:54 +02:00
|
|
|
}
|