PHP code example of arillo / silverstripe-dataobject-preview

1. Go to this page and download the library: Download arillo/silverstripe-dataobject-preview library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arillo / silverstripe-dataobject-preview example snippets



namespace Arillo\DataObjectPreview\Models;

use SilverStripe\ORM\CMSPreviewable;
use SilverStripe\ORM\DataObject;

class MyDataObject extends DataObject implements CMSPreviewable
{
    ...

    private static $show_stage_link = true;
    private static $show_live_link = true;

    private static $extensions = array(
        Versioned::class
    );

    private static $versioning = array(
        "Stage",  "Live"
    );

    public function PreviewLink($action = null){
        return Controller::join_links(Director::baseURL(), 'cms-preview', 'show', urlencode($this->ClassName), $this->ID);
    }

    public function getMimeType()
    {
        return 'text/html';
    }

    public function CMSEditLink(){
        ...
    }
    ...
}


namespace Arillo\DataObjectPreview\Admins;

use Arillo\DataObjectPreview\Models\MyDataObject;

class CustomModelAdmin extends ModelAdmin {
    private static $managed_models = array (
		MyDataObject::class
	);
}

namespace Arillo\DataObjectPreview\Models;
class MyDataObject extends DataObject implements CMSPreviewable
{
    ...
    public function renderPreview()
    {
        // this will look for themes/yourtheme/templates/Arillo/DataObjectPreview/Models/MyDataObject.ss
        return $this->renderWith(MyDataObject::class);
    }
}

SilverStripe\DataObjectPreview\Extensions\PreviewGridFieldDetailFormExtension:
  inject_legacy_code: false