mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
FIX Remove last use of static session methods, update some namespaces and assertion fixes
This commit is contained in:
parent
b0087b9035
commit
1a9797c185
@ -5,6 +5,7 @@ namespace SilverStripe\Subsites\Forms;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\Session;
|
||||
use SilverStripe\Core\Manifest\ModuleLoader;
|
||||
use SilverStripe\Forms\TreeDropdownField;
|
||||
use SilverStripe\View\Requirements;
|
||||
|
||||
@ -28,7 +29,8 @@ class SubsitesTreeDropdownField extends TreeDropdownField
|
||||
{
|
||||
$html = parent::Field($properties);
|
||||
|
||||
Requirements::javascript('subsites/javascript/SubsitesTreeDropdownField.js');
|
||||
$module = ModuleLoader::getModule('silverstripe/subsites');
|
||||
Requirements::javascript($module->getRelativeResourcePath('javascript/SubsitesTreeDropdownField.js'));
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ namespace SilverStripe\Subsites\Pages;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\CMS\Model\VirtualPage;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\Session;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Forms\DropdownField;
|
||||
use SilverStripe\Forms\LabelField;
|
||||
@ -15,6 +14,7 @@ use SilverStripe\ORM\ArrayList;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Subsites\Forms\SubsitesTreeDropdownField;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
use SilverStripe\Subsites\State\SubsiteState;
|
||||
use SilverStripe\View\ArrayData;
|
||||
|
||||
class SubsitesVirtualPage extends VirtualPage
|
||||
@ -139,7 +139,10 @@ class SubsitesVirtualPage extends VirtualPage
|
||||
|
||||
public function getCopyContentFromID_SubsiteID()
|
||||
{
|
||||
return $this->CopyContentFromID ? (int)$this->CopyContentFrom()->SubsiteID : (int)Session::get('SubsiteID');
|
||||
if ($this->CopyContentFromID) {
|
||||
return (int) $this->CopyContentFrom()->SubsiteID;
|
||||
}
|
||||
return SubsiteState::singleton()->getSubsiteId();
|
||||
}
|
||||
|
||||
public function getVirtualFields()
|
||||
@ -177,22 +180,22 @@ class SubsitesVirtualPage extends VirtualPage
|
||||
if ($this->CustomMetaTitle) {
|
||||
$this->MetaTitle = $this->CustomMetaTitle;
|
||||
} else {
|
||||
$this->MetaTitle = $this->ContentSource()->MetaTitle ? $this->ContentSource()->MetaTitle : $this->MetaTitle;
|
||||
$this->MetaTitle = $this->ContentSource()->MetaTitle ?: $this->MetaTitle;
|
||||
}
|
||||
if ($this->CustomMetaKeywords) {
|
||||
$this->MetaKeywords = $this->CustomMetaKeywords;
|
||||
} else {
|
||||
$this->MetaKeywords = $this->ContentSource()->MetaKeywords ? $this->ContentSource()->MetaKeywords : $this->MetaKeywords;
|
||||
$this->MetaKeywords = $this->ContentSource()->MetaKeywords ?: $this->MetaKeywords;
|
||||
}
|
||||
if ($this->CustomMetaDescription) {
|
||||
$this->MetaDescription = $this->CustomMetaDescription;
|
||||
} else {
|
||||
$this->MetaDescription = $this->ContentSource()->MetaDescription ? $this->ContentSource()->MetaDescription : $this->MetaDescription;
|
||||
$this->MetaDescription = $this->ContentSource()->MetaDescription ?: $this->MetaDescription;
|
||||
}
|
||||
if ($this->CustomExtraMeta) {
|
||||
$this->ExtraMeta = $this->CustomExtraMeta;
|
||||
} else {
|
||||
$this->ExtraMeta = $this->ContentSource()->ExtraMeta ? $this->ContentSource()->ExtraMeta : $this->ExtraMeta;
|
||||
$this->ExtraMeta = $this->ContentSource()->ExtraMeta ?: $this->ExtraMeta;
|
||||
}
|
||||
}
|
||||
|
||||
@ -217,13 +220,13 @@ class SubsitesVirtualPage extends VirtualPage
|
||||
$origDisableSubsiteFilter = Subsite::$disable_subsite_filter;
|
||||
Subsite::$disable_subsite_filter = true;
|
||||
$existingPage = DataObject::get_one(
|
||||
'SilverStripe\\CMS\\Model\\SiteTree',
|
||||
SiteTree::class,
|
||||
"\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter",
|
||||
false // disable cache, it doesn't include subsite status in the key
|
||||
);
|
||||
Subsite::$disable_subsite_filter = $origDisableSubsiteFilter;
|
||||
$existingPageInSubsite = DataObject::get_one(
|
||||
'SilverStripe\\CMS\\Model\\SiteTree',
|
||||
SiteTree::class,
|
||||
"\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter",
|
||||
false // disable cache, it doesn't include subsite status in the key
|
||||
);
|
||||
|
@ -154,8 +154,8 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
||||
$p2->write();
|
||||
|
||||
// Check that the URLs weren't modified in our set-up
|
||||
$this->assertEquals($p1->URLSegment, 'test-page');
|
||||
$this->assertEquals($p2->URLSegment, 'test-page');
|
||||
$this->assertEquals('test-page', $p1->URLSegment);
|
||||
$this->assertEquals('test-page', $p2->URLSegment);
|
||||
|
||||
// Check that if we switch between the different subsites, we receive the correct pages
|
||||
Subsite::changeSubsite($s1);
|
||||
@ -215,8 +215,8 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
||||
|
||||
/** @var Subsite $otherSubsite */
|
||||
$otherSubsite = $this->objFromFixture(Subsite::class, 'subsite1');
|
||||
$staffPage = $this->objFromFixture('Page', 'staff'); // nested page
|
||||
$contactPage = $this->objFromFixture('Page', 'contact'); // top level page
|
||||
$staffPage = $this->objFromFixture(Page::class, 'staff'); // nested page
|
||||
$contactPage = $this->objFromFixture(Page::class, 'contact'); // top level page
|
||||
|
||||
$staffPage2 = $staffPage->duplicateToSubsite($otherSubsite->ID);
|
||||
$contactPage2 = $contactPage->duplicateToSubsite($otherSubsite->ID);
|
||||
@ -270,7 +270,7 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
||||
{
|
||||
$this->logInWithPermission('ADMIN');
|
||||
// Saving existing page in the same subsite doesn't change urls
|
||||
$mainHome = $this->objFromFixture('Page', 'home');
|
||||
$mainHome = $this->objFromFixture(Page::class, 'home');
|
||||
$mainSubsiteID = $this->idFromFixture(Subsite::class, 'main');
|
||||
Subsite::changeSubsite($mainSubsiteID);
|
||||
$mainHome->Content = '<p>Some new content</p>';
|
||||
|
@ -262,7 +262,7 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest
|
||||
$subsite2 = $this->objFromFixture(Subsite::class, 'subsite2');
|
||||
Subsite::changeSubsite($subsite1->ID);
|
||||
|
||||
$subsite1Page = $this->objFromFixture('Page', 'subsite1_staff');
|
||||
$subsite1Page = $this->objFromFixture(Page::class, 'subsite1_staff');
|
||||
$subsite1Page->URLSegment = 'staff';
|
||||
$subsite1Page->write();
|
||||
|
||||
@ -271,9 +271,10 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest
|
||||
$subsite1Vp->CopyContentFromID = $subsite1Page->ID;
|
||||
$subsite1Vp->SubsiteID = $subsite1->ID;
|
||||
$subsite1Vp->write();
|
||||
|
||||
$this->assertNotEquals(
|
||||
(string) $subsite1Vp->URLSegment,
|
||||
(string) $subsite1Page->URLSegment,
|
||||
$subsite1Vp->URLSegment,
|
||||
$subsite1Page->URLSegment,
|
||||
"Doesn't allow explicit URLSegment overrides when already existing in same subsite"
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user