Skip to content

Commit

Permalink
FIX Update API changes in ErrorPage and typo in extension config clas…
Browse files Browse the repository at this point in the history
…s name
  • Loading branch information
robbieaverill committed Aug 30, 2017
1 parent c620ff0 commit c155855
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion _config/extensions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ SilverStripe\Assets\File:
extensions:
- SilverStripe\Subsites\Extensions\FileSubsites

SilverStripe\CMS\Model\ErrorPage:
SilverStripe\ErrorPage\ErrorPage:
extensions:
- SilverStripe\Subsites\Extensions\ErrorPageSubsite

Expand Down
29 changes: 18 additions & 11 deletions code/extensions/ErrorPageSubsite.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,28 @@
class ErrorPageSubsite extends DataExtension
{
/**
* Alter file path to generated a static (static) error page file to handle error page template on different sub-sites
* Alter file path to generated a static (static) error page file to handle error page template
* on different sub-sites
*
* @see Error::get_filepath_for_errorcode()
* @see ErrorPage::get_error_filename()
*
* 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.
* @param $statusCode
* @param null $locale
* @return string
* 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.
*
* @param string $name
* @param int $statusCode
*/
public function alternateFilepathForErrorcode($statusCode, $locale = null)
public function updateErrorFilename(&$name, &$statusCode)
{
$static_filepath = Config::inst()->get($this->owner->ClassName, 'static_filepath');
$subdomainPart = '';

// Try to get current subsite from session
$subsite = Subsite::currentSubsite();

// since this function is called from Page class before the controller is created, we have to get subsite from domain instead
// 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) {
Expand All @@ -44,12 +47,16 @@ public function alternateFilepathForErrorcode($statusCode, $locale = null)
$subdomainPart = "-{$subdomain}";
}

if (singleton(SiteTree::class)->hasExtension('Translatable') && $locale && $locale != Translatable::default_locale()) {
// @todo implement Translatable namespace
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;
$name = $filepath;
}
}
2 changes: 1 addition & 1 deletion code/extensions/SiteTreeSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ public function canCreate($member = null)
if ($subsite && $subsite->exists() && $subsite->PageTypeBlacklist) {
$blacklisted = explode(',', $subsite->PageTypeBlacklist);
// All subclasses need to be listed explicitly
if (in_array($this->owner->class, $blacklisted)) {
if (in_array(get_class($this->owner), $blacklisted)) {
return false;
}
}
Expand Down
4 changes: 1 addition & 3 deletions tests/php/SiteTreeSubsitesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,10 @@ public function testBasicSanity()

public function testErrorPageLocations()
{
$this->markTestSkipped('needs refactoring');

$subsite1 = $this->objFromFixture(Subsite::class, 'domaintest1');

Subsite::changeSubsite($subsite1->ID);
$path = ErrorPage::get_filepath_for_errorcode(500);
$path = TestErrorPage::get_error_filename_spy(500);

$static_path = Config::inst()->get(ErrorPage::class, 'static_filepath');
$expected_path = $static_path . '/error-500-' . $subsite1->domain() . '.html';
Expand Down

0 comments on commit c155855

Please sign in to comment.