Version: current

     1 <?php
     2
     3 /**
     4  * This DataObject only exists to provide a link between related pages.
     5  * Unfortunately, there is no way to provide a decent GUI otherwise.
     6  */
     7 class RelatedPageLink extends DataObject {
     8     static $db = array(
     9     );
    10
    11     static $has_one = array(
    12         'RelatedPage' => 'SiteTree',
    13         // Note: The *last* matching has_one relation to SiteTree is used as the link field for the
    14         // has_many (RelatedPages) on SiteTree.  This isn't obvious and the framework could be
    15         // extended in a future version to allow for explicit selection of a has_one relation to
    16         // bind a has_many to.
    17         'MasterPage' => 'SiteTree',
    18     );
    19
    20     function getCMSFields() {
    21         $subsites = Subsite::accessible_sites("CMS_ACCESS_CMSMain");
    22         if(!$subsites) $subsites = new DataObjectSet();
    23
    24         if(Subsite::hasMainSitePermission(null, array("CMS_ACCESS_CMSMain"))) {
    25             $subsites->push(new ArrayData(array('Title' => 'Main site', "\"ID\"" => 0)));
    26         }
    27
    28         if($subsites->Count()) {
    29             $subsiteSelectionField = new DropdownField(
    30                 "CopyContentFromID_SubsiteID",
    31                 "Subsite",
    32                 $subsites->toDropdownMap('ID', 'Title'),
    33                 ($this->CopyContentFromID) ? $this->CopyContentFrom()->SubsiteID : Session::get('SubsiteID')
    34             );
    35         }
    36
    37         // Setup the linking to the original page.
    38         $pageSelectionField = new SubsitesTreeDropdownField(
    39             "RelatedPageID",
    40             _t('VirtualPage.CHOOSE', "Choose a page to link to"),
    41             "SiteTree",
    42             "ID",
    43             "MenuTitle"
    44         );
    45
    46         if (isset($_GET['RelatedPageID_SubsiteID'])) $pageSelectionField->setSubsiteID($_GET['RelatedPageID_SubsiteID']);
    47
    48         $pageSelectionField->setFilterFunction(create_function('$item', 'return $item->ClassName != "VirtualPage";'));
    49
    50         if($subsites->Count()) $fields = new FieldSet($subsiteSelectionField, $pageSelectionField);
    51         else $fields = new FieldSet($pageSelectionField);
    52
    53         return $fields;
    54     }
    55
    56     function RelatedPageAdminLink($master = false) {
    57         $page = $master ? Dataobject::get_by_id("SiteTree", $this->MasterPageID) : Dataobject::get_by_id("SiteTree", $this->RelatedPageID);
    58         $otherPage = $master ? Dataobject::get_by_id("SiteTree", $this->RelatedPageID) : Dataobject::get_by_id("SiteTree", $this->MasterPageID);
    59         if(!$page) return;
    60
    61         // Use cmsEditlink only when moving between different pages in the same subsite.
    62         $classClause = ($page->SubsiteID == $otherPage->SubsiteID) ? ' class="cmsEditlink"' : '';
    63         return '<a href="admin/show/' . $page->ID . "\"$classClause>" . Convert::raw2xml($page->Title) . '</a>';
    64     }
    65
    66     function AbsoluteLink($master = false) {
    67         $page = $master ? Dataobject::get_by_id("SiteTree", $this->MasterPageID) : Dataobject::get_by_id("SiteTree", $this->RelatedPageID);
    68         if(!$page) return;
    69
    70
    71         $url = $page->AbsoluteLink();
    72     }
    73
    74     function canView($member = null) {
    75         return $this->MasterPage()->canView($member);
    76     }
    77     function canEdit($member = null) {
    78         return $this->MasterPage()->canView($member);
    79     }
    80     function canDelete($member = null) {
    81         return $this->MasterPage()->canDelete($member);
    82     }
    83 }
    84
    85 ?>
    86

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -