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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page Type Permissions & TextField Value Not Working


Reply


3 Posts   1506 Views

Avatar
Liam

Community Member, 470 Posts

8 May 2009 at 7:32am

A couple things.

I have created a VideoType.php page type. I have added the following to my page class:

public static $can_be_root = false;
public static $allowed_children = 'none';

Neither seem to work. I can create this page type with no parent above it, and I can also create any kind of child underneath this page.

Also, I'm trying to populate a TextField with data except nothing is showing up.

$fields->addFieldToTab("Root.Content.Main", new TextField('Author', 'Author', "Testing"), 'Content');

"Testing" does not show up.

I'm using the latest beta version though I'm pretty sure this wasn't working on the stable version I tested the other day.

Am I missing something blatantly obvious, or can somebody confirm this also happens to them?

Avatar
banal

Community Member, 901 Posts

8 May 2009 at 7:48am

Edited: 08/05/2009 7:50am

Hi LeeUmm

As far as I know, $allowed_children should be an array. You could try $allowed_children = array(); instead.
The $can_be_root directive seems to be ignored indeed... maybe a SilverStripe core developer can shed some light on this?

As for your TextField value. It works, as long as the "Author" field isn't a DB field (since its value will be overridden by the value coming from the DB).
If you do:

$fields->addFieldToTab(
   'Root.Content.Main',
   new TextField('NotADBField', 'Author', 'Testing')
);

It works just fine. To set a default value for a DB field, use the $defaults array

public static $defaults = array(
   'Author' => 'Testing'
);

Avatar
Liam

Community Member, 470 Posts

8 May 2009 at 8:02am

Edited: 08/05/2009 8:03am

Thanks for the reply,

I tried changing the $allowed_children to an array and also to $allowed_children = array('none'); with no luck. The docs say just put it like I had in the original topic. Nothing seems to work as I'm able to to create children under them.

As for the populating the text field, thanks for the heads up. To be a bit more specific, I was trying to populate it with the logged in user's name.

I thought this would work? Didn't the blog used to do it like this? Or does? Haven't used it in a while.

function getCMSFields() {
      $firstName = Member::CurrentMember() ? Member::currentMember()->FirstName : '';
      $lastName = Member::CurrentMember() ? Member::currentMember()->Surname : '';      
      
      $fields = parent::getCMSFields();
      
      $fields->addFieldToTab("Root.Content.Main", new TextField('Author', 'Author', "$firstName $lastName"), 'Content');
   
      return $fields;
   }