BUGFIX: Improved linking behavior of links and reverse links. (from r89843)

This commit is contained in:
Tom Rix 2010-03-01 21:38:38 +00:00
parent 0ba7ee6b17
commit 61d67accf7
2 changed files with 26 additions and 16 deletions

View File

@ -59,11 +59,24 @@ class RelatedPageLink extends DataObject {
return $fields; return $fields;
} }
function RelatedPageAdminLink() { function RelatedPageAdminLink($master = false) {
return '<a href="admin/show/' . $this->RelatedPage()->ID . '" class="cmsEditlink">' . Convert::raw2xml($this->RelatedPage()->Title) . '</a>'; $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) return;
// Use cmsEditlink only when moving between different pages in the same subsite.
$classClause = ($page->SubsiteID == $otherPage->SubsiteID) ? ' class="cmsEditlink"' : '';
return '<a href="admin/show/' . $page->ID . "\"$classClause>" . Convert::raw2xml($page->Title) . '</a>';
} }
function AbsoluteLink() { function AbsoluteLink($master = false) {
$url = $this->RelatedPage()->AbsoluteLink(); $page = $master ? Dataobject::get_by_id("SiteTree", $this->MasterPageID)
: Dataobject::get_by_id("SiteTree", $this->RelatedPageID);
if(!$page) return;
$url = $page->AbsoluteLink();
return '<a href="' . Convert::raw2att($url) .'" class="externallink">' . Convert::raw2xml($url) . '</a>'; return '<a href="' . Convert::raw2att($url) .'" class="externallink">' . Convert::raw2xml($url) . '</a>';
} }

View File

@ -188,27 +188,24 @@ class SiteTreeSubsites extends SiteTreeDecorator {
$related->setPermissions(array('add', 'edit', 'delete')); $related->setPermissions(array('add', 'edit', 'delete'));
if($reverse) { if($reverse) {
$text = '<p>In addition, this page is marked as related by the following pages: </p><ul>'; $text = '<p>In addition, this page is marked as related by the following pages: </p><p>';
foreach($reverse as $rpage) { foreach($reverse as $rpage) {
$text .= '<ul><a href="admin/show/' . $rpage->ID . '" class="cmsEditlink">' . $rpage->Title . '</a> '.$rpage->AbsoluteLink().'</ul>'; $text .= $rpage->RelatedPageAdminLink(true) . " - " . $rpage->AbsoluteLink(true) . "<br />\n";
} }
$text .= '</ul>'; $text .= '</p>';
$tab->push(new LiteralField('ReverseRelated', $text)); $tab->push(new LiteralField('ReverseRelated', $text));
} }
} }
/**
* Returns the RelatedPageLink objects that are reverse-associated with this page.
*/
function ReverseRelated() { function ReverseRelated() {
$return = new DataObjectSet(); return DataObject::get('RelatedPageLink', 'RelatedPageID = ' . $this->owner->ID,'',
$links = DataObject::get('RelatedPageLink', 'RelatedPageID = ' . $this->owner->ID); "INNER JOIN \"SiteTree\" ON \"SiteTree\".\"ID\" = \"RelatedPageLink\".\"MasterPageID\""
if($links) foreach($links as $link) { );
if($link->MasterPage()->exists()) {
$return->push($link->MasterPage());
}
}
return $return->Count() > 0 ? $return : false;
} }
function NormalRelated() { function NormalRelated() {