{"id":20816081,"url":"https://github.com/arillo/silverstripe-dataobject-preview","last_synced_at":"2025-05-07T12:40:45.639Z","repository":{"id":47395873,"uuid":"70848914","full_name":"arillo/silverstripe-dataobject-preview","owner":"arillo","description":"Preview your dataobjects like pages in the SilverStripe CMS.","archived":false,"fork":false,"pushed_at":"2024-01-25T15:19:56.000Z","size":70,"stargazers_count":4,"open_issues_count":2,"forks_count":3,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-29T14:47:32.455Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://arillo.github.io/silverstripe-dataobject-preview/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arillo.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"License.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-13T21:17:50.000Z","updated_at":"2021-12-02T16:00:40.000Z","dependencies_parsed_at":"2024-11-17T21:28:13.619Z","dependency_job_id":"a562ab4e-869e-40be-b874-a5d88811229b","html_url":"https://github.com/arillo/silverstripe-dataobject-preview","commit_stats":{"total_commits":41,"total_committers":6,"mean_commits":6.833333333333333,"dds":"0.41463414634146345","last_synced_commit":"de70f46689069d245411a57459f848eea0ec0069"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arillo%2Fsilverstripe-dataobject-preview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arillo%2Fsilverstripe-dataobject-preview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arillo%2Fsilverstripe-dataobject-preview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arillo%2Fsilverstripe-dataobject-preview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arillo","download_url":"https://codeload.github.com/arillo/silverstripe-dataobject-preview/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252879005,"owners_count":21818688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T21:27:57.755Z","updated_at":"2025-05-07T12:40:45.615Z","avatar_url":"https://github.com/arillo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dataobject preview\n\n[![Latest Stable Version](https://poser.pugx.org/arillo/silverstripe-dataobject-preview/v/stable?format=flat)](https://packagist.org/packages/arillo/silverstripe-dataobject-preview)\n[![Total Downloads](https://poser.pugx.org/arillo/silverstripe-dataobject-preview/downloads?format=flat)](https://packagist.org/packages/arillo/silverstripe-dataobject-preview)\n\nShows a preview of your dataobjects like the one you get for pages. Works for GridField and ModelAdmin. Works only for Versioned DataObjects.\n\nFor the preview to work you need to implement the CMSPreviewable interface on your DataObject and declare the methods getMimeType, CMSEditLink and PreviewLink($action = null).\n\nYou also will need to declare the stages this DataObject should show in the preview pane by setting the appropiate static variables to true.\n\nPreviewLink 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.\n\nSince activating this feature is a bit hacky, we need to also define a custom template for our CustomModelAdmin.\n\n## Requirements\n\nSilverStripe CMS ^4.0\n\nFor a SilverStripe 3.x compatible version of this module, please see the [1 branch, or 1.x release line](https://github.com/arillo/silverstripe-arbitrarysettings/tree/1.0).\n\n## Installation\n\n    composer require arillo/silverstripe-dataobject-preview:2.0.*\n\n## Example\n\n```php\n\u003c?php\nnamespace Arillo\\DataObjectPreview\\Models;\n\nuse SilverStripe\\ORM\\CMSPreviewable;\nuse SilverStripe\\ORM\\DataObject;\n\nclass MyDataObject extends DataObject implements CMSPreviewable\n{\n    ...\n\n    private static $show_stage_link = true;\n    private static $show_live_link = true;\n\n    private static $extensions = array(\n        Versioned::class\n    );\n\n    private static $versioning = array(\n        \"Stage\",  \"Live\"\n    );\n\n    public function PreviewLink($action = null){\n        return Controller::join_links(Director::baseURL(), 'cms-preview', 'show', urlencode($this-\u003eClassName), $this-\u003eID);\n    }\n\n    public function getMimeType()\n    {\n        return 'text/html';\n    }\n\n    public function CMSEditLink(){\n        ...\n    }\n    ...\n}\n```\n\nIf our CustomModelAdmin looks like this:\n\n```php\n\u003c?php\nnamespace Arillo\\DataObjectPreview\\Admins;\n\nuse Arillo\\DataObjectPreview\\Models\\MyDataObject;\n\nclass CustomModelAdmin extends ModelAdmin {\n    private static $managed_models = array (\n\t\tMyDataObject::class\n\t);\n}\n```\n\nWe 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.)\n\n```html\n\u003cdiv\n    class=\"cms-preview fill-height flexbox-area-grow\"\n    data-layout-type=\"border\"\n\u003e\n    \u003cdiv class=\"panel flexbox-area-grow fill-height\"\u003e\n        \u003cdiv class=\"preview-note\"\u003e\n            \u003cspan\u003e\u003c!-- --\u003e\u003c/span\u003e\u003c%t\n            SilverStripe\\CMS\\Controllers\\CMSPageHistoryController.PREVIEW\n            'Website preview' %\u003e\n        \u003c/div\u003e\n        \u003cdiv class=\"preview__device\"\u003e\n            \u003cdiv class=\"preview-device-outer\"\u003e\n                \u003cdiv class=\"preview-device-inner\"\u003e\n                    \u003ciframe\n                        src=\"about:blank\"\n                        class=\"center\"\n                        name=\"cms-preview-iframe\"\n                    \u003e\u003c/iframe\u003e\n                \u003c/div\u003e\n            \u003c/div\u003e\n        \u003c/div\u003e\n    \u003c/div\u003e\n    \u003cdiv\n        class=\"toolbar toolbar--south cms-content-controls cms-preview-controls\"\n    \u003e\u003c/div\u003e\n    \u003cdiv class=\"cms-preview-overlay ui-widget-overlay-light\"\u003e\u003c/div\u003e\n\u003c/div\u003e\n```\n\n## Usage\n\nBy 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.\nIf you would like to customise this behaviour you can do so by implementing your own renderPreview method on the DataObject.\n\n```php\nnamespace Arillo\\DataObjectPreview\\Models;\nclass MyDataObject extends DataObject implements CMSPreviewable\n{\n    ...\n    public function renderPreview()\n    {\n        // this will look for themes/yourtheme/templates/Arillo/DataObjectPreview/Models/MyDataObject.ss\n        return $this-\u003erenderWith(MyDataObject::class);\n    }\n}\n```\n\nYou can overwrite the main template by placing it either in themes/yourtheme/templates/PreviewDataObject.ss or mysite/PreviewDataObject.ss.\n\n-   PreviewDataObject.ss -\u003e Container for MyDataObject preview (Like the main Page.ss)\n\n\nSince 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:\n\n```\nSilverStripe\\DataObjectPreview\\Extensions\\PreviewGridFieldDetailFormExtension:\n  inject_legacy_code: false\n```\n\nTip: If you are using [silverstripe-gridfield-betterbuttons](https://github.com/unclecheese/silverstripe-gridfield-betterbuttons) you can disable the dataobject preview links since they are no longer needed. Just add this to your config.yml.\n\n```\nBetterButtonsActions:\n  edit:\n    BetterButtonFrontendLinksAction: false\n  versioned_edit:\n    BetterButtonFrontendLinksAction: false\n```\n\n## Changelog\n\nV 2.0.2\n\n-   added modeladmin support\n\nV 2.0.0\n\n-   renamed method previewRender to renderPreview\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farillo%2Fsilverstripe-dataobject-preview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farillo%2Fsilverstripe-dataobject-preview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farillo%2Fsilverstripe-dataobject-preview/lists"}