mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
BUG: Merged patch from kmayo how ever re-added some of the removed fields since they really should appear on the Main Content tab instead of the Metadata tab.
Fixed a few missed strict errors Applied patch from kmayo to fix issues with SubsiteAdminTest.php Fixed issue causing the url segments of subsites created from a template to add -2 to the end Fixed undefined method TotalItems() on datalist for the SubsiteTest Fixed failure on SubsiteTest because DataObject::get_one() now returns boolean false instead of null when no result is found Fixed failure on SubsitesVirtualPageTest caused by Versioned::get_one_by_stage() returning null instead of false Fixed failure caused by the contact-us page existing on subsite 2 Merged another patch from kmayo Force main site to be on, for some reason it gets hidden in some cases i.e. refreshing the cms while editing a page
This commit is contained in:
parent
598b0253f5
commit
ef4d539a12
@ -63,10 +63,10 @@ class SubsitesVirtualPage extends VirtualPage {
|
||||
}
|
||||
|
||||
|
||||
$fields->addFieldToTab('Root.Metadata', new TextField('CustomMetaTitle', 'Title (overrides inherited value from the source)'), 'MetaTitle');
|
||||
$fields->addFieldToTab('Root.Metadata', new TextareaField('CustomMetaKeywords', 'Keywords (overrides inherited value from the source)'), 'MetaKeywords');
|
||||
$fields->addFieldToTab('Root.Metadata', new TextareaField('CustomMetaDescription', 'Description (overrides inherited value from the source)'), 'MetaDescription');
|
||||
$fields->addFieldToTab('Root.Metadata', new TextField('CustomExtraMeta', 'Custom Meta Tags (overrides inherited value from the source)'), 'ExtraMeta');
|
||||
$fields->addFieldToTab('Root.Main', new TextField('CustomMetaTitle', 'Title (overrides inherited value from the source)'), 'MetaTitle');
|
||||
$fields->addFieldToTab('Root.Main', new TextareaField('CustomMetaKeywords', 'Keywords (overrides inherited value from the source)'), 'MetaKeywords');
|
||||
$fields->addFieldToTab('Root.Main', new TextareaField('CustomMetaDescription', 'Description (overrides inherited value from the source)'), 'MetaDescription');
|
||||
$fields->addFieldToTab('Root.Main', new TextField('CustomExtraMeta', 'Custom Meta Tags (overrides inherited value from the source)'), 'ExtraMeta');
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
@ -30,8 +30,11 @@ class FileSubsites extends DataExtension {
|
||||
function updateCMSFields(FieldList $fields) {
|
||||
if($this->owner instanceof Folder) {
|
||||
$sites = Subsite::accessible_sites('CMS_ACCESS_AssetAdmin');
|
||||
$dropdownValues = ($sites) ? $sites->map() : array();
|
||||
$dropdownValues = array();
|
||||
$dropdownValues[0] = 'All sites';
|
||||
foreach ($sites as $site) {
|
||||
$dropDownValues[$site->ID] = $site->Title;
|
||||
}
|
||||
ksort($dropdownValues);
|
||||
if($sites)$fields->push(new DropdownField("SubsiteID", "Subsite", $dropdownValues));
|
||||
}
|
||||
@ -107,4 +110,3 @@ class FileSubsites extends DataExtension {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -38,7 +38,35 @@ class LeftAndMainSubsites extends Extension {
|
||||
}
|
||||
|
||||
public function Subsites() {
|
||||
return Subsite::accessible_sites('ADMIN');
|
||||
$accessPerm = 'CMS_ACCESS_'. $this->owner->class;
|
||||
switch($this->owner->class) {
|
||||
case "AssetAdmin":
|
||||
$subsites = Subsite::accessible_sites($accessPerm, true, "Shared files & images");
|
||||
break;
|
||||
|
||||
case "SecurityAdmin":
|
||||
$subsites = Subsite::accessible_sites($accessPerm, true, "Groups accessing all sites");
|
||||
if($subsites->find('ID',0)) {
|
||||
$subsites->push(new ArrayData(array('Title' => 'All groups', 'ID' => -1)));
|
||||
}
|
||||
break;
|
||||
|
||||
case "CMSMain":
|
||||
// If there's a default site then main site has no meaning
|
||||
$showMainSite = !DataObject::get_one('Subsite',"\"DefaultSite\"=1 AND \"IsPublic\"=1");
|
||||
$subsites = Subsite::accessible_sites($accessPerm, $showMainSite);
|
||||
break;
|
||||
|
||||
case "SubsiteAdmin":
|
||||
$subsites = Subsite::accessible_sites('ADMIN', true);
|
||||
break;
|
||||
|
||||
default:
|
||||
$subsites = Subsite::accessible_sites($accessPerm);
|
||||
break;
|
||||
}
|
||||
|
||||
return $subsites;
|
||||
}
|
||||
|
||||
public function SubsiteList() {
|
||||
@ -144,4 +172,4 @@ class LeftAndMainSubsites extends Extension {
|
||||
|
||||
|
||||
|
||||
?>
|
||||
?>
|
@ -96,18 +96,15 @@ class SiteTreeSubsites extends DataExtension {
|
||||
$subsite = $this->owner->Subsite();
|
||||
if($subsite && $subsite->ID) {
|
||||
$baseUrl = 'http://' . $subsite->domain() . '/';
|
||||
$fields->removeByName('URLSegment');
|
||||
|
||||
$baseLink = Controller::join_links (
|
||||
$baseUrl,
|
||||
(SiteTree::nested_urls() && $this->owner->ParentID ? $this->owner->Parent()->RelativeLink(true) : null)
|
||||
);
|
||||
|
||||
$url = (strlen($baseLink) > 36) ? "..." .substr($baseLink, -32) : $baseLink;
|
||||
$urlsegment = new SiteTreeURLSegmentField("URLSegment", $this->owner->fieldLabel('URLSegment'));
|
||||
$url = (strlen($baseLink) > 36 ? "..." .substr($baseLink, -32) : $baseLink);
|
||||
$urlsegment = $fields->dataFieldByName('URLSegment');
|
||||
$urlsegment->setURLPrefix($url);
|
||||
$urlsegment->setHelpText(SiteTree::nested_urls() && count($this->owner->Children()) ? $this->owner->fieldLabel('LinkChangeNote'): false);
|
||||
$fields->addFieldToTab('Root.Metadata', $urlsegment, 'MetaTitle');
|
||||
}
|
||||
|
||||
$relatedCount = 0;
|
||||
@ -119,7 +116,8 @@ class SiteTreeSubsites extends DataExtension {
|
||||
$tabName = $relatedCount ? 'Related (' . $relatedCount . ')' : 'Related';
|
||||
$tab = $fields->findOrMakeTab('Root.Related', $tabName);
|
||||
// Related pages
|
||||
$tab->push(new LiteralField('RelatedNote', '<p>You can list pages here that are related to this page.<br />When this page is updated, you will get a reminder to check whether these related pages need to be updated as well.</p>'));
|
||||
$tab->push(new LiteralField('RelatedNote',
|
||||
'<p>You can list pages here that are related to this page.<br />When this page is updated, you will get a reminder to check whether these related pages need to be updated as well.</p>'));
|
||||
$tab->push(
|
||||
$related=new GridField('RelatedPages', 'Related Pages', $this->owner->RelatedPages(), GridFieldConfig_Base::create())
|
||||
);
|
||||
@ -231,16 +229,25 @@ class SiteTreeSubsites extends DataExtension {
|
||||
$subsiteID = $subsite->ID;
|
||||
} else $subsite = DataObject::get_by_id('Subsite', $subsiteID);
|
||||
|
||||
$oldSubsite=Subsite::currentSubsiteID();
|
||||
if($subsiteID) {
|
||||
Subsite::changeSubsite($subsiteID);
|
||||
}else {
|
||||
$subsiteID=$oldSubsite;
|
||||
}
|
||||
|
||||
$page = $this->owner->duplicate(false);
|
||||
|
||||
$page->CheckedPublicationDifferences = $page->AddedToStage = true;
|
||||
$subsiteID = ($subsiteID ? $subsiteID : Subsite::currentSubsiteID());
|
||||
$subsiteID = ($subsiteID ? $subsiteID : $oldSubsite);
|
||||
$page->SubsiteID = $subsiteID;
|
||||
|
||||
if($isTemplate) $page->MasterPageID = $this->owner->ID;
|
||||
|
||||
$page->write();
|
||||
|
||||
|
||||
Subsite::changeSubsite($oldSubsite);
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,8 @@ class SubsitesTreeDropdownField extends TreeDropdownField {
|
||||
|
||||
protected $extraClasses = array('SubsitesTreeDropdownField');
|
||||
|
||||
function Field() {
|
||||
$html = parent::Field();
|
||||
function Field($properties = array()) {
|
||||
$html = parent::Field($properties);
|
||||
|
||||
Requirements::javascript('subsites/javascript/SubsitesTreeDropdownField.js');
|
||||
|
||||
|
@ -27,14 +27,14 @@ class RelatedPageLink extends DataObject {
|
||||
if(!$subsites) $subsites = new ArrayList();
|
||||
|
||||
if(Subsite::hasMainSitePermission(null, array("CMS_ACCESS_CMSMain"))) {
|
||||
$subsites->push(new ArrayData(array('Title' => 'Main site', "\"ID\"" => 0)));
|
||||
$subsites = Subsite::accessible_sites("CMS_ACCESS_CMSMain", true);
|
||||
}
|
||||
|
||||
if($subsites->Count()) {
|
||||
$subsiteSelectionField = new DropdownField(
|
||||
"CopyContentFromID_SubsiteID",
|
||||
"Subsite",
|
||||
$subsites->toDropdownMap('ID', 'Title'),
|
||||
$subsites->map('ID', 'Title'),
|
||||
($this->CopyContentFromID) ? $this->CopyContentFrom()->SubsiteID : Session::get('SubsiteID')
|
||||
);
|
||||
}
|
||||
@ -87,4 +87,4 @@ class RelatedPageLink extends DataObject {
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
@ -322,7 +322,7 @@ JS;
|
||||
/**
|
||||
* @todo Possible security issue, don't grant edit permissions to everybody.
|
||||
*/
|
||||
function canEdit() {
|
||||
function canEdit($member = false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -403,7 +403,7 @@ JS;
|
||||
if(!is_array($permissionCodes))
|
||||
user_error('Permissions must be passed to Subsite::hasMainSitePermission as an array', E_USER_ERROR);
|
||||
|
||||
if(!$member && $member !== FALSE) $member = Member::currentMember();
|
||||
if(!$member && $member !== FALSE) $member = Member::currentUser();
|
||||
|
||||
if(!$member) return false;
|
||||
|
||||
@ -429,8 +429,8 @@ JS;
|
||||
/**
|
||||
* Duplicate this subsite
|
||||
*/
|
||||
function duplicate() {
|
||||
$newTemplate = parent::duplicate();
|
||||
function duplicate($doWrite = true) {
|
||||
$newTemplate = parent::duplicate($doWrite);
|
||||
|
||||
$oldSubsiteID = Session::get('SubsiteID');
|
||||
self::changeSubsite($this->ID);
|
||||
@ -476,7 +476,7 @@ JS;
|
||||
* @param $member
|
||||
* @return DataList of {@link Subsite} instances
|
||||
*/
|
||||
function accessible_sites($permCode, $includeMainSite = true, $mainSiteTitle = "Main site", $member = null) {
|
||||
public static function accessible_sites($permCode, $includeMainSite = true, $mainSiteTitle = "Main site", $member = null) {
|
||||
// Rationalise member arguments
|
||||
if(!$member) $member = Member::currentUser();
|
||||
if(!$member) return new ArrayList();
|
||||
@ -661,9 +661,17 @@ class Subsite_Template extends Subsite {
|
||||
if($children) {
|
||||
foreach($children as $child) {
|
||||
$childClone = $child->duplicateToSubsite($intranet);
|
||||
|
||||
//Change to destination subsite
|
||||
self::changeSubsite($intranet->ID);
|
||||
|
||||
$childClone->ParentID = $destParentID;
|
||||
$childClone->writeToStage('Stage');
|
||||
$childClone->publish('Stage', 'Live');
|
||||
|
||||
//Change Back to this subsite
|
||||
self::changeSubsite($this->ID);
|
||||
|
||||
array_push($stack, array($child->ID, $childClone->ID));
|
||||
}
|
||||
}
|
||||
@ -674,4 +682,4 @@ class Subsite_Template extends Subsite {
|
||||
return $intranet;
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
@ -25,8 +25,8 @@ class SubsiteDomain extends DataObject {
|
||||
|
||||
public function getCMSFields() {
|
||||
return new FieldList(
|
||||
new TextField('Domain', _t('SubsiteDomain.DOMAIN', '_Domain'), null, 255),
|
||||
new CheckboxField('IsPrimary', _t('SubsiteDomain.IS_PRIMARY', '_Is Primary Domain'))
|
||||
);
|
||||
new TextField('Domain', _t('SubsiteDomain.DOMAIN', '_Domain'), null, 255),
|
||||
new CheckboxField('IsPrimary', _t('SubsiteDomain.IS_PRIMARY', '_Is Primary Domain'))
|
||||
);
|
||||
}
|
||||
}
|
@ -14,8 +14,8 @@
|
||||
|
||||
var ref=this;
|
||||
$('#Form_ItemEditForm_AccessAllSubsites input').change(function() {
|
||||
ref.showHideSubsiteList();
|
||||
});
|
||||
ref.showHideSubsiteList();
|
||||
});
|
||||
},
|
||||
|
||||
showHideSubsiteList: function () {
|
||||
@ -42,11 +42,10 @@
|
||||
|
||||
//Bind listener
|
||||
$('a#PageTypeBlacklistToggle').click(function(e) {
|
||||
jQuery('#PageTypeBlacklist').toggle();
|
||||
|
||||
e.stopPropagation();
|
||||
return false;
|
||||
});
|
||||
jQuery('#PageTypeBlacklist').toggle();
|
||||
e.stopPropagation();
|
||||
return false;
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -10,7 +10,7 @@ class FileSubsitesTest extends SapphireTest {
|
||||
$file->Title = 'FileTitle';
|
||||
$this->assertEquals(' * FileTitle', $file->alternateTreeTitle());
|
||||
$file->SubsiteID = $this->objFromFixture('Subsite', 'domaintest1')->ID;
|
||||
$this->assertEquals('FileTitle', $file->TreeTitle());
|
||||
$this->assertEquals('FileTitle', $file->getTreeTitle());
|
||||
$this->assertTrue(singleton('Folder')->getCMSFields() instanceof FieldList);
|
||||
Subsite::changeSubsite(1);
|
||||
$this->assertEquals($file->cacheKeyComponent(), 'subsite-1');
|
||||
@ -55,4 +55,4 @@ class FileSubsitesTest extends SapphireTest {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -15,11 +15,11 @@ class GroupSubsitesTest extends SapphireTest {
|
||||
$group = new Group();
|
||||
$group->Title = 'The A Team';
|
||||
$group->AccessAllSubsites = true;
|
||||
$this->assertEquals($group->TreeTitle(), 'The A Team <i>(global group)</i>');
|
||||
$this->assertEquals($group->getTreeTitle(), 'The A Team <i>(global group)</i>');
|
||||
$group->AccessAllSubsites = false;
|
||||
$group->write();
|
||||
$group->Subsites()->add($this->objFromFixture('Subsite', 'domaintest1'));
|
||||
$group->Subsites()->add($this->objFromFixture('Subsite', 'domaintest2'));
|
||||
$this->assertEquals($group->TreeTitle(), 'The A Team <i>(Test 1, Test 2)</i>');
|
||||
$this->assertEquals($group->getTreeTitle(), 'The A Team <i>(Test 1, Test 2)</i>');
|
||||
}
|
||||
}
|
@ -164,25 +164,27 @@ class SiteTreeSubsitesTest extends SapphireTest {
|
||||
$s1->write();
|
||||
|
||||
Subsite::changeSubsite($s1);
|
||||
$settingsFields = $page->getSettingsFields()->dataFieldByName('ClassName')->getSource();
|
||||
$this->assertArrayNotHasKey('ErrorPage',
|
||||
$page->getCMSFields()->dataFieldByName('ClassName')->getSource()
|
||||
$settingsFields
|
||||
);
|
||||
$this->assertArrayNotHasKey('SiteTreeSubsitesTest_ClassA',
|
||||
$page->getCMSFields()->dataFieldByName('ClassName')->getSource()
|
||||
$settingsFields
|
||||
);
|
||||
$this->assertArrayHasKey('SiteTreeSubsitesTest_ClassB',
|
||||
$page->getCMSFields()->dataFieldByName('ClassName')->getSource()
|
||||
$settingsFields
|
||||
);
|
||||
|
||||
Subsite::changeSubsite($s2);
|
||||
$settingsFields = $page->getSettingsFields()->dataFieldByName('ClassName')->getSource();
|
||||
$this->assertArrayHasKey('ErrorPage',
|
||||
$page->getCMSFields()->dataFieldByName('ClassName')->getSource()
|
||||
$settingsFields
|
||||
);
|
||||
$this->assertArrayHasKey('SiteTreeSubsitesTest_ClassA',
|
||||
$page->getCMSFields()->dataFieldByName('ClassName')->getSource()
|
||||
$settingsFields
|
||||
);
|
||||
$this->assertArrayHasKey('SiteTreeSubsitesTest_ClassB',
|
||||
$page->getCMSFields()->dataFieldByName('ClassName')->getSource()
|
||||
$settingsFields
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,8 @@ class SubsiteAdminTest extends SapphireTest {
|
||||
$response1 = Director::test('admin/subsites/', null, $this->adminLoggedInSession());
|
||||
|
||||
// Confirm that this URL gets you the entire page, with the edit form loaded
|
||||
$response2 = Director::test("admin/subsites/Subsite/$subsite1ID/edit", null, $this->adminLoggedInSession());
|
||||
$this->assertTrue(strpos($response2->getBody(), 'id="Form_EditForm_ID"') !== false, "Testing Form_EditForm_ID exists");
|
||||
$response2 = Director::test("admin/subsites/Subsite/EditForm/field/Subsite/item/$subsite1ID/edit", null, $this->adminLoggedInSession());
|
||||
$this->assertTrue(strpos($response2->getBody(), 'id="Form_ItemEditForm_ID"') !== false, "Testing Form_ItemEditForm_ID exists");
|
||||
$this->assertTrue(strpos($response2->getBody(), '<head') !== false, "Testing <head> exists");
|
||||
}
|
||||
|
||||
@ -101,8 +101,8 @@ class SubsiteAdminTest extends SapphireTest {
|
||||
foreach($cmsMain->Subsites() as $subsite) {
|
||||
$ids[$subsite->ID] = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($subsite->adminSearchFields() instanceof FieldList);
|
||||
|
||||
$this->assertTrue(Subsite::adminSearchFields() instanceof FieldList);
|
||||
$this->assertArrayHasKey(0, $ids, "Main site accessible");
|
||||
$this->assertArrayHasKey($this->idFromFixture('Subsite_Template','main'), $ids, "Site with no groups inaccesible");
|
||||
$this->assertArrayHasKey($this->idFromFixture('Subsite_Template','subsite1'), $ids, "Subsite1 Template inaccessible");
|
||||
|
@ -33,7 +33,7 @@ class SubsiteTest extends SapphireTest {
|
||||
|
||||
// Publish all the pages in the template, testing that DataObject::get only returns pages from the chosen subsite
|
||||
$pages = DataObject::get("SiteTree");
|
||||
$totalPages = $pages->TotalItems();
|
||||
$totalPages = $pages->Count();
|
||||
foreach($pages as $page) {
|
||||
$this->assertEquals($template->ID, $page->SubsiteID);
|
||||
$page->publish('Stage', 'Live');
|
||||
@ -52,7 +52,7 @@ class SubsiteTest extends SapphireTest {
|
||||
$subsite->activate();
|
||||
|
||||
$siteHome = DataObject::get_one('SiteTree', "\"URLSegment\" = 'home'");
|
||||
$this->assertNotNull($siteHome);
|
||||
$this->assertNotEquals($siteHome, false, 'Home Page for subsite not found');
|
||||
$this->assertEquals($subsite->ID, $siteHome->SubsiteID,
|
||||
'createInstance() copies existing pages retaining the same URLSegment'
|
||||
);
|
||||
|
@ -60,16 +60,19 @@ SiteTree:
|
||||
Title: Important Page
|
||||
SubsiteID: =>Subsite_Template.main
|
||||
subsite1_home:
|
||||
Title: Home (Subsite 1)
|
||||
Title: Home
|
||||
SubsiteID: =>Subsite_Template.subsite1
|
||||
subsite1_contactus:
|
||||
Title: Contact Us (Subsite 1)
|
||||
Title: Contact Us
|
||||
SubsiteID: =>Subsite_Template.subsite1
|
||||
subsite1_staff:
|
||||
Title: Staff
|
||||
SubsiteID: =>Subsite_Template.subsite1
|
||||
subsite2_home:
|
||||
Title: Home (Subsite 2)
|
||||
Title: Home
|
||||
SubsiteID: =>Subsite_Template.subsite2
|
||||
subsite2_contactus:
|
||||
Title: Contact Us (Subsite 2)
|
||||
Title: Contact Us
|
||||
SubsiteID: =>Subsite_Template.subsite2
|
||||
|
||||
Group:
|
||||
|
@ -199,12 +199,12 @@ class SubsitesVirtualPageTest extends SapphireTest {
|
||||
|
||||
Subsite::changeSubsite($vp1->SubsiteID);
|
||||
$onLive = Versioned::get_one_by_stage('SubsitesVirtualPage', 'Live', "\"SiteTree_Live\".\"ID\" = ".$vp1->ID);
|
||||
$this->assertFalse($onLive, 'SVP has been removed from live');
|
||||
$this->assertNull($onLive, 'SVP has been removed from live');
|
||||
|
||||
$subsite = $this->objFromFixture('Subsite_Template', 'subsite2');
|
||||
Subsite::changeSubsite($vp2->SubsiteID);
|
||||
$onLive = Versioned::get_one_by_stage('SubsitesVirtualPage', 'Live', "\"SiteTree_Live\".\"ID\" = ".$vp2->ID);
|
||||
$this->assertFalse($onLive, 'SVP has been removed from live');
|
||||
$this->assertNull($onLive, 'SVP has been removed from live');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -217,8 +217,8 @@ class SubsitesVirtualPageTest extends SapphireTest {
|
||||
$subsite2 = $this->objFromFixture('Subsite_Template', 'subsite2');
|
||||
Subsite::changeSubsite($subsite1->ID);
|
||||
|
||||
$subsite1Page = $this->objFromFixture('SiteTree', 'subsite1_contactus');
|
||||
$subsite1Page->URLSegment = 'contact-us';
|
||||
$subsite1Page = $this->objFromFixture('SiteTree', 'subsite1_staff');
|
||||
$subsite1Page->URLSegment = 'staff';
|
||||
$subsite1Page->write();
|
||||
|
||||
// saving on subsite1, and linking to subsite1
|
||||
@ -232,6 +232,9 @@ class SubsitesVirtualPageTest extends SapphireTest {
|
||||
"Doesn't allow explicit URLSegment overrides when already existing in same subsite"
|
||||
);
|
||||
|
||||
//Change to subsite 2
|
||||
Subsite::changeSubsite($subsite2->ID);
|
||||
|
||||
// saving in subsite2 (which already has a page with URLSegment 'contact-us'),
|
||||
// but linking to a page in subsite1
|
||||
$subsite2Vp = new SubsitesVirtualPage();
|
||||
|
Loading…
Reference in New Issue
Block a user