From 68694c01b7a825970be978bd66164fd3bf034ce8 Mon Sep 17 00:00:00 2001 From: Jake Bentvelzen Date: Tue, 15 Mar 2016 10:48:46 +1100 Subject: [PATCH] Added readonly version of SiteTreeURLSegmentFiled, small quality of life thing when a user is looking at readonly data and wants to easily view the frontend of that page. --- code/forms/SiteTreeURLSegmentField.php | 23 ++++++++++++++++++++++ templates/forms/SiteTreeURLSegmentField.ss | 8 +++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/code/forms/SiteTreeURLSegmentField.php b/code/forms/SiteTreeURLSegmentField.php index 0ea7d87c..3e4a63ea 100644 --- a/code/forms/SiteTreeURLSegmentField.php +++ b/code/forms/SiteTreeURLSegmentField.php @@ -133,4 +133,27 @@ class SiteTreeURLSegmentField extends TextField { return Controller::join_links($this->getURLPrefix(), $this->Value(), $this->getURLSuffix()); } + public function performReadonlyTransformation() { + $newInst = parent::performReadonlyTransformation(); + $newInst->helpText = $this->helpText; + $newInst->urlPrefix = $this->urlPrefix; + $newInst->urlSuffix = $this->urlSuffix; + $newInst->defaultUrl = $this->defaultUrl; + return $newInst; + } +} + + +/** + * Readonly version of a site tree URL segment field + * + * @package forms + * @subpackage fields-basic + */ +class SiteTreeURLSegmentField_Readonly extends SiteTreeURLSegmentField { + protected $readonly = true; + + public function performReadonlyTransformation() { + return clone $this; + } } diff --git a/templates/forms/SiteTreeURLSegmentField.ss b/templates/forms/SiteTreeURLSegmentField.ss index 57effe1f..c7fbfce9 100644 --- a/templates/forms/SiteTreeURLSegmentField.ss +++ b/templates/forms/SiteTreeURLSegmentField.ss @@ -2,9 +2,11 @@ $URL - + <% if not $IsReadonly %> + + <% end_if %>