Provides the ability to preview DataObjects in the CMS.
$ 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.
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"
]
}
}
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>";
}
getCMSFields
$fields->addFieldToTab(
'Root.Main',
new DataObjectPreviewField(
'SomeDataObject',
$this,
new DataObjectPreviewer($generator)
)
);
getCMSFields
$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
Module rating system helping users find modules that are well supported. For more on how the rating system works visit Module standards
Score not correct? Let us know there is a problem