Skip to content
Provides the ability to preview DataObjects in the CMS
PHP JavaScript CSS
Branch: master
Clone or download
Pull request Compare This branch is 18 commits ahead of heyday:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
_config
cache
client
resources
src
.gitignore
.upgrade.yml
LICENSE
README.md
_config.php
composer.json
upgrade_notes.md

README.md

SilverStripe DataObject Preview

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

DataObject Preview 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

You can’t perform that action at this time.