Download the PHP package arillo/silverstripe-dataobject-preview without Composer
On this page you can find all versions of the php package arillo/silverstripe-dataobject-preview. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download arillo/silverstripe-dataobject-preview
More information about arillo/silverstripe-dataobject-preview
Files in arillo/silverstripe-dataobject-preview
Package silverstripe-dataobject-preview
Short Description Shows a preview of your dataobjects like the one you get for pages.
License MIT
Homepage https://github.com/arillo/silverstripe-dataobject-preview
Informations about the package silverstripe-dataobject-preview
Dataobject preview
Shows a preview of your dataobjects like the one you get for pages. Works for GridField and ModelAdmin. Works only for Versioned DataObjects.
For the preview to work you need to implement the CMSPreviewable interface on your DataObject and declare the methods getMimeType, CMSEditLink and PreviewLink($action = null).
You also will need to declare the stages this DataObject should show in the preview pane by setting the appropiate static variables to true.
PreviewLink is the only link we are interested for the preview to work. The DataObjectPreviewController will listen for this links to render your MyDataObject with the MyDataObject.ss template in your theme/templates/* folder.
Since activating this feature is a bit hacky, we need to also define a custom template for our CustomModelAdmin.
Requirements
SilverStripe CMS ^4.0
For a SilverStripe 3.x compatible version of this module, please see the 1 branch, or 1.x release line.
Installation
composer require arillo/silverstripe-dataobject-preview:2.0.*
Example
If our CustomModelAdmin looks like this:
We need to create the corresponding template in mysite/templates/Arillo/DataObjectPreview/Admins/Includes/CustomModelAdmin_PreviewPanel.ss with this content copied from version 4.7.0 of the silverstripe/cms module. (Beware that this can vary depending on the version and may be changed over time.)
Usage
By default, the dataobject preview will look for templates with the dataobject classname directly in the templates folder. So for the example above it will look for themes/yourtheme/templates/Arillo/DataObjectPreview/Models/MyDataObject.ss. If you would like to customise this behaviour you can do so by implementing your own renderPreview method on the DataObject.
You can overwrite the main template by placing it either in themes/yourtheme/templates/PreviewDataObject.ss or mysite/PreviewDataObject.ss.
- PreviewDataObject.ss -> Container for MyDataObject preview (Like the main Page.ss)
Since SilverStripe 4.11 supports better previews for DataObject, you might want to disable legacy code injection by this module. It can be turned off by:
Tip: If you are using silverstripe-gridfield-betterbuttons you can disable the dataobject preview links since they are no longer needed. Just add this to your config.yml.
Changelog
V 2.0.2
- added modeladmin support
V 2.0.0
- renamed method previewRender to renderPreview