Source of file PreviewPage.php
Size: 1,418 Bytes - Last Modified: 2021-12-24T06:19:13+00:00
/var/www/docs.ssmods.com/process/src/example_files/PreviewPage.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 | <?PHP class PreviewPage extends Page { public static $db = array( ); public static $has_one = array( ); public static $has_many = array( ); public function getCMSFields() { $fields = parent::getCMSFields(); return $fields; } } class PreviewPage_Controller extends Page_Controller implements CanPreviewableDataObject { public static $allowed_actions = array( 'show' ); public $exampleObject; public function getPreviewAction(SiteTree $page, PreviewableDataObject $obj) { /* * $obj is an instance of ExampleObject in this case. * 'show' can be what ever action you wish the controller to use */ return $page->Link('show/' . $obj->ID); } public function index($request){ // Could list all ExampleObjects etc. Just show blank in the CMS Preview panel. return $this->renderWith('PreviewableDataObjectEmpty', 'Page'); } public function show($request){ $this->exampleObject = ExampleObject::get()->filter(array('ID' => $request->param('ID')))->First(); if ( is_null($this->exampleObject) ) { // This means the object is either new in the CMS or doesn't exist return $this->renderWith('PreviewableDataObjectEmpty', 'Page'); } return $this->renderWith('PreviewPage', 'Page'); } public function getName(){ return $this->exampleObject->Name; } } |