Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » New Page Types and Default Page Type

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 2440 Views
  • gakenny
    Avatar
    Community Member
    153 Posts

    New Page Types and Default Page Type Link to this post

    Hello,

    Is there a way to replace the field types inherited on new Page TYypes from the default Page Type?

    What do I mean by this? On each page, the author must enter 'Page name', 'Navigation label' and 'Content'. I would like to create a field called 'Description' and have this field populate the entered value into the 'Page name', 'Navigation label' fields as well.

    In addition, must we have the 'Content' field? Can we change the associated label?

    I am just playing about with the backend at the moment for a project we are working on.

    Kind regards,

    Gary

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: New Page Types and Default Page Type Link to this post

    As far as I know, the only way to easily do this is by removing the Title, Content and MenuTitle fields and then re-adding the appropriate ones.

    For example:

    class MyPage extends Page {

    function getCMSFields() {
    $fields = parent::getCMSFields();

    // remove these fields
    $fields->removeByName('Title');
    $fields->removeByName('Content');

    // re-add the fields, with a different title
    $fields->addFieldToTab('Title', 'My new title');
    $fields->addFieldToTab('Content', 'My Content');

    return $fields;
    }

    }

    Hope this helps!

    Sean

  • gakenny
    Avatar
    Community Member
    153 Posts

    Re: New Page Types and Default Page Type Link to this post

    Thanks Sean!

    Do you know if there is a way to populate those fields automatically? Often, each will have the same value and it seems a shame to make the user enter them three times (I do know that they each are used in a different way).

    Cheers,

    Gary

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: New Page Types and Default Page Type Link to this post

    Which fields would you automatically populate, and from what field(s)?

    Cheers,
    Sean

  • gakenny
    Avatar
    Community Member
    153 Posts

    Re: New Page Types and Default Page Type Link to this post

    Hi Sean,

    I had been thinking of adding a field called Description on a new table. By default, all tables include 'Page name' and 'Navigation label'. I had though of removing 'Page name' and 'Navigation label' when adding a new record to this table and having the value of the 'Description' field added to these two fields when the record is saved.

    Does this make sense?

    Cheers,

    Gary

  • Nathan Cox
    Avatar
    Community Member
    99 Posts

    Re: New Page Types and Default Page Type Link to this post

    I think you can do this in the page's onBeforeWrite() method.

    Try something like:

    protected function onBeforeWrite() {
    $this->Title = $this->Description;
    $this->menuTitle = $this->Description;

    parent::onBeforeWrite();
    }

    Although I'm not actually sure if onBeforeWrite happens before of after $this->Description is set, now I think of it...

  • gakenny
    Avatar
    Community Member
    153 Posts

    Re: New Page Types and Default Page Type Link to this post

    Thanks Nathan, I'll have a look at this.

    2440 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.