/**
  *	Update link mappings when replacing the default automated URL handling.
  */
 public function onAfterWrite()
 {
     parent::onAfterWrite();
     // Determine whether the default automated URL handling has been replaced.
     if (Config::inst()->get('MisdirectionRequestFilter', 'replace_default')) {
         // Determine whether the URL segment or parent ID has been updated.
         $changed = $this->owner->getChangedFields();
         if (isset($changed['URLSegment']['before']) && isset($changed['URLSegment']['after']) && $changed['URLSegment']['before'] != $changed['URLSegment']['after'] || isset($changed['ParentID']['before']) && isset($changed['ParentID']['after']) && $changed['ParentID']['before'] != $changed['ParentID']['after']) {
             // The link mappings should only be created for existing pages.
             $URL = isset($changed['URLSegment']['before']) ? $changed['URLSegment']['before'] : $this->owner->URLSegment;
             if (strpos($URL, 'new-') !== 0) {
                 // Determine the page URL.
                 $parentID = isset($changed['ParentID']['before']) ? $changed['ParentID']['before'] : $this->owner->ParentID;
                 $parent = SiteTree::get_one('SiteTree', "SiteTree.ID = {$parentID}");
                 while ($parent) {
                     $URL = Controller::join_links($parent->URLSegment, $URL);
                     $parent = SiteTree::get_one('SiteTree', "SiteTree.ID = {$parent->ParentID}");
                 }
                 // Instantiate a link mapping for this page.
                 singleton('MisdirectionService')->createPageMapping($URL, $this->owner->ID);
                 // Purge any link mappings that point back to the same page.
                 $this->owner->regulateMappings($this->owner->Link() === Director::baseURL() ? Controller::join_links(Director::baseURL(), 'home/') : $this->owner->Link(), $this->owner->ID);
                 // Recursively create link mappings for any children.
                 $children = $this->owner->AllChildrenIncludingDeleted();
                 if ($children->count()) {
                     $this->owner->recursiveMapping($URL, $children);
                 }
             }
         }
     }
 }
コード例 #2
0
ファイル: Project.php プロジェクト: micschk/SilverProject
 function eLink()
 {
     $page = SiteTree::get_one("ProjectPage");
     $link = $page->Link() . "edit/" . $this->ID;
     return $link;
 }
コード例 #3
0
ファイル: Task.php プロジェクト: micschk/SilverProject
 function Link()
 {
     $page = SiteTree::get_one("TaskPage");
     $link = $page->Link() . "show/" . $this->ID;
     return $link;
 }