silverstripe-cms/code/Controllers/SilverStripeNavigatorItem_CMSLink.php
Guy Sartorelli d7857ebbe0
API Migrate SilverStripeNagivator classes
These classes are useful with `silverstripe/admin` and
`silverstripe/versioned` without needing `silverstripe/cms`.
2022-10-05 14:24:11 +13:00

49 lines
1.2 KiB
PHP

<?php
namespace SilverStripe\CMS\Controllers;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Admin\Navigator\SilverStripeNavigatorItem;
use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\Control\Controller;
class SilverStripeNavigatorItem_CMSLink extends SilverStripeNavigatorItem
{
/** @config */
private static $priority = 10;
public function getHTML()
{
return sprintf(
'<a href="%s">%s</a>',
$this->record->CMSEditLink(),
_t('SilverStripe\\CMS\\Controllers\\ContentController.CMS', 'CMS')
);
}
public function getTitle()
{
return _t('SilverStripe\\CMS\\Controllers\\ContentController.CMS', 'CMS', 'Used in navigation. Should be a short label');
}
public function getLink()
{
return $this->record->CMSEditLink();
}
public function isActive()
{
return (Controller::curr() instanceof LeftAndMain);
}
public function canView($member = null)
{
return (
// Don't show in CMS
!(Controller::curr() instanceof LeftAndMain)
// Don't follow redirects in preview, they break the CMS editing form
&& !($this->record instanceof RedirectorPage)
);
}
}