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-05-24 12:32:05 +02:00
|
|
|
use SilverStripe\Subsites\Model\Subsite;
|
|
|
|
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2013-10-16 02:20:54 +02:00
|
|
|
/**
|
|
|
|
* Section-agnostic PJAX controller.
|
|
|
|
*/
|
|
|
|
class SubsiteXHRController extends LeftAndMain {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Relax the access permissions, so anyone who has access to any CMS subsite can access this controller.
|
|
|
|
*/
|
|
|
|
public function canView($member = null) {
|
|
|
|
if (parent::canView()) return true;
|
|
|
|
|
|
|
|
if (Subsite::all_accessible_sites()->count()>0) return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-04 05:22:00 +01:00
|
|
|
/**
|
|
|
|
* Similar as above, but for the LeftAndMainSubsites - allow access if user allowed into the CMS at all.
|
|
|
|
*/
|
|
|
|
public function canAccess() {
|
|
|
|
if (Subsite::all_accessible_sites()->count()>0) return true;
|
|
|
|
}
|
|
|
|
|
2013-10-16 02:20:54 +02:00
|
|
|
public function getResponseNegotiator() {
|
|
|
|
$negotiator = parent::getResponseNegotiator();
|
|
|
|
$self = $this;
|
|
|
|
|
|
|
|
// Register a new callback
|
|
|
|
$negotiator->setCallback('SubsiteList', function() use(&$self) {
|
|
|
|
return $self->SubsiteList();
|
|
|
|
});
|
|
|
|
|
|
|
|
return $negotiator;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provide the list of available subsites as a cms-section-agnostic PJAX handler.
|
|
|
|
*/
|
|
|
|
public function SubsiteList() {
|
2016-09-22 16:38:29 +02:00
|
|
|
return $this->renderWith('Includes/SubsiteList');
|
2013-10-16 02:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|