753 Posts in 310 Topics by 289 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 486 Views |
-
Using TreeDropdownField() in widget admin editor.

13 September 2012 at 5:36am Last edited: 13 September 2012 5:47am
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 -
Re: Using TreeDropdownField() in widget admin editor.

31 October 2012 at 7:08am Last edited: 2 November 2012 1:50am
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.
| 486 Views | ||
|
Page:
1
|
Go to Top |


