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.

Archive

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

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

New Page Types and Default Page Type


Reply

7 Posts   2452 Views

Avatar
gakenny

31 July 2007 at 8:45pm (Last edited: 31 July 2007 10:43pm), Community Member, 153 Posts

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

Avatar
Sean

31 July 2007 at 9:32pm (Last edited: 31 July 2007 9:38pm), Forum Moderator, 921 Posts

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

Avatar
gakenny

1 August 2007 at 9:58am Community Member, 153 Posts

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

Avatar
Sean

1 August 2007 at 2:00pm Forum Moderator, 921 Posts

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

Cheers,
Sean

Avatar
gakenny

1 August 2007 at 2:48pm Community Member, 153 Posts

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

Avatar
Nathan Cox

1 August 2007 at 3:19pm (Last edited: 1 August 2007 3:19pm), Community Member, 99 Posts

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

Avatar
gakenny

2 August 2007 at 9:06am Community Member, 153 Posts

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