Jump to:

23489 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Page Type Permissions & TextField Value Not Working

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: 1
Go to End
Author Topic: 1479 Views
  • Liam
    Avatar
    Community Member
    470 Posts

    Page Type Permissions & TextField Value Not Working Link to this post

    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?

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Page Type Permissions & TextField Value Not Working Link to this post

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

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: Page Type Permissions & TextField Value Not Working Link to this post

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

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