Add Subsite theme as main theme; allow cascading of themes

This commit is contained in:
Werner M. Krauß 2017-06-07 11:57:32 +02:00
parent a4a1ab6a78
commit 877f4f5f9d
4 changed files with 68 additions and 1 deletions

View File

@ -297,7 +297,7 @@ class SiteTreeSubsites extends DataExtension
$subsite = Subsite::currentSubsite(); $subsite = Subsite::currentSubsite();
if ($subsite && $subsite->Theme) { if ($subsite && $subsite->Theme) {
Config::modify()->set(SSViewer::class, 'theme', Subsite::currentSubsite()->Theme); SSViewer::set_themes(array_merge([$subsite->Theme], SSViewer::get_themes()));
} }
} }

View File

@ -4,6 +4,7 @@ namespace SilverStripe\Subsites\Tests;
use Page; use Page;
use SilverStripe\CMS\Controllers\CMSMain; use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\CMS\Controllers\ModelAsController;
use SilverStripe\CMS\Model\ErrorPage; use SilverStripe\CMS\Model\ErrorPage;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
@ -18,6 +19,7 @@ use SilverStripe\Subsites\Extensions\SiteTreeSubsites;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Subsites\Pages\SubsitesVirtualPage; use SilverStripe\Subsites\Pages\SubsitesVirtualPage;
use SilverStripe\Versioned\Versioned; use SilverStripe\Versioned\Versioned;
use SilverStripe\View\SSViewer;
class SiteTreeSubsitesTest extends BaseSubsiteTest class SiteTreeSubsitesTest extends BaseSubsiteTest
{ {
@ -337,6 +339,32 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
$this->assertEquals($moved->SubsiteID, $newSubsite->ID, 'Ensure returned records are on new subsite'); $this->assertEquals($moved->SubsiteID, $newSubsite->ID, 'Ensure returned records are on new subsite');
$this->assertEquals($moved->AllChildren()->count(), 0, 'All pages are copied across'); $this->assertEquals($moved->AllChildren()->count(), 0, 'All pages are copied across');
} }
/**
* @todo: move to a functional test?
*/
public function testIfSubsiteThemeIsSetToThemeList()
{
$defaultThemes = ['default'];
SSViewer::set_themes($defaultThemes);
$subsitePage = $this->objFromFixture(Page::class, 'home');
Subsite::changeSubsite($subsitePage->SubsiteID);
$controller = ModelAsController::controller_for($subsitePage);
SiteTree::singleton()->extend('contentcontrollerInit', $controller);
$this->assertEquals(SSViewer::get_themes(), $defaultThemes,
'Themes should not be modified when Subsite has no theme defined');
$pageWithTheme = $this->objFromFixture(Page::class, 'subsite1_home');
Subsite::changeSubsite($pageWithTheme->SubsiteID);
$controller = ModelAsController::controller_for($pageWithTheme);
SiteTree::singleton()->extend('contentcontrollerInit', $controller);
$subsiteTheme = $pageWithTheme->Subsite()->Theme;
$this->assertEquals(SSViewer::get_themes(), array_merge([$subsiteTheme], $defaultThemes),
'Themes should be modified when Subsite has theme defined');
}
} }

View File

@ -0,0 +1,38 @@
<?php
namespace subsites\tests\php;
use Page;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\View\SSViewer;
class SubsiteFunctionalTest extends FunctionalTest
{
public static $fixture_file = 'subsites/tests/php/SubsiteTest.yml';
/**
* @todo: remove test from SiteTreeSubsitesTest when this one works. Seems domain lookup is broken atm
*/
public function testIfSubsiteThemeIsSetToThemeList()
{
$this->markTestSkipped('doesn\'t work somehow - refactor when domain lookup is working');
$defaultThemes = ['default'];
SSViewer::set_themes($defaultThemes);
$subsitePage = $this->objFromFixture(Page::class, 'contact');
$this->get($subsitePage->AbsoluteLink());
$this->assertEquals($subsitePage->SubsiteID, Subsite::currentSubsiteID(), 'Subsite should be changed');
$this->assertEquals(SSViewer::get_themes(), $defaultThemes,
'Themes should not be modified when Subsite has no theme defined');
$pageWithTheme = $this->objFromFixture(Page::class, 'subsite1_contactus');
$this->get($pageWithTheme->AbsoluteLink());
$subsiteTheme = $pageWithTheme->Subsite()->Theme;
$this->assertEquals($pageWithTheme->SubsiteID, Subsite::currentSubsiteID(), 'Subsite should be changed');
$this->assertEquals(SSViewer::get_themes(), array_merge([$subsiteTheme], $defaultThemes),
'Themes should be modified when Subsite has theme defined');
}
}

View File

@ -3,6 +3,7 @@ SilverStripe\Subsites\Model\Subsite:
Title: Template Title: Template
subsite1: subsite1:
Title: Subsite1 Template Title: Subsite1 Template
Theme: subsiteTheme
subsite2: subsite2:
Title: Subsite2 Template Title: Subsite2 Template
domaintest1: domaintest1: