Version: current

     1 <?php
     2 class ErrorPageSubsite extends DataObjectDecorator {
     3
     4     /**
     5      * Alter file path to generated a static (static) error page file to handle error page template on different sub-sites
     6      *
     7      * @see Error::get_filepath_for_errorcode()
     8      *
     9      * FIXME since {@link Subsite::currentSubsite()} partly relies on Session, viewing other sub-site (including main site) between
    10      * opening ErrorPage in the CMS and publish ErrorPage causes static error page to get generated incorrectly.
    11      */
    12     function alternateFilepathForErrorcode($statusCode, $locale = null) {
    13         $static_filepath = Object::get_static($this->owner->ClassName, 'static_filepath');
    14         $subdomainPart = "";
    15
    16         // Try to get current subsite from session
    17         $subsite = Subsite::currentSubsite(false);
    18
    19         // since this function is called from Page class before the controller is created, we have to get subsite from domain instead
    20         if(!$subsite) {
    21             $subsiteID = Subsite::getSubsiteIDForDomain();
    22             if($subsiteID != 0) $subsite = DataObject::get_by_id("Subsite", $subsiteID);
    23             else $subsite = null;
    24         }
    25
    26         if($subsite) {
    27             $subdomain = preg_replace('!/!', '', $subsite->domain());
    28             $subdomainPart = "-{$subdomain}";
    29         }
    30
    31         if(singleton('SiteTree')->hasExtension('Translatable') && $locale && $locale != Translatable::default_locale()) {
    32             $filepath = $static_filepath . "/error-{$statusCode}-{$locale}{$subdomainPart}.html";
    33         } else {
    34             $filepath = $static_filepath . "/error-{$statusCode}{$subdomainPart}.html";
    35         }
    36
    37         return $filepath;
    38     }
    39
    40 }

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -