Skip to content
This repository
Browse code

BUG Use AbsoluteLiveLink() for CMS previews

It uses the correct live URLSegments for its parents
by setting the global Versioned reading mode correctly,
see 8a514d8 for detail.
  • Loading branch information...
commit cec461b767c7ddeaa6da3047d4b65bab43f98f7d 1 parent 8a514d8
Ingo Schommer authored August 28, 2012

Showing 1 changed file with 8 additions and 9 deletions. Show diff stats Hide diff stats

  1. 17  code/controllers/CMSMain.php
17  code/controllers/CMSMain.php
@@ -573,22 +573,21 @@ public function getEditForm($id = null, $fields = null) {
573 573
 
574 574
 			$fields->push($idField = new HiddenField("ID", false, $id));
575 575
 			// Necessary for different subsites
576  
-			$fields->push($liveURLField = new HiddenField("AbsoluteLink", false, $record->AbsoluteLink()));
577  
-			$fields->push($liveURLField = new HiddenField("LiveLink"));
578  
-			$fields->push($stageURLField = new HiddenField("StageLink"));
  576
+			$fields->push($liveLinkField = new HiddenField("AbsoluteLink", false, $record->AbsoluteLink()));
  577
+			$fields->push($liveLinkField = new HiddenField("LiveLink"));
  578
+			$fields->push($stageLinkField = new HiddenField("StageLink"));
579 579
 			$fields->push(new HiddenField("TreeTitle", false, $record->TreeTitle));
580 580
 
581 581
 			$fields->push(new HiddenField('Sort','', $record->Sort));
582 582
 
583 583
 			if($record->ID && is_numeric( $record->ID ) ) {
584  
-				$liveRecord = Versioned::get_one_by_stage('SiteTree', 'Live', "\"SiteTree\".\"ID\" = $record->ID");
585  
-				if($liveRecord) {
586  
-					$liveURLField->setValue(Controller::join_links($liveRecord->AbsoluteLink(), '?stage=Live'));
  584
+				$liveLink = $record->getAbsoluteLiveLink();
  585
+				if($liveLink) $liveLinkField->setValue($liveLink);
  586
+				if(!$deletedFromStage) {
  587
+					$stageLink = Controller::join_links($record->AbsoluteLink(), '?stage=Stage');
  588
+					if($stageLink) $stageLinkField->setValue($stageLink);
587 589
 				}
588 590
 			}
589  
-			if(!$deletedFromStage) {
590  
-				$stageURLField->setValue(Controller::join_links($record->AbsoluteLink(), '?stage=Stage'));
591  
-			}
592 591
 			
593 592
 			// Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load
594 593
 			if(in_array('CMSPreviewable', class_implements($record)) && !$fields->fieldByName('SilverStripeNavigator')) {

0 notes on commit cec461b

Please sign in to comment.
Something went wrong with that request. Please try again.