ENHANCEMENT: open/7886 added preview button to the settings page so that when a user changes the theme they can preview the change.

This commit is contained in:
Jeremy Bridson 2012-10-05 16:27:13 +13:00
parent 0d03c62984
commit 76e569a8bb
2 changed files with 22 additions and 1 deletions

View File

@ -24,6 +24,12 @@ class CMSSettingsController extends LeftAndMain {
$siteConfig = SiteConfig::current_site_config(); $siteConfig = SiteConfig::current_site_config();
$fields = $siteConfig->getCMSFields(); $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(); $actions = $siteConfig->getCMSActions();
$form = new Form($this, 'EditForm', $fields, $actions); $form = new Form($this, 'EditForm', $fields, $actions);
$form->addExtraClass('root-form'); $form->addExtraClass('root-form');
@ -44,6 +50,14 @@ class CMSSettingsController extends LeftAndMain {
return $form; 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 * Save the current sites {@link SiteConfig} into the database
@ -62,7 +76,9 @@ class CMSSettingsController extends LeftAndMain {
} }
public function LinkPreview() { 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) { public function Breadcrumbs($unlinked = false) {

View File

@ -19,6 +19,11 @@
<% loop Actions %> <% loop Actions %>
$Field $Field
<% end_loop %> <% end_loop %>
<% if Controller.LinkPreview %>
<a href="$Controller.LinkPreview" class="cms-preview-toggle-link ss-ui-button" data-icon="preview">
<% _t('LeftAndMain.PreviewButton', 'Preview') %> &raquo;
</a>
<% end_if %>
</div> </div>
<% end_if %> <% end_if %>
</form> </form>