Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » TreeDropDownField in Popup (SS 2.3.2 / 2.3.3)

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

Page: 1
Go to End
Author Topic: 2373 Views
  • Andre
    Avatar
    Community Member
    125 Posts

    TreeDropDownField in Popup (SS 2.3.2 / 2.3.3) Link to this post

    Hi there,
    I was trying to write a Module for having a Menu with Shortlinks. Therefore my Idea was a class Shortlink, inheriting from DataObject and a ShortlinkPage having many shortlinks.
    This is the Code:
    class ShortLink extends DataObject{
    static $db = array (
    'LinkTitle' => 'Text'
    );
    static $has_one = array (
    'ShortLink' => 'Page'
    );
    function getCMSFields_forPopup(){
    $fields = new FieldSet();
    $fields->push(new TextField('LinkTitle', _t("ShortLink.LINKTITLE", "Link Title:")));
    $fields->push(new TreeDropdownField("ShortLink", _t("ShortLink.SHORTLINK", "Link Target:"), "Page"));
    return $fields;
    }

    }
    class ShortLinkPage extends Page {

    static $has_many = array (
    'ShortLinks' => 'ShortLink'
    );
    public function getCMSFields() {
    $fields = parent::getCMSFields();
    $shortLinks = new ComplexTableField(
    $this,
    _t("ShortLinkPage.SHORTLINKS", "Short Links:"),
    'ShortLink',
    null,
    null
    //"ShortLink.ShortLinkPageID = {$this->ID}"
    );
    $fields->addFieldToTab('Root.Content.Shortlinks', $shortLinks);
    return $fields;
    }
    public function getShortLinks(){
    $page = $this;
    $Shortlinks = $this->ShortLinks();
    print_r($Shortlinks); // this is still not ready, but isn't my problem at the moment
    /*while(!$Menublock->ID && $page->ParentID != 0){
    $page = $page->Parent();
    if(!method_exists($page, 'LinkToMenublock') && $page->ParentID != 0){
    $page = $page->Parent();
    $Menublock = $page->LinkToMenublock();
    }else{
    $Menublock = $page->LinkToMenublock();
    }
    }
    //return new DataObjectSet($Menublock->Children());
    return $Menublock->Children();*/
    }

    }
    class ShortLinkPage_Controller extends ExtendedPage_Controller {
    }
    What doesn't work is the TreeDropDownField inside the Popup for creating a new shortlink (in Version 2.3.2 and 2.3.3, didn't tested 2.3.1). Is this a general Problem, that doesn't work or have I been doing something wrong? Elsewhere is the an alternative way, to slect a page for a collection of Links?

  • BurtOfOz
    Avatar
    Community Member
    3 Posts

    Re: TreeDropDownField in Popup (SS 2.3.2 / 2.3.3) Link to this post

    Gday Andre,

    What do you mean by "doesn't work"? I ran up against some issues with the TreeDropdownField, but have things working ok now.

    If you mean that it creates a single line box underneath the initial box, that makes it next to impossible to select a page from the tree, try changing the order of your fields in the FieldSet, such that the TreeDropdownField isn't the last one on the pop-up.

    If it's something else, let me know and I'll see if I can help.

  • Andre
    Avatar
    Community Member
    125 Posts

    Re: TreeDropDownField in Popup (SS 2.3.2 / 2.3.3) Link to this post

    Now I'm a little confused. With "It doesn't work", I mean, the TreeDropdownField doesn't show up. Now I now I changed the order, which didn't help, and, what is more confusing, I commented the Textfield, but it still shows up (did /dev/build?flush=1 already a few times).

    Here is My code again plus a Screenshot:

    <?php

    class ShortLink extends DataObject{
       static $has_one = array (
    'ShortLink' => 'Page'
    );

    static $db = array (
          'LinkTitle' => 'Text'
       );

       function getCMSFields_forPopup(){
          $fields = new FieldSet();
          $fields->push(new TreeDropdownField("ShortLink", _t("ShortLink.SHORTLINK", "Link Target:"), "Page"));
    //$fields->push(new TextField('LinkTitle', _t("ShortLink.LINKTITLE", "Link Title:")));

          return $fields;
       }
       
    }

    ?>

    Attached Files
  • Andre
    Avatar
    Community Member
    125 Posts

    Re: TreeDropDownField in Popup (SS 2.3.2 / 2.3.3) Link to this post

    Hi, me again,

    the following is also not working. Now I get no fields inside the Popup.

    <?php

    class ShortLink extends DataObject{
       static $has_one = array (
    'ShortLink' => 'Page'
    );

    static $db = array (
          //'LinkTitle' => 'Text'
       );

       function getCMSFields_forPopup(){
          $fields = new FieldSet(
    new TreeDropdownField("ShortLink", _t("ShortLink.SHORTLINK", "Link Target:"), "Page")
    //new TextField('LinkTitle', _t("ShortLink.LINKTITLE", "Link Title:"))
    );

          return $fields;
       }
       
    }

    ?>

    Do I have a stupid mistake, or is this a bug wtihin TreeDropdown or Popup?

  • Andre
    Avatar
    Community Member
    125 Posts

    Re: TreeDropDownField in Popup (SS 2.3.2 / 2.3.3) Link to this post

    Got it working now. Also changed Complextablefield to Dataobjectmanager.

    <?php

    class ShortLink extends DataObject{
    public static $has_one = array (
    'ShortLink' => 'SiteTree'
    );

    public static $db = array (
    'LinkTitle' => 'Text'
    );

    public function getCMSFields_forPopup(){
    $fields = new FieldSet(
    new TreeDropdownField("ShortLink", _t("ShortLink.SHORTLINK", "Link Target:"), "SiteTree"),
    new TextField('LinkTitle', _t("ShortLink.LINKTITLE", "Link Title:"))
    );

    return $fields;
    }
    }

    ?>

    <?php

    class ShortLinkPage extends ExtendedPage {
       
       static $has_many = array (
          'ShortLinks' => 'ShortLink'
       );

       public function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->addFieldToTab('Root.Content.Shortlinks', new DataObjectManager(
    $this,
    _t("ShortLinkPage.SHORTLINKS", "Short Links:"),
    'ShortLink',
    array('LinkTitle' => _t("ShortLinkPage.LINKTITLE", "Link Title")),
    'getCMSFields_forPopup'
    ));

          return $fields;
       }
    }

    class ShortLinkPage_Controller extends ExtendedPage_Controller {
    }

    ?>

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: TreeDropDownField in Popup (SS 2.3.2 / 2.3.3) Link to this post

    I am using SS 2.4.5 and am unable to get a TreeDropdownField to open in the popup modal window. Also, it completely breaks SimpleTinyMCEField.

    //Garrett

  • rodolfocartas
    Avatar
    Community Member
    2 Posts

    Re: TreeDropDownField in Popup (SS 2.3.2 / 2.3.3) Link to this post

    I'm facing the same problem. Did you fix it?

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: TreeDropDownField in Popup (SS 2.3.2 / 2.3.3) Link to this post

    No, so I am using the SimpleTreeDropDownField object from DataObjectManager module. It's not as fancy but it works for my purposes.

    //Garrett

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