DOCS Update HistoryViewerField to require javascript more consistently (#9773)

This commit is contained in:
Scott Hutchinson 2020-11-17 10:56:50 +13:00 committed by GitHub
parent 19af9cfc13
commit bdb2deb3f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1264,18 +1264,33 @@ For more information, see [ReactJS, Redux and GraphQL](../../customising_the_adm
### Adding the HistoryViewerField
You can add the [HistoryViewerField](api:SilverStripe\VersionedAdmin\Forms\HistoryViewerField) to your object's CMS
Firstly, ensure your JavaScript bundle is included throughout the CMS:
```yml
---
Name: CustomAdmin
After:
- 'versionedadmincmsconfig'
- 'versionededitform'
- 'cmsscripts'
- 'elemental' # Only needed if silverstripe-elemental is installed
---
SilverStripe\Admin\LeftAndMain:
extra_requirements_javascript:
- app/client/dist/js/bundle.js
```
Then you can add the [HistoryViewerField](api:SilverStripe\VersionedAdmin\Forms\HistoryViewerField) to your object's CMS
fields in the same way as any other form field:
```php
use SilverStripe\VersionedAdmin\Forms\HistoryViewerField;
use SilverStripe\View\Requirements;
public function getCMSFields()
{
$fields = parent::getCMSFields();
Requirements::javascript('app/client/dist/js/bundle.js');
$fields->addFieldToTab('Root.History', HistoryViewerField::create('MyObjectHistory'));
return $fields;