Jump to:

5453 Posts in 1674 Topics by 1198 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Get all versions of the current page

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1225 Views
  • PGiessler
    Avatar
    Community Member
    47 Posts

    Get all versions of the current page Link to this post

    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!

  • bschmitt
    Avatar
    Community Member
    22 Posts

    Re: Get all versions of the current page Link to this post

    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

  • PGiessler
    Avatar
    Community Member
    47 Posts

    Re: Get all versions of the current page Link to this post

    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

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Get all versions of the current page Link to this post

    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');
    }

    1225 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.