|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\Subsites\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Admin\LeftAndMain; |
|
6
|
|
|
use SilverStripe\Security\Member; |
|
7
|
|
|
use SilverStripe\Security\Permission; |
|
8
|
|
|
use SilverStripe\Subsites\Model\Subsite; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Section-agnostic PJAX controller. |
|
12
|
|
|
*/ |
|
13
|
|
|
class SubsiteXHRController extends LeftAndMain |
|
14
|
|
|
{ |
|
15
|
|
|
private static $url_segment = 'subsite_xhr'; |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
private static $ignore_menuitem = true; |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Relax the access permissions, so anyone who has access to any CMS subsite can access this controller. |
|
21
|
|
|
* @param Member|null $member |
|
22
|
|
|
* @return bool |
|
23
|
|
|
*/ |
|
24
|
|
|
public function canView($member = null) |
|
25
|
|
|
{ |
|
26
|
|
|
if (parent::canView($member)) { |
|
27
|
|
|
return true; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
if (Subsite::all_accessible_sites()->count() > 0) { |
|
31
|
|
|
return true; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
return false; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Allow access if user allowed into the CMS at all. |
|
39
|
|
|
*/ |
|
40
|
|
|
public function canAccess() |
|
41
|
|
|
{ |
|
42
|
|
|
// Allow if any cms access is available |
|
43
|
|
|
return Permission::check([ |
|
44
|
|
|
'CMS_ACCESS', // Supported by 3.1.14 and up |
|
45
|
|
|
'CMS_ACCESS_LeftAndMain' |
|
46
|
|
|
]); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function getResponseNegotiator() |
|
50
|
|
|
{ |
|
51
|
|
|
$negotiator = parent::getResponseNegotiator(); |
|
52
|
|
|
|
|
53
|
|
|
// Register a new callback |
|
54
|
|
|
$negotiator->setCallback('SubsiteList', function () { |
|
55
|
|
|
return $this->SubsiteList(); |
|
56
|
|
|
}); |
|
57
|
|
|
|
|
58
|
|
|
return $negotiator; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Provide the list of available subsites as a cms-section-agnostic PJAX handler. |
|
63
|
|
|
*/ |
|
64
|
|
|
public function SubsiteList() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->renderWith(['type' => 'Includes', self::class . '_subsitelist']); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|