Skip to content

Commit

Permalink
DOC Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Dec 21, 2022
1 parent fc24cb9 commit 77fe84a
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A stand-alone `GridField` component that enables previewing records directly fro

## Install

```
```sh
composer require guysartorelli/silverstripe-gridfield-preview
```

Expand All @@ -18,7 +18,7 @@ Click the preview button in the gridfield. This will automatically open the prev

## Developer Usage

So far this has only been tested in a `ModelAdmin` which manages a `CMSPreviewable` model. This is not guaranteed to work in a `GridField` sitting inside the edit form of another `CMSPreviewable` record - though if you do try that, let me know how it goes.
### Directly inn a `ModelAdmin`

The easiest way to use this module is to add `PreviewableModelAdminExtension` as an extension for your `ModelAdmin` subclass. By default this will add a preview button to the gridfield for all tabs that have `CMSPreviewable` models.

Expand All @@ -37,3 +37,27 @@ MyApp\Admin\MyModelAdmin:
gridfield_previewable_classes:
- MyApp\Model\MyPreviewableModel
```
### In literally any other `GridField`

You can add the `GridFieldPreviewButton` `GridField` component to literally _any_ `GridField`, even one that belongs to a `DataObject` which has its own preview!

```php
use GuySartorelli\GridFieldPreview\GridFieldPreviewButton;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordViewer;
//...
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', GridField::create('SomethingPreviewable', 'Something Previewable', BaseElement::get(), $config = GridFieldConfig_RecordViewer::create()));
// Here's the important part - add the GridFieldPreviewButton component!
$config->addComponent(GridFieldPreviewButton::create());
return $fields;
}
```

0 comments on commit 77fe84a

Please sign in to comment.