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

1.0.5 2015-11-12 09:41 UTC

This package is auto-updated.

Last update: 2024-03-29 03:07:12 UTC


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

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