From 76e569a8bb5c5856fb07717436d1c607a9544093 Mon Sep 17 00:00:00 2001 From: Jeremy Bridson Date: Fri, 5 Oct 2012 16:27:13 +1300 Subject: [PATCH] ENHANCEMENT: open/7886 added preview button to the settings page so that when a user changes the theme they can preview the change. --- code/controllers/CMSSettingsController.php | 18 +++++++++++++++++- .../Includes/CMSSettingsController_EditForm.ss | 5 +++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/code/controllers/CMSSettingsController.php b/code/controllers/CMSSettingsController.php index a5000edb..100769ab 100644 --- a/code/controllers/CMSSettingsController.php +++ b/code/controllers/CMSSettingsController.php @@ -24,6 +24,12 @@ class CMSSettingsController extends LeftAndMain { $siteConfig = SiteConfig::current_site_config(); $fields = $siteConfig->getCMSFields(); + // Tell the CMS what URL the preview should show + $fields->push(new HiddenField('PreviewURL', 'Preview URL', RootURLController::get_homepage_link())); + // Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load + $fields->push($navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator())); + $navField->setAllowHTML(true); + $actions = $siteConfig->getCMSActions(); $form = new Form($this, 'EditForm', $fields, $actions); $form->addExtraClass('root-form'); @@ -44,6 +50,14 @@ class CMSSettingsController extends LeftAndMain { return $form; } + /** + * Used for preview controls, mainly links which switch between different states of the page. + * + * @return ArrayData + */ + public function getSilverStripeNavigator() { + return $this->renderWith('CMSSettingsController_SilverStripeNavigator'); + } /** * Save the current sites {@link SiteConfig} into the database @@ -62,7 +76,9 @@ class CMSSettingsController extends LeftAndMain { } public function LinkPreview() { - return false; + $record = $this->getRecord($this->currentPageID()); + $baseLink = ($record && $record instanceof Page) ? $record->Link('?stage=Stage') : Director::absoluteBaseURL(); + return $baseLink; } public function Breadcrumbs($unlinked = false) { diff --git a/templates/Includes/CMSSettingsController_EditForm.ss b/templates/Includes/CMSSettingsController_EditForm.ss index d233a3df..dcbd4135 100644 --- a/templates/Includes/CMSSettingsController_EditForm.ss +++ b/templates/Includes/CMSSettingsController_EditForm.ss @@ -19,6 +19,11 @@ <% loop Actions %> $Field <% end_loop %> + <% if Controller.LinkPreview %> + + <% _t('LeftAndMain.PreviewButton', 'Preview') %> » + + <% end_if %> <% end_if %>