Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Can only display one TreeDropdownField ?

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

Page: 1
Go to End
Author Topic: 1373 Views
  • _Vince
    Avatar
    Community Member
    156 Posts

    Can only display one TreeDropdownField ? Link to this post

    I'm trying to get a "featured content" thing happening.
    There's supposed to be a bit of text, a heading, an associated image and two page id's.
    One would be for the page where the content will be displayed and the other would be a page that the user would be taken to if they click on the associated image.

    I've read that the TreeDropdownField doesn't work in widgets, so I've created a page where users can input the featured content and say on which pages they want it.

    So far it looks like this:

    class FeaturedContent extends DataObject{

    static $db = array(
    "FeaturedContentTitle" => "Varchar(40)",
    "FeaturedContentText" => "Text",
    "FeaturedContentDisplay" => "Boolean"
    );

    static $has_one = array(
    "FeaturedContentHostPage" => "SiteTree",
    "FeaturedContentLink" => "SiteTree",
    "FeaturedContentImage" => "Image"
    );

    function getCMSFields_forPopup() {

    $fields = new FieldSet();
    $fields->push(new TextField("FeaturedContentTitle", "Title"));
    $fields->push(new TextareaField("FeaturedContentText", "Text"));
    $fields->push(new CheckboxField("FeaturedContentDisplay", "Display this content?"));
    $fields->push(new TreeDropdownField("FeaturedContentHostPageID", "Display On", 'SiteTree'));
    $fields->push(new TreeDropdownField("FeaturedContentLinkID", 'Linkto', 'SiteTree'));
    $fields->push(new ImageField("FeaturedContentImage", "Associated Image"));
    return $fields;
    }
    }

    class ManageFeaturedContentPage extends Page{

    function getCMSFields() {

    $fields = parent::getCMSFields();

       $FeaturedContent = Object::create("FeaturedContent");

    $TableField = new ComplexTableField(
    $controller = $this,
          $name = "lstFeaturedContent",
    $sourceClass = $FeaturedContent->class,
           $fieldList = array(
    'FeaturedContentTitle' => 'Content Title',
    'FeaturedContentText' => 'Content'
    ),
    $functionForPopupFields = "getCMSFields_forPopup",
    $sourceFilter = "",
    $sourceSort = "FeaturedContentTitle"
    );

    $TableField->setPermissions(
    array(
    "add",
    "edit",
    "delete"
    )
    );

    $fields->addFieldToTab( 'Root.Content.Main', $TableField );
    $fields->removeFieldFromTab('Root.Content.Main', 'Content');
    return $fields;
    }
    }

    Now, the odd bit is that the image works fine and ONE of the TreeDropdownFields works fine, but it only ever displays one. I can never get them both displayed and working. Sometimes it's one, sometimes it's the other (can't figure out the rule behind this) and whatever column is not displayed automatically gets assigned the page id of the manage featured content page.

    I've tried using different browsers and tried it on versions 2.3.4 and 2.3.2 and it doesn't work on either of them.

    Can anyone tell me what I am doing wrong?

  • _Vince
    Avatar
    Community Member
    156 Posts

    Re: Can only display one TreeDropdownField ? Link to this post

    I've stumbled upon a workaround but it's a real kludge and I have no idea why it's working, so it's probably going to fail at the worst possible time

    Anyway, I added a third "SiteTree" and now it's actually working.

    static $has_one = array(
    "FeaturedContentImage" => "Image",
    "FeaturedContentLink" => "SiteTree",
    "FeaturedContentHost" => "SiteTree",
    "FeaturedContentLinkToPage" => "SiteTree"
    );

    FeaturedContentLink still doesn't display on the popup, but takes on the page id of the page on which I have the table. It's therefore, always set to "23". I don't know why.

    And FeaturedContentLinkToPage displays and receives the selected page's ID. That's all correct and the way it should be.

    Can someone tell me why this is happening? I've reinstalled SS and the problem is still there. It's not a browser or a version thing either. Weird.

  • _Vince
    Avatar
    Community Member
    156 Posts

    Re: Can only display one TreeDropdownField ? Link to this post

    *bouncing* this in case somebody has had a similar problem before.

    Since my last post, I've come up with a better work-around (eg: rename the TreeDropdownField in the popup to some arbitrary name and then manually assign the values to the database fields in the onBeforeWrite function), but it really worries me that the TreeDropdownField works in such a haphazard way. I'm sure I must be doing something wrong, but what?

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