Jump to:

791 Posts in 369 Topics by 303 members

Widgets

SilverStripe Forums » Widgets » Using TreeDropdownField() in widget admin editor.

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 817 Views
  • DubbeleJ
    Avatar
    Community Member
    9 Posts

    Using TreeDropdownField() in widget admin editor. Link to this post

    Hello,

    I have created a widget, in which I want to bind a PageID/SiteTreeID to the widget to load data. In order to select the page ID my first solution was to use the TreeDropdownField(). I have the following code to generate my admin for the widget:

       public function getCMSFields() {
          return new FieldList(
             new TextField("WidgetTitle", "WidgetTitel"),
             new TreeDropdownField("PageID", "Kies pagina voor submenu", "SiteTree")
          );
       }

    However when I use this, I get the following error:

    Fatal error: Call to a member function FormAction() on a non-object in C:\xampp\htdocs\4happyfeet.nl\framework\forms\FormField.php on line 139

    Do I need some additional things in my Widget in order to make this work, like dependencies in Javascript and such?

    Any ideas regarding this would be appreciated.

    Regards,
    Jan Jaap

  • Matty Balaam
    Avatar
    Community Member
    69 Posts

    Re: Using TreeDropdownField() in widget admin editor. Link to this post

    Possibly too late, but there are several fields missing in the SS3 Widgets module, and it seems TreeDropDownField is one.

    To get around this I used a regular DropdownField, you only get a flat list with no nesting of sub menus however:

    new DropdownField("PageLinkID", "Page to link to", SiteTree::get()->map())

    Unfortunately, I then had another problem, I couldn't get the link into my widget template. I would usually use <a href="$PageLinkID.Link" > but that doesn't seem to work in a widget

    After much hacking around I managed to create a function in a WidgetController class

    class PageLinkWidget_Controller extends Widget_Controller {
       
          public function SiteTreeLink($pageID){
             $page = SiteTree::get()->byID($pageID)->Link();
             if ($page) return $page;
          }      
    }

    Then inside the template I used: <a href ="$SiteTreeLink($PageLinkID)">

    If there's a simpler way I'm all ears, but it works.

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