mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
NEW Add preview state for non-versioned DataObjects. (#2692)
Currently only Versioned DataObjects are enabled for the CMS preview. Without a navigator item, non-versioned DataObjects aren't allowed to display in the preview panel even if they implement CMSPreviewable.
This commit is contained in:
parent
ab22108c85
commit
803f19b3a4
67
code/Controllers/SilverStripeNavigatorItem_Unversioned.php
Normal file
67
code/Controllers/SilverStripeNavigatorItem_Unversioned.php
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\CMS\Controllers;
|
||||||
|
|
||||||
|
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem;
|
||||||
|
use SilverStripe\Core\Config\Config;
|
||||||
|
use SilverStripe\Core\Convert;
|
||||||
|
use SilverStripe\Security\Member;
|
||||||
|
use SilverStripe\Versioned\Versioned;
|
||||||
|
|
||||||
|
class SilverStripeNavigatorItem_Unversioned extends SilverStripeNavigatorItem
|
||||||
|
{
|
||||||
|
public function getHTML()
|
||||||
|
{
|
||||||
|
$recordLink = Convert::raw2att($this->getLink());
|
||||||
|
$linkTitle = _t('SilverStripe\\CMS\\Controllers\\ContentController.UNVERSIONEDPREVIEW', 'Preview');
|
||||||
|
return "<a class=\"current\" href=\"$recordLink\">$linkTitle</a>";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLink()
|
||||||
|
{
|
||||||
|
return $this->getRecord()->PreviewLink();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle()
|
||||||
|
{
|
||||||
|
return _t(
|
||||||
|
'SilverStripe\\CMS\\Controllers\\ContentController.UNVERSIONEDPREVIEW',
|
||||||
|
'Preview',
|
||||||
|
'Used for the Switch between states (if any other other states are added). Needs to be a short label'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if the record doesn't have the Versioned extension and is configured to display this item.
|
||||||
|
*
|
||||||
|
* @param Member $member
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function canView($member = null)
|
||||||
|
{
|
||||||
|
return (
|
||||||
|
!$this->getRecord()->hasExtension(Versioned::class)
|
||||||
|
&& $this->showUnversionedLink()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if the record is configured to display this item.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function showUnversionedLink(): bool
|
||||||
|
{
|
||||||
|
return (bool) Config::inst()->get(get_class($this->record), 'show_unversioned_preview_link');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This item is always active, as there are unlikely to be other preview states available for the record.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isActive()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -134,6 +134,7 @@ en:
|
|||||||
Password: Password
|
Password: Password
|
||||||
PostInstallTutorialIntro: 'This website is a simplistic version of a SilverStripe 3 site. To extend this, please take a look at {link}.'
|
PostInstallTutorialIntro: 'This website is a simplistic version of a SilverStripe 3 site. To extend this, please take a look at {link}.'
|
||||||
StartEditing: 'You can start editing your content by opening <a href="{link}">the CMS</a>.'
|
StartEditing: 'You can start editing your content by opening <a href="{link}">the CMS</a>.'
|
||||||
|
UNVERSIONEDPREVIEW: 'Preview'
|
||||||
UnableDeleteInstall: 'Unable to delete installation files. Please delete the files below manually'
|
UnableDeleteInstall: 'Unable to delete installation files. Please delete the files below manually'
|
||||||
VIEWPAGEIN: 'View Page in:'
|
VIEWPAGEIN: 'View Page in:'
|
||||||
SilverStripe\CMS\Controllers\SilverStripeNavigator:
|
SilverStripe\CMS\Controllers\SilverStripeNavigator:
|
||||||
|
Loading…
Reference in New Issue
Block a user