Allows preview of dataobjects in GridField
Provides the ability to preview DataObjects in the CMS., (*1)
$ composer require heyday/silverstripe-dataobjectpreview
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., (*2)
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:, (*3)
{ // ... "scripts": { "post-install-cmd": [ "chmod 777 silverstripe-dataobjectpreview/cache" ] } }
, (*4)
DataObjects that you want to preview must implement, DataObjectPreviewInterface
, which consists of one method getPreviewHtml
., (*5)
This method getPreviewHtml
must return a string., (*6)
getPreviewHtml
, (*7)
public function getPreviewHtml() { return "<html><body>Hello</body></html>"; }
getCMSFields
, (*8)
$fields->addFieldToTab( 'Root.Main', new DataObjectPreviewField( 'SomeDataObject', $this, new DataObjectPreviewer($generator) ) );
getCMSFields
, (*9)
$fields->addFieldsToTab( 'Root.Items', new GridField( 'Items', 'Items', $this->Items(), $config = GridFieldConfig_RelationEditor::create() ) ); $config->addComponent( new GridFieldDataObjectPreview( new DataObjectPreviewer($generator) ) );
SilverStripe DataObject Preview is licensed under an MIT license, (*10)