sunnysideup / dataobjectpreview
Allows preview of dataobjects in GridField
Installs: 23
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 4
Type:silverstripe-vendormodule
Requires
- silverstripe/recipe-cms: ^4.0 || ^5.0
This package is auto-updated.
Last update: 2024-10-25 04:37:56 UTC
README
Provides the ability to preview DataObjects in the CMS.
Installation (with composer)
$ composer require heyday/silverstripe-dataobjectpreview
Filesystem permissions
The cache/
directory in this module needs to be writable by PHP for DataObject Preview to work. Previews are rendered to file here to avoid repeated rendering of the same content.
When installing via Composer, you may want to add a post-install script in your project's composer.json
to configure these permissions. For example:
{ // ... "scripts": { "post-install-cmd": [ "chmod 777 silverstripe-dataobjectpreview/cache" ] } }
Example
Usage
DataObjects that you want to preview must implement, DataObjectPreviewInterface
, which consists of one method getPreviewHtml
.
This method getPreviewHtml
must return a string.
getPreviewHtml
public function getPreviewHtml() { return "<html><body>Hello</body></html>"; }
DataObjectPreviewField
getCMSFields
$fields->addFieldToTab( 'Root.Main', new DataObjectPreviewField( 'SomeDataObject', $this, new DataObjectPreviewer($generator) ) );
GridFieldDataObjectPreview
getCMSFields
$fields->addFieldsToTab( 'Root.Items', new GridField( 'Items', 'Items', $this->Items(), $config = GridFieldConfig_RelationEditor::create() ) ); $config->addComponent( new GridFieldDataObjectPreview( new DataObjectPreviewer($generator) ) );
License
SilverStripe DataObject Preview is licensed under an MIT license