API Removed related pages functionality, this is now a separate module

If you need this functionality still, please checkout
github.com/silverstripe-labs/silverstripe-subsites_relatedpages
This commit is contained in:
Sean Harvey 2013-05-01 12:35:17 +12:00
parent fbddc076b8
commit 0247765563
3 changed files with 6 additions and 216 deletions

View File

@ -7,21 +7,12 @@ class SiteTreeSubsites extends DataExtension {
public static $has_one=array( public static $has_one=array(
'Subsite' => 'Subsite', // The subsite that this page belongs to 'Subsite' => 'Subsite', // The subsite that this page belongs to
'MasterPage' => 'SiteTree',// Optional; the page that is the content master
);
public static $has_many=array(
'RelatedPages' => 'RelatedPageLink'
); );
public static $many_many=array( public static $many_many=array(
'CrossSubsiteLinkTracking' => 'SiteTree' // Stored separately, as the logic for URL rewriting is different 'CrossSubsiteLinkTracking' => 'SiteTree' // Stored separately, as the logic for URL rewriting is different
); );
public static $belongs_many_many=array(
'BackCrossSubsiteLinkTracking' => 'SiteTree'
);
public static $many_many_extraFields=array( public static $many_many_extraFields=array(
"CrossSubsiteLinkTracking" => array("FieldName" => "Varchar") "CrossSubsiteLinkTracking" => array("FieldName" => "Varchar")
); );
@ -75,27 +66,6 @@ class SiteTreeSubsites extends DataExtension {
unset($subsitesMap[$this->owner->SubsiteID]); unset($subsitesMap[$this->owner->SubsiteID]);
} }
// Master page notice
if($this->owner->MasterPageID) {
$masterPage = $this->owner->MasterPage();
$masterNoteField = new LiteralField(
'MasterLink',
sprintf(
_t(
'SiteTreeSubsites.MasterLinkNote',
'<p>This page\'s content is copied from the <a href="%s" target="_blank">%s</a> master page (<a href="%s">edit</a>)</p>'
),
$masterPage->AbsoluteLink(),
$masterPage->Title,
Controller::join_links(
singleton('CMSMain')->Link('show'),
$masterPage->ID
)
)
);
$fields->addFieldToTab('Root.Main',$masterNoteField);
}
// Master page edit field (only allowed from default subsite to avoid inconsistent relationships) // Master page edit field (only allowed from default subsite to avoid inconsistent relationships)
$isDefaultSubsite = $this->owner->SubsiteID == 0 || $this->owner->Subsite()->DefaultSite; $isDefaultSubsite = $this->owner->SubsiteID == 0 || $this->owner->Subsite()->DefaultSite;
if($isDefaultSubsite && $subsitesMap) { if($isDefaultSubsite && $subsitesMap) {
@ -116,20 +86,6 @@ class SiteTreeSubsites extends DataExtension {
) )
); );
$copyAction->includeDefaultJS(false); $copyAction->includeDefaultJS(false);
} else {
$defaultSubsite = DataObject::get_one('Subsite', '"DefaultSite" = 1');
if($defaultSubsite) {
$fields->addFieldToTab('Root.Main',
$masterPageField = new SubsitesTreeDropdownField(
"MasterPageID",
_t('VirtualPage.MasterPage', "Master page"),
"SiteTree",
"ID",
"MenuTitle"
)
);
$masterPageField->setSubsiteID($defaultSubsite->ID);
}
} }
// replace readonly link prefix // replace readonly link prefix
@ -146,59 +102,6 @@ class SiteTreeSubsites extends DataExtension {
$urlsegment = $fields->dataFieldByName('URLSegment'); $urlsegment = $fields->dataFieldByName('URLSegment');
$urlsegment->setURLPrefix($url); $urlsegment->setURLPrefix($url);
} }
$relatedCount = 0;
$reverse = $this->ReverseRelated();
if($reverse) $relatedCount += $reverse->Count();
$normalRelated = $this->NormalRelated();
if($normalRelated) $relatedCount += $normalRelated->Count();
$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(
$related=new GridField('RelatedPages', 'Related Pages', $this->owner->RelatedPages(), GridFieldConfig_Base::create())
);
$related->setModelClass('RelatedPageLink');
// The 'show' link doesn't provide any useful info
//$related->setPermissions(array('add', 'edit', 'delete'));
if($reverse) {
$text = '<p>In addition, this page is marked as related by the following pages: </p><p>';
foreach($reverse as $rpage) {
$text .= $rpage->RelatedPageAdminLink(true) . " - " . $rpage->AbsoluteLink(true) . "<br />\n";
}
$text .= '</p>';
$tab->push(new LiteralField('ReverseRelated', $text));
}
}
/**
* Returns the RelatedPageLink objects that are reverse-associated with this page.
*/
function ReverseRelated() {
return DataObject::get('RelatedPageLink', "\"RelatedPageLink\".\"RelatedPageID\" = {$this->owner->ID}
AND R2.\"ID\" IS NULL", '')
->innerJoin('SiteTree', "\"SiteTree\".\"ID\" = \"RelatedPageLink\".\"MasterPageID\"")
->leftJoin('RelatedPageLink', "R2.\"MasterPageID\" = {$this->owner->ID} AND R2.\"RelatedPageID\" = \"RelatedPageLink\".\"MasterPageID\"", 'R2');
}
function NormalRelated() {
$return = new ArrayList();
$links = DataObject::get('RelatedPageLink', '"MasterPageID" = ' . $this->owner->ID);
if($links) foreach($links as $link) {
if($link->RelatedPage()->exists()) {
$return->push($link->RelatedPage());
}
}
return $return->Count() > 0 ? $return : false;
} }
function alternateSiteConfig() { function alternateSiteConfig() {
@ -280,6 +183,8 @@ class SiteTreeSubsites extends DataExtension {
$page->CheckedPublicationDifferences = $page->AddedToStage = true; $page->CheckedPublicationDifferences = $page->AddedToStage = true;
$subsiteID = ($subsiteID ? $subsiteID : $oldSubsite); $subsiteID = ($subsiteID ? $subsiteID : $oldSubsite);
$page->SubsiteID = $subsiteID; $page->SubsiteID = $subsiteID;
// MasterPageID is here for legacy purposes, to satisfy the subsites_relatedpages module
$page->MasterPageID = $this->owner->ID; $page->MasterPageID = $this->owner->ID;
$page->write(); $page->write();

View File

@ -1,89 +0,0 @@
<?php
/**
* This DataObject only exists to provide a link between related pages.
* Unfortunately, there is no way to provide a decent GUI otherwise.
*/
class RelatedPageLink extends DataObject {
static $db = array(
);
static $has_one = array(
'RelatedPage' => 'SiteTree',
// Note: The *last* matching has_one relation to SiteTree is used as the link field for the
// has_many (RelatedPages) on SiteTree. This isn't obvious and the framework could be
// extended in a future version to allow for explicit selection of a has_one relation to
// bind a has_many to.
'MasterPage' => 'SiteTree',
);
public static $summary_fields=array(
'RelatedPageAdminLink' => 'Page',
'AbsoluteLink' => 'URL',
);
function getCMSFields() {
$subsites = Subsite::accessible_sites("CMS_ACCESS_CMSMain");
if(!$subsites) $subsites = new ArrayList();
if(Subsite::hasMainSitePermission(null, array("CMS_ACCESS_CMSMain"))) {
$subsites = Subsite::accessible_sites("CMS_ACCESS_CMSMain", true);
}
if($subsites->Count()) {
$subsiteSelectionField = new DropdownField(
"CopyContentFromID_SubsiteID",
"Subsite",
$subsites->map('ID', 'Title'),
($this->CopyContentFromID) ? $this->CopyContentFrom()->SubsiteID : Session::get('SubsiteID')
);
}
// Setup the linking to the original page.
$pageSelectionField = new SubsitesTreeDropdownField(
"RelatedPageID",
_t('VirtualPage.CHOOSE', "Choose a page to link to"),
"SiteTree",
"ID",
"MenuTitle"
);
if (isset($_GET['RelatedPageID_SubsiteID'])) $pageSelectionField->setSubsiteID($_GET['RelatedPageID_SubsiteID']);
$pageSelectionField->setFilterFunction(create_function('$item', 'return $item->ClassName != "VirtualPage";'));
if($subsites->Count()) $fields = new FieldList($subsiteSelectionField, $pageSelectionField);
else $fields = new FieldList($pageSelectionField);
return $fields;
}
function RelatedPageAdminLink($master = false) {
$page = $master ? Dataobject::get_by_id("SiteTree", $this->MasterPageID) : Dataobject::get_by_id("SiteTree", $this->RelatedPageID);
$otherPage = $master ? Dataobject::get_by_id("SiteTree", $this->RelatedPageID) : Dataobject::get_by_id("SiteTree", $this->MasterPageID);
if(!$page || !$otherPage) return;
// Use cmsEditlink only when moving between different pages in the same subsite.
$classClause = ($page->SubsiteID == $otherPage->SubsiteID) ? ' class="cmsEditlink"' : '';
return '<a href="admin/pages/edit/show/' . $page->ID . "\"$classClause>" . Convert::raw2xml($page->Title) . '</a>';
}
function AbsoluteLink($master = false) {
$page = $master ? Dataobject::get_by_id("SiteTree", $this->MasterPageID) : Dataobject::get_by_id("SiteTree", $this->RelatedPageID);
if(!$page) return;
$url = $page->AbsoluteLink();
}
function canView($member = null) {
return $this->MasterPage()->canView($member);
}
function canEdit($member = null) {
return $this->MasterPage()->canView($member);
}
function canDelete($member = null) {
return $this->MasterPage()->canDelete($member);
}
}

View File

@ -57,32 +57,6 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest {
$this->assertEquals($expected_path, $path); $this->assertEquals($expected_path, $path);
} }
function testRelatedPages() {
$this->assertTrue(singleton('RelatedPageLink')->getCMSFields() instanceof FieldList);
$importantpage = $this->objFromFixture('Page', 'importantpage');
$contact = $this->objFromFixture('Page', 'contact');
$link = new RelatedPageLink();
$link->MasterPageID = $importantpage->ID;
$link->RelatedPageID = $contact->ID;
$link->write();
$importantpage->RelatedPages()->add($link);
$this->assertTrue(singleton('SiteTree')->getCMSFields() instanceof FieldList);
$this->assertEquals($importantpage->NormalRelated()->Count(), 1);
$this->assertEquals($contact->ReverseRelated()->Count(), 1);
$this->assertTrue($importantpage->getCMSFields() instanceof FieldList);
$this->assertTrue($contact->getCMSFields() instanceof FieldList);
$this->assertEquals($importantpage->canView(), $link->canView());
$this->assertEquals($importantpage->canEdit(), $link->canEdit());
$this->assertEquals($importantpage->canDelete(), $link->canDelete());
$link->AbsoluteLink(true);
$this->assertEquals($link->RelatedPageAdminLink(), '<a href="admin/pages/edit/show/' . $contact->ID . '" class="cmsEditlink">Contact Us</a>');
}
function testCanEditSiteTree() { function testCanEditSiteTree() {
$admin = $this->objFromFixture('Member', 'admin'); $admin = $this->objFromFixture('Member', 'admin');
$subsite1member = $this->objFromFixture('Member', 'subsite1member'); $subsite1member = $this->objFromFixture('Member', 'subsite1member');