2009-10-05 23:01:01 +02:00
|
|
|
<?php
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2017-05-24 12:32:05 +02:00
|
|
|
namespace SilverStripe\Subsites\Extensions;
|
|
|
|
|
2017-05-29 13:42:42 +02:00
|
|
|
use SilverStripe\Core\Config\Config;
|
2017-05-24 15:26:28 +02:00
|
|
|
use SilverStripe\ORM\DataObject;
|
2017-05-29 13:42:42 +02:00
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
|
|
|
use SilverStripe\ORM\DataExtension;
|
2017-05-24 12:32:05 +02:00
|
|
|
use SilverStripe\Subsites\Model\Subsite;
|
2017-05-24 13:36:04 +02:00
|
|
|
|
2017-05-24 15:26:28 +02:00
|
|
|
class ErrorPageSubsite extends DataExtension
|
|
|
|
{
|
2017-04-23 22:23:34 +02:00
|
|
|
|
2017-05-24 15:26:28 +02:00
|
|
|
/**
|
|
|
|
* Alter file path to generated a static (static) error page file to handle error page template on different sub-sites
|
|
|
|
*
|
2017-05-29 13:42:42 +02:00
|
|
|
* @see Error::get_filepath_for_errorcode()
|
2017-05-24 15:26:28 +02:00
|
|
|
*
|
|
|
|
* FIXME since {@link Subsite::currentSubsite()} partly relies on Session, viewing other sub-site (including main site) between
|
|
|
|
* opening ErrorPage in the CMS and publish ErrorPage causes static error page to get generated incorrectly.
|
|
|
|
*/
|
2017-05-29 13:42:42 +02:00
|
|
|
public function alternateFilepathForErrorcode($statusCode, $locale = null)
|
2017-05-24 15:26:28 +02:00
|
|
|
{
|
2017-05-29 13:42:42 +02:00
|
|
|
$static_filepath = Config::inst()->get($this->owner->ClassName, 'static_filepath');
|
|
|
|
$subdomainPart = "";
|
2017-05-24 15:26:28 +02:00
|
|
|
|
|
|
|
// Try to get current subsite from session
|
|
|
|
$subsite = Subsite::currentSubsite(false);
|
|
|
|
|
|
|
|
// since this function is called from Page class before the controller is created, we have to get subsite from domain instead
|
|
|
|
if (!$subsite) {
|
|
|
|
$subsiteID = Subsite::getSubsiteIDForDomain();
|
|
|
|
if ($subsiteID != 0) {
|
2017-06-01 14:42:56 +02:00
|
|
|
$subsite = DataObject::get_by_id(Subsite::class, $subsiteID);
|
2017-05-29 13:42:42 +02:00
|
|
|
} else {
|
|
|
|
$subsite = null;
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($subsite) {
|
|
|
|
$subdomain = $subsite->domain();
|
2017-05-29 13:42:42 +02:00
|
|
|
$subdomainPart = "-{$subdomain}";
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
2017-05-24 12:32:05 +02:00
|
|
|
|
2017-05-29 13:42:42 +02:00
|
|
|
if (singleton(SiteTree::class)->hasExtension('Translatable') && $locale && $locale != Translatable::default_locale()) {
|
|
|
|
$filepath = $static_filepath . "/error-{$statusCode}-{$locale}{$subdomainPart}.html";
|
|
|
|
} else {
|
|
|
|
$filepath = $static_filepath . "/error-{$statusCode}{$subdomainPart}.html";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $filepath;
|
|
|
|
}
|
2017-04-23 22:23:34 +02:00
|
|
|
|
2017-05-24 12:32:05 +02:00
|
|
|
}
|