Removed unnecessary BetterNavigatorShouldDisplay and adjusted readme around using custom logic to control the display of the navigator
This commit is contained in:
parent
8d85d5df36
commit
a9576bb520
25
README.md
25
README.md
|
@ -33,10 +33,10 @@ The navigator is auto-injected into your template, and no code changes are neede
|
||||||
|
|
||||||
If your website uses caching, make sure BetterNavigator's output is excluded.
|
If your website uses caching, make sure BetterNavigator's output is excluded.
|
||||||
|
|
||||||
## Disabling the navigator
|
## Custom navigator display logic
|
||||||
|
|
||||||
You can disable the navigator using your own custom logic by defining a `showBetterNavigator(): bool`
|
You can customise the navigator display logic using your own custom logic by defining a `showBetterNavigator(): bool`
|
||||||
method in any controller with the extension applied.
|
method in any controller with the extension applied. By default the navigator will only show on controllers that have a `dataRecord` property that is an instance of `SilverStripe\CMS\Model\SiteTree`.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
public function showBetterNavigator()
|
public function showBetterNavigator()
|
||||||
|
@ -101,25 +101,6 @@ public function BetterNavigatorEditLink()
|
||||||
|
|
||||||
(This example uses [sunnysideup/cms_edit_link_field](https://github.com/sunnysideup/silverstripe-cms_edit_link_field) to automatically find an edit link for a specified DataObject, but you can return any URL.)
|
(This example uses [sunnysideup/cms_edit_link_field](https://github.com/sunnysideup/silverstripe-cms_edit_link_field) to automatically find an edit link for a specified DataObject, but you can return any URL.)
|
||||||
|
|
||||||
## Overriding whether better navigator should be shown or not
|
|
||||||
|
|
||||||
There may be occasions when you wish to override whether better navigator should be shown at all, for example on custom data objects. To do so simply add a `BetterNavigatorShouldDisplay()` method to your Controller, e.g.:
|
|
||||||
```php
|
|
||||||
// EventController.php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Detect whether better navigator should be displayed or not
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function BetterNavigatorShouldDisplay()
|
|
||||||
{
|
|
||||||
return $this->dataRecord
|
|
||||||
&& $this->dataRecord instanceof Event
|
|
||||||
&& $this->dataRecord->ID > 0
|
|
||||||
&& (Director::isDev() || Permission::check('CMS_ACCESS_' . EventAdmin::class));
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Overriding the permissions required for the cms edit link
|
## Overriding the permissions required for the cms edit link
|
||||||
|
|
||||||
By default users are required to have at least the `CMS_ACCESS_CMSMain` permission in order to see the edit link in better navigator, you can override this by setting the `better_navigator_edit_permission` configuration option on your controller to another permission code or an array of permission codes, e.g.:
|
By default users are required to have at least the `CMS_ACCESS_CMSMain` permission in order to see the edit link in better navigator, you can override this by setting the `better_navigator_edit_permission` configuration option on your controller to another permission code or an array of permission codes, e.g.:
|
||||||
|
|
|
@ -66,7 +66,7 @@ class BetterNavigatorExtension extends DataExtension
|
||||||
*/
|
*/
|
||||||
public function showBetterNavigator()
|
public function showBetterNavigator()
|
||||||
{
|
{
|
||||||
return true;
|
return $this->isAPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -165,14 +165,8 @@ class BetterNavigatorExtension extends DataExtension
|
||||||
return $this->owner->getField('_betterNavigatorShouldDisplay');
|
return $this->owner->getField('_betterNavigatorShouldDisplay');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->owner->hasMethod('BetterNavigatorShouldDisplay')) {
|
|
||||||
$result = $this->owner->BetterNavigatorShouldDisplay();
|
|
||||||
$this->owner->setField('_betterNavigatorShouldDisplay', $result);
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure this is a page
|
// Make sure this is a page
|
||||||
if (!$this->isAPage() || !$this->owner->showBetterNavigator()) {
|
if (!$this->owner->showBetterNavigator()) {
|
||||||
$this->owner->setField('_betterNavigatorShouldDisplay', false);
|
$this->owner->setField('_betterNavigatorShouldDisplay', false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue