Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS

Get all versions of the current page


Reply

4 Posts   1304 Views

Avatar
PGiessler

13 November 2009 at 2:51am Community Member, 47 Posts

Hello everybody,
I'm creating a module and I want to show the versions of the current page. So I wrote the function to get the data. I checked the output with Debug::dump(). It seems to be the right versions. But how can I render this data with a specified template?

At the beginning of loading my cms form the function, which I retrieve the data, will called. The data shall show under my specified tab. But I only get the word 'array'. Furthermore I also add a template, which is called IncludeObjects_version, for rendering my retrieved data.

In the following paragraph I will post my function getCMSFields() and my function versions() to retrieve the data.

public function versions() {
$page = DataObject::get_by_id('IncludeObjects', $id);
if ($page) {
$versions = $page->allversions();
return array(
'Versions' => $versions,
);
}
}

public function getCMSFields($id) {

$fields = new FieldSet(
new TabSet('Root',
new Tab('Content',
new TabSet('Option',
new Tab('Main',
new TextField('IncludeName', _t('IncludeObjectsAdmin.INCLUDENAME','Name'),""),
new TextareaField('IncludeDescription', _t('IncludeObjectsAdmin.INCLUDEDESCRIPTION','Description'),""),
new HTMLEditorField('IncludeContent', _t('IncludeObjectsAdmin.INCLUDECONTENT','Content'),""),
new HiddenField('IncludeUser', _t('IncludeObjectsAdmin.INCLUDEUSER','CurrentUser'), $this->getCurrentMember())
),
new Tab('Log',
new ReadonlyField('ID','Include ID', $id),
new ReadonlyField('LastModifiedUser','Last User', $this->getLogData($id, 'IncludeUser')),
new ReadonlyField('Created', 'Created', $this->getLogData($id, 'Created')),
new ReadonlyField('LastEdited', 'Last Modified', $this->getLogData($id, 'LastEdited')),
new ReadonlyField('LastVersion','Current Version', $this->getLogData($id, 'CurrentVersion'))
),
new Tab('Versions',
new CustomHTMLField('Versions', $this->versions($id))
),
new Tab('Settings',
new ReadonlyField('Publish-Date','Publish-Date', '01.01.2010'),
new ReadonlyField('Owner','Owner','webteam'),
new ReadonlyField('Approval','Approval', 'Jens Armbruster')
)
))) );

if(self::$runCMSFieldsExtensions) {

$this->extend('updateCMSFields', $fields);
}

return $fields;

}

Many thanks for your help!

Avatar
bschmitt

13 November 2009 at 4:38am Community Member, 22 Posts

Do you want to render a DataObjectSet with an template file to a tab in your backend?

public function versions($id) {
$page = DataObject::get_by_id('IncludeObjects', $id); // dataobject set
if ($page) {
$versions = $page->allversions();
return array(
'Versions' => $versions,
);
}
}

new Tab('Versions',
new CustomHTMLField('Versions', $this->versions($id))
),

What does CustomHTMLField do?

Best, Bjoern

Avatar
PGiessler

13 November 2009 at 5:01am Community Member, 47 Posts

Hi bschmitt,

This is exactly what I want to do. The CustomHTMLField is a simple own developed formfield. It just returns the given string parameter (I'm using it for inserting simple html to a form).

I think the reason of my problem is, that SilverStripe doesn't render the incoming data with the given template.

Can someone give me a hint, how to add the DataObject to the new Tab() that it get's rendered with a given template?

Best regards,
Pascal

Avatar
banal

13 November 2009 at 6:04am Community Member, 901 Posts

You must override the Field method of your custom Field. This might look like this:

function Field() {
   Requirements::css('my/custom/styles.css');
   return $this->renderWith('MyTemplate');
}