2007-08-16 08:38:29 +02:00
|
|
|
<?php
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2017-04-23 22:23:34 +02:00
|
|
|
namespace SilverStripe\Subsites\Extensions;
|
|
|
|
|
2017-08-30 05:29:13 +02:00
|
|
|
use SilverStripe\Admin\AdminRootController;
|
2017-04-23 22:23:34 +02:00
|
|
|
use SilverStripe\Admin\CMSMenu;
|
2017-08-30 01:06:07 +02:00
|
|
|
use SilverStripe\Admin\LeftAndMainExtension;
|
2018-01-30 04:21:45 +01:00
|
|
|
use SilverStripe\CMS\Controllers\CMSPagesController;
|
2017-04-23 22:23:34 +02:00
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
2017-09-05 03:48:28 +02:00
|
|
|
use SilverStripe\CMS\Controllers\CMSPageEditController;
|
2017-04-23 22:23:34 +02:00
|
|
|
use SilverStripe\Control\Controller;
|
2017-06-01 15:56:28 +02:00
|
|
|
use SilverStripe\Core\Config\Config;
|
2016-09-22 16:38:29 +02:00
|
|
|
use SilverStripe\Core\Convert;
|
|
|
|
use SilverStripe\Forms\HiddenField;
|
|
|
|
use SilverStripe\ORM\ArrayList;
|
|
|
|
use SilverStripe\ORM\DataObject;
|
2017-04-23 22:23:34 +02:00
|
|
|
use SilverStripe\Security\Member;
|
2016-09-22 16:38:29 +02:00
|
|
|
use SilverStripe\Security\Permission;
|
|
|
|
use SilverStripe\Security\Security;
|
2017-06-04 04:30:51 +02:00
|
|
|
use SilverStripe\Subsites\Controller\SubsiteXHRController;
|
2017-04-23 22:23:34 +02:00
|
|
|
use SilverStripe\Subsites\Model\Subsite;
|
2017-08-30 01:06:07 +02:00
|
|
|
use SilverStripe\Subsites\State\SubsiteState;
|
2017-04-23 22:23:34 +02:00
|
|
|
use SilverStripe\View\ArrayData;
|
|
|
|
use SilverStripe\View\Requirements;
|
|
|
|
|
2007-08-16 08:38:29 +02:00
|
|
|
/**
|
|
|
|
* Decorator designed to add subsites support to LeftAndMain
|
2013-10-16 02:25:06 +02:00
|
|
|
*
|
2008-11-24 04:22:01 +01:00
|
|
|
* @package subsites
|
2007-08-16 08:38:29 +02:00
|
|
|
*/
|
2017-08-30 01:06:07 +02:00
|
|
|
class LeftAndMainSubsites extends LeftAndMainExtension
|
2017-05-24 15:26:28 +02:00
|
|
|
{
|
2017-06-01 15:56:28 +02:00
|
|
|
private static $allowed_actions = ['CopyToSubsite'];
|
2017-05-24 15:26:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Normally SubsiteID=0 on a DataObject means it is only accessible from the special "main site".
|
|
|
|
* However in some situations SubsiteID=0 will be understood as a "globally accessible" object in which
|
|
|
|
* case this property is set to true (i.e. in AssetAdmin).
|
|
|
|
*/
|
|
|
|
private static $treats_subsite_0_as_global = false;
|
|
|
|
|
2017-05-29 13:42:42 +02:00
|
|
|
public function init()
|
2017-05-24 15:26:28 +02:00
|
|
|
{
|
2017-12-04 03:26:17 +01:00
|
|
|
Requirements::css('silverstripe/subsites:css/LeftAndMain_Subsites.css');
|
|
|
|
Requirements::javascript('silverstripe/subsites:javascript/LeftAndMain_Subsites.js');
|
|
|
|
Requirements::javascript('silverstripe/subsites:javascript/VirtualPage_Subsites.js');
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the title of the CMS tree
|
|
|
|
*/
|
2017-05-29 13:42:42 +02:00
|
|
|
public function getCMSTreeTitle()
|
2017-05-24 15:26:28 +02:00
|
|
|
{
|
2017-06-01 14:44:09 +02:00
|
|
|
$subsite = Subsite::currentSubsite();
|
2017-09-26 03:49:05 +02:00
|
|
|
return $subsite ? Convert::raw2xml($subsite->Title) : _t(__CLASS__.'.SITECONTENTLEFT', 'Site Content');
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
|
|
|
|
2017-05-29 13:42:42 +02:00
|
|
|
public function updatePageOptions(&$fields)
|
2017-05-24 15:26:28 +02:00
|
|
|
{
|
2017-08-30 01:06:07 +02:00
|
|
|
$fields->push(HiddenField::create('SubsiteID', 'SubsiteID', SubsiteState::singleton()->getSubsiteId()));
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find all subsites accessible for current user on this controller.
|
|
|
|
*
|
2017-06-01 15:10:07 +02:00
|
|
|
* @param bool $includeMainSite
|
|
|
|
* @param string $mainSiteTitle
|
|
|
|
* @param null $member
|
|
|
|
* @return ArrayList of <a href='psi_element://Subsite'>Subsite</a> instances.
|
|
|
|
* instances.
|
2017-05-24 15:26:28 +02:00
|
|
|
*/
|
2017-06-01 14:49:55 +02:00
|
|
|
public function sectionSites($includeMainSite = true, $mainSiteTitle = 'Main site', $member = null)
|
2017-05-24 15:26:28 +02:00
|
|
|
{
|
|
|
|
if ($mainSiteTitle == 'Main site') {
|
|
|
|
$mainSiteTitle = _t('Subsites.MainSiteTitle', 'Main site');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rationalise member arguments
|
|
|
|
if (!$member) {
|
2017-08-30 02:04:43 +02:00
|
|
|
$member = Security::getCurrentUser();
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
|
|
|
if (!$member) {
|
2017-08-30 02:04:43 +02:00
|
|
|
return ArrayList::create();
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
|
|
|
if (!is_object($member)) {
|
2017-05-29 13:42:42 +02:00
|
|
|
$member = DataObject::get_by_id(Member::class, $member);
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Collect permissions - honour the LeftAndMain::required_permission_codes, current model requires
|
|
|
|
// us to check if the user satisfies ALL permissions. Code partly copied from LeftAndMain::canView.
|
2017-06-01 15:56:28 +02:00
|
|
|
$codes = [];
|
2017-08-30 02:04:43 +02:00
|
|
|
$extraCodes = Config::inst()->get(get_class($this->owner), 'required_permission_codes');
|
2017-05-24 15:26:28 +02:00
|
|
|
if ($extraCodes !== false) {
|
|
|
|
if ($extraCodes) {
|
|
|
|
$codes = array_merge($codes, (array)$extraCodes);
|
|
|
|
} else {
|
2017-08-30 02:04:43 +02:00
|
|
|
$codes[] = sprintf('CMS_ACCESS_%s', get_class($this->owner));
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Check overriden - all subsites accessible.
|
|
|
|
return Subsite::all_sites();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find subsites satisfying all permissions for the Member.
|
2017-06-01 15:56:28 +02:00
|
|
|
$codesPerSite = [];
|
|
|
|
$sitesArray = [];
|
2017-05-24 15:26:28 +02:00
|
|
|
foreach ($codes as $code) {
|
|
|
|
$sites = Subsite::accessible_sites($code, $includeMainSite, $mainSiteTitle, $member);
|
|
|
|
foreach ($sites as $site) {
|
|
|
|
// Build the structure for checking how many codes match.
|
|
|
|
$codesPerSite[$site->ID][$code] = true;
|
|
|
|
|
|
|
|
// Retain Subsite objects for later.
|
|
|
|
$sitesArray[$site->ID] = $site;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find sites that satisfy all codes conjuncitvely.
|
|
|
|
$accessibleSites = new ArrayList();
|
|
|
|
foreach ($codesPerSite as $siteID => $siteCodes) {
|
2017-06-01 15:56:28 +02:00
|
|
|
if (count($siteCodes) == count($codes)) {
|
2017-05-24 15:26:28 +02:00
|
|
|
$accessibleSites->push($sitesArray[$siteID]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $accessibleSites;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns a list of the subsites accessible to the current user.
|
|
|
|
* It's enough for any section to be accessible for the section to be included.
|
|
|
|
*/
|
|
|
|
public function Subsites()
|
|
|
|
{
|
|
|
|
return Subsite::all_accessible_sites();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generates a list of subsites with the data needed to
|
|
|
|
* produce a dropdown site switcher
|
|
|
|
* @return ArrayList
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function ListSubsites()
|
|
|
|
{
|
|
|
|
$list = $this->Subsites();
|
2017-08-30 01:06:07 +02:00
|
|
|
$currentSubsiteID = SubsiteState::singleton()->getSubsiteId();
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2017-06-01 14:44:09 +02:00
|
|
|
if ($list == null || $list->count() == 1 && $list->first()->DefaultSite == true) {
|
2017-05-24 15:26:28 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-04 03:26:17 +01:00
|
|
|
Requirements::javascript('silverstripe/subsites:javascript/LeftAndMain_Subsites.js');
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2017-08-30 05:29:13 +02:00
|
|
|
$output = ArrayList::create();
|
2017-05-24 15:26:28 +02:00
|
|
|
|
|
|
|
foreach ($list as $subsite) {
|
2017-08-30 05:29:13 +02:00
|
|
|
$currentState = $subsite->ID == $currentSubsiteID ? 'selected' : '';
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2017-08-30 05:29:13 +02:00
|
|
|
$output->push(ArrayData::create([
|
|
|
|
'CurrentState' => $currentState,
|
2017-05-24 15:26:28 +02:00
|
|
|
'ID' => $subsite->ID,
|
2018-06-19 03:47:15 +02:00
|
|
|
'Title' => $subsite->Title,
|
2017-06-01 15:56:28 +02:00
|
|
|
]));
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function alternateMenuDisplayCheck($controllerName)
|
|
|
|
{
|
|
|
|
if (!class_exists($controllerName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-06-04 04:30:51 +02:00
|
|
|
// Don't display SubsiteXHRController
|
2017-08-30 05:29:13 +02:00
|
|
|
if (singleton($controllerName) instanceof SubsiteXHRController) {
|
2017-06-04 04:30:51 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-24 15:26:28 +02:00
|
|
|
// Check subsite support.
|
2017-08-30 01:06:07 +02:00
|
|
|
if (SubsiteState::singleton()->getSubsiteId() == 0) {
|
2017-05-24 15:26:28 +02:00
|
|
|
// Main site always supports everything.
|
|
|
|
return true;
|
2017-06-01 15:07:13 +02:00
|
|
|
}
|
|
|
|
|
2017-05-24 15:26:28 +02:00
|
|
|
// It's not necessary to check access permissions here. Framework calls canView on the controller,
|
|
|
|
// which in turn uses the Permission API which is augmented by our GroupSubsites.
|
2017-06-01 15:48:01 +02:00
|
|
|
$controller = singleton($controllerName);
|
|
|
|
return $controller->hasMethod('subsiteCMSShowInMenu') && $controller->subsiteCMSShowInMenu();
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function CanAddSubsites()
|
|
|
|
{
|
2017-06-01 14:49:55 +02:00
|
|
|
return Permission::check('ADMIN', 'any', null, 'all');
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for testing if the subsite should be adjusted.
|
2017-08-30 01:06:07 +02:00
|
|
|
* @param string $adminClass
|
|
|
|
* @param int $recordSubsiteID
|
|
|
|
* @param int $currentSubsiteID
|
2017-06-01 15:10:07 +02:00
|
|
|
* @return bool
|
2017-05-24 15:26:28 +02:00
|
|
|
*/
|
|
|
|
public function shouldChangeSubsite($adminClass, $recordSubsiteID, $currentSubsiteID)
|
|
|
|
{
|
2017-06-01 15:56:28 +02:00
|
|
|
if (Config::inst()->get($adminClass, 'treats_subsite_0_as_global') && $recordSubsiteID == 0) {
|
2017-05-24 15:26:28 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-06-01 15:56:28 +02:00
|
|
|
if ($recordSubsiteID != $currentSubsiteID) {
|
2017-05-24 15:26:28 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the current controller is accessible for this user on this subsite.
|
|
|
|
*/
|
2017-05-29 13:42:42 +02:00
|
|
|
public function canAccess()
|
2017-05-24 15:26:28 +02:00
|
|
|
{
|
|
|
|
// Admin can access everything, no point in checking.
|
2017-08-30 02:04:43 +02:00
|
|
|
$member = Security::getCurrentUser();
|
2017-09-04 01:45:21 +02:00
|
|
|
if ($member
|
|
|
|
&& (Permission::checkMember($member, 'ADMIN') // 'Full administrative rights'
|
|
|
|
|| Permission::checkMember($member, 'CMS_ACCESS_LeftAndMain') // 'Access to all CMS sections'
|
|
|
|
)
|
|
|
|
) {
|
2017-05-24 15:26:28 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we have access to current section on the current subsite.
|
2017-06-01 14:49:55 +02:00
|
|
|
$accessibleSites = $this->owner->sectionSites(true, 'Main site', $member);
|
2017-08-30 01:06:07 +02:00
|
|
|
return $accessibleSites->count() && $accessibleSites->find('ID', SubsiteState::singleton()->getSubsiteId());
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prevent accessing disallowed resources. This happens after onBeforeInit has executed,
|
|
|
|
* so all redirections should've already taken place.
|
|
|
|
*/
|
|
|
|
public function alternateAccessCheck()
|
|
|
|
{
|
|
|
|
return $this->owner->canAccess();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redirect the user to something accessible if the current section/subsite is forbidden.
|
|
|
|
*
|
|
|
|
* This is done via onBeforeInit as it needs to be done before the LeftAndMain::init has a
|
|
|
|
* chance to forbids access via alternateAccessCheck.
|
|
|
|
*
|
|
|
|
* If we need to change the subsite we force the redirection to /admin/ so the frontend is
|
|
|
|
* fully re-synchronised with the internal session. This is better than risking some panels
|
|
|
|
* showing data from another subsite.
|
|
|
|
*/
|
|
|
|
public function onBeforeInit()
|
|
|
|
{
|
2017-08-30 02:04:43 +02:00
|
|
|
$request = Controller::curr()->getRequest();
|
|
|
|
$session = $request->getSession();
|
2017-07-25 04:25:58 +02:00
|
|
|
|
2017-09-04 01:45:21 +02:00
|
|
|
$state = SubsiteState::singleton();
|
|
|
|
|
2017-05-24 15:26:28 +02:00
|
|
|
// FIRST, check if we need to change subsites due to the URL.
|
|
|
|
|
|
|
|
// Catch forced subsite changes that need to cause CMS reloads.
|
2017-08-30 05:29:13 +02:00
|
|
|
if ($request->getVar('SubsiteID') !== null) {
|
2017-05-24 15:26:28 +02:00
|
|
|
// Clear current page when subsite changes (or is set for the first time)
|
2017-09-05 03:48:28 +02:00
|
|
|
if ($state->getSubsiteIdWasChanged()) {
|
2017-09-05 02:07:49 +02:00
|
|
|
// sessionNamespace() is protected - see for info
|
|
|
|
$override = $this->owner->config()->get('session_namespace');
|
|
|
|
$sessionNamespace = $override ? $override : get_class($this->owner);
|
|
|
|
$session->clear($sessionNamespace . '.currentPage');
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
|
|
|
|
2018-01-30 04:21:45 +01:00
|
|
|
// Context: Subsite ID has already been set to the state via InitStateMiddleware
|
|
|
|
|
|
|
|
// If the user cannot view the current page, redirect to the admin landing section
|
|
|
|
if (!$this->owner->canView()) {
|
2017-09-05 03:48:28 +02:00
|
|
|
return $this->owner->redirect(AdminRootController::config()->get('url_base') . '/');
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
2017-09-05 03:48:28 +02:00
|
|
|
|
2018-01-30 04:21:45 +01:00
|
|
|
$currentController = Controller::curr();
|
|
|
|
if ($currentController instanceof CMSPageEditController) {
|
|
|
|
/** @var SiteTree $page */
|
|
|
|
$page = $currentController->currentPage();
|
|
|
|
|
|
|
|
// If the page exists but doesn't belong to the requested subsite, redirect to admin/pages which
|
|
|
|
// will show a list of the requested subsite's pages
|
|
|
|
$currentSubsiteId = $request->getVar('SubsiteID');
|
|
|
|
if ($page && (int) $page->SubsiteID !== (int) $currentSubsiteId) {
|
|
|
|
return $this->owner->redirect(CMSPagesController::singleton()->Link());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Page does belong to the current subsite, so remove the query string parameter and refresh the page
|
|
|
|
// Remove the subsiteID parameter and redirect back to the current URL again
|
|
|
|
$request->offsetSet('SubsiteID', null);
|
|
|
|
return $this->owner->redirect($request->getURL(true));
|
|
|
|
}
|
|
|
|
|
2018-02-07 12:22:31 +01:00
|
|
|
// Redirect back to the default admin URL
|
|
|
|
return $this->owner->redirect($request->getURL());
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Automatically redirect the session to appropriate subsite when requesting a record.
|
|
|
|
// This is needed to properly initialise the session in situations where someone opens the CMS via a link.
|
|
|
|
$record = $this->owner->currentPage();
|
2017-06-01 15:56:28 +02:00
|
|
|
if ($record
|
|
|
|
&& isset($record->SubsiteID, $this->owner->urlParams['ID'])
|
|
|
|
&& is_numeric($record->SubsiteID)
|
2017-08-30 01:06:07 +02:00
|
|
|
&& $this->shouldChangeSubsite(
|
2017-08-30 02:04:43 +02:00
|
|
|
get_class($this->owner),
|
2017-08-30 01:06:07 +02:00
|
|
|
$record->SubsiteID,
|
|
|
|
SubsiteState::singleton()->getSubsiteId()
|
|
|
|
)
|
2017-06-01 15:56:28 +02:00
|
|
|
) {
|
2017-09-04 01:45:21 +02:00
|
|
|
// Update current subsite
|
|
|
|
$canViewElsewhere = SubsiteState::singleton()->withState(function ($newState) use ($record) {
|
|
|
|
$newState->setSubsiteId($record->SubsiteID);
|
|
|
|
|
2018-01-30 04:21:45 +01:00
|
|
|
return (bool) $this->owner->canView(Security::getCurrentUser());
|
2017-09-04 01:45:21 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if ($canViewElsewhere) {
|
|
|
|
// Redirect to clear the current page
|
|
|
|
return $this->owner->redirect(
|
2017-09-05 02:07:49 +02:00
|
|
|
Controller::join_links($this->owner->Link('show'), $record->ID, '?SubsiteID=' . $record->SubsiteID)
|
2017-09-04 01:45:21 +02:00
|
|
|
);
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
2017-09-04 01:45:21 +02:00
|
|
|
// Redirect to the default CMS section
|
|
|
|
return $this->owner->redirect(AdminRootController::config()->get('url_base') . '/');
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// SECOND, check if we need to change subsites due to lack of permissions.
|
|
|
|
|
|
|
|
if (!$this->owner->canAccess()) {
|
2017-08-30 02:04:43 +02:00
|
|
|
$member = Security::getCurrentUser();
|
2017-05-24 15:26:28 +02:00
|
|
|
|
|
|
|
// Current section is not accessible, try at least to stick to the same subsite.
|
|
|
|
$menu = CMSMenu::get_menu_items();
|
|
|
|
foreach ($menu as $candidate) {
|
2017-08-30 02:04:43 +02:00
|
|
|
if ($candidate->controller && $candidate->controller != get_class($this->owner)) {
|
2017-05-24 15:26:28 +02:00
|
|
|
$accessibleSites = singleton($candidate->controller)->sectionSites(true, 'Main site', $member);
|
2017-08-30 01:06:07 +02:00
|
|
|
if ($accessibleSites->count()
|
|
|
|
&& $accessibleSites->find('ID', SubsiteState::singleton()->getSubsiteId())
|
|
|
|
) {
|
2017-05-24 15:26:28 +02:00
|
|
|
// Section is accessible, redirect there.
|
|
|
|
return $this->owner->redirect(singleton($candidate->controller)->Link());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no section is available, look for other accessible subsites.
|
|
|
|
foreach ($menu as $candidate) {
|
|
|
|
if ($candidate->controller) {
|
|
|
|
$accessibleSites = singleton($candidate->controller)->sectionSites(true, 'Main site', $member);
|
|
|
|
if ($accessibleSites->count()) {
|
|
|
|
Subsite::changeSubsite($accessibleSites->First()->ID);
|
|
|
|
return $this->owner->redirect(singleton($candidate->controller)->Link());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have not found any accessible section or subsite. User should be denied access.
|
|
|
|
return Security::permissionFailure($this->owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Current site is accessible. Allow through.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-29 13:42:42 +02:00
|
|
|
public function augmentNewSiteTreeItem(&$item)
|
2017-05-24 15:26:28 +02:00
|
|
|
{
|
2017-08-30 02:04:43 +02:00
|
|
|
$request = Controller::curr()->getRequest();
|
|
|
|
$item->SubsiteID = $request->postVar('SubsiteID') ?: SubsiteState::singleton()->getSubsiteId();
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
|
|
|
|
2017-05-29 13:42:42 +02:00
|
|
|
public function onAfterSave($record)
|
2017-05-24 15:26:28 +02:00
|
|
|
{
|
|
|
|
if ($record->hasMethod('NormalRelated') && ($record->NormalRelated() || $record->ReverseRelated())) {
|
2017-08-29 07:07:24 +02:00
|
|
|
$this->owner->response->addHeader(
|
|
|
|
'X-Status',
|
2017-09-07 06:38:20 +02:00
|
|
|
rawurlencode(_t(__CLASS__ . '.Saved', 'Saved, please update related pages.'))
|
2017-08-29 07:07:24 +02:00
|
|
|
);
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-29 07:07:24 +02:00
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
* @param Form $form
|
|
|
|
*/
|
2015-11-23 04:53:45 +01:00
|
|
|
public function copytosubsite($data, $form)
|
2017-05-24 15:26:28 +02:00
|
|
|
{
|
2017-08-30 02:04:43 +02:00
|
|
|
$page = DataObject::get_by_id(SiteTree::class, $data['ID']);
|
|
|
|
$subsite = DataObject::get_by_id(Subsite::class, $data['CopyToSubsiteID']);
|
2016-07-18 06:27:54 +02:00
|
|
|
$includeChildren = (isset($data['CopyToSubsiteWithChildren'])) ? $data['CopyToSubsiteWithChildren'] : false;
|
2017-05-29 13:42:42 +02:00
|
|
|
|
|
|
|
$newPage = $page->duplicateToSubsite($subsite->ID, $includeChildren);
|
2017-05-24 15:26:28 +02:00
|
|
|
$response = $this->owner->getResponse();
|
|
|
|
$response->addHeader('X-Reload', true);
|
2007-08-16 08:38:29 +02:00
|
|
|
|
2017-05-29 13:42:42 +02:00
|
|
|
return $this->owner->redirect(Controller::join_links(
|
|
|
|
$this->owner->Link('show'),
|
|
|
|
$newPage->ID
|
|
|
|
));
|
|
|
|
}
|
2013-04-25 19:29:56 +02:00
|
|
|
}
|