Skip to content

Commit

Permalink
NEW Let SiteConfig be previewable
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Oct 7, 2022
1 parent c900bc7 commit 458f5dd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
20 changes: 16 additions & 4 deletions code/SiteConfigLeftAndMain.php
Expand Up @@ -10,6 +10,7 @@
use SilverStripe\Forms\HiddenField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\CMSPreviewable;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\ValidationResult;
use SilverStripe\Versioned\RecursivePublishable;
Expand Down Expand Up @@ -79,10 +80,15 @@ public function getEditForm($id = null, $fields = null)
$home = Director::absoluteBaseURL();
$fields->push(new HiddenField('PreviewURL', 'Preview URL', $home));

// Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load
/** @skipUpgrade */
$fields->push($navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator()));
$navField->setAllowHTML(true);
if ($siteConfig instanceof CMSPreviewable || $siteConfig->has_extension(CMSPreviewable::class)) {
// Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load
/** @skipUpgrade */
$fields->push($navField = new LiteralField(
'SilverStripeNavigator',
$this->getSilverStripeNavigator($siteConfig)
));
$navField->setAllowHTML(true);
}

// Retrieve validator, if one has been setup (e.g. via data extensions).
if ($siteConfig->hasMethod("getCMSValidator")) {
Expand Down Expand Up @@ -122,6 +128,12 @@ public function getEditForm($id = null, $fields = null)
$form->loadDataFrom($siteConfig);
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));


// Announce the capability so the frontend can decide whether to allow preview or not.
if ($siteConfig instanceof CMSPreviewable || $siteConfig->has_extension(CMSPreviewable::class)) {
$form->addExtraClass('cms-previewable');
}

// Use <button> to allow full jQuery UI styling
$actions = $actions->dataFields();
if ($actions) {
Expand Down
Expand Up @@ -27,6 +27,14 @@
<%t SilverStripe\\Admin\\LeftAndMain.PreviewButton 'Preview' %> &raquo;
</a>
<% end_if %>

<% if $hasExtraClass('cms-previewable') %>
<% if $Actions.last.id == 'Form_ItemEditForm_RightGroup' %>
<% include SilverStripe\\Admin\\LeftAndMain_ViewModeSelector SelectID="preview-mode-dropdown-in-content", ExtraClass="ml-0" %>
<% else %>
<% include SilverStripe\\Admin\\LeftAndMain_ViewModeSelector SelectID="preview-mode-dropdown-in-content", ExtraClass="ml-auto" %>
<% end_if %>
<% end_if %>
</div>
<% end_if %>
</div>
Expand Down

This file was deleted.

0 comments on commit 458f5dd

Please sign in to comment.