heyday / silverstripe-dataobjectpreview
Allows preview of dataobjects in GridField
Installs: 4 533
Dependents: 2
Suggesters: 0
Security: 0
Stars: 9
Watchers: 27
Forks: 4
Open Issues: 0
Type:silverstripe-module
Requires
- composer/installers: ~1.0
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