753 Posts in 310 Topics by 289 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 808 Views |
-
Using HasManyComplexTableField in a Widget

13 April 2011 at 4:22am Last edited: 13 April 2011 4:29am
Is it possible to use a HasManyComplexTableField in a Widget?
I'm trying to piece together a quick widget which will allow people to create and manage a list of links without dealing with an editor (yes, there's a need for this in my user base...).
The Widget class I have so far is:
class ListWidget extends Widget {
public static $db = array(
'Title' => 'Varchar'
);public static $has_many = array(
'ListItems' => 'ListItem'
);static $title = '';
static $cmsTitle = 'List of Links';
static $description = 'Create, Manage, and Title a list of links';function Title() {
return $this->Title;
}function Items() {
$output = new DataObjectSet();$items = $this->ListItems;
foreach( $items as $item ) {
$output->push(
new ArrayData(
array(
'Text' => $item->Text,
'Link' => $item->Link
)
)
);
}return $output;
}
function getCMSFields() {
$fields = new FieldSet();$titleField = new TextField( 'Title', 'Title' );
$fields->push( $titleField );$listItemsField = new HasManyComplexTableField( $this, 'ListItems', 'ListItem', array( 'Text' => 'Text', 'Link' => 'Link' ) );
$fields->push( $listItemsField );return $fields;
}}
...and the ListItem DataObject looks like this:
class ListItem extends DataObject {
public static $db = array(
'Text' => 'Varchar',
'Link' => 'Varchar'
);public static $has_one = array(
'ListWidget' => 'ListWidget'
);}
This all seems like it should work, but when I try to add the Widget to a WidgetArea I get the following error:
Fatal error: Call to a member function FormAction() on a non-object in C:<webroot>\sapphire\forms\FormField.php on line 98
Any idea as to what's going on here?
-
Re: Using HasManyComplexTableField in a Widget

13 April 2011 at 8:35am
Hrrm,...
I think I've come to the conclusion that what I'm trying to do is simply impossible in SilverStripe. I'm not certain if it's because the Widget class isn't under SiteTree or what...
SilverStripe widgets have a fairly odd implementation... they're just not what I expected them to be, I guess.
-
Re: Using HasManyComplexTableField in a Widget

28 July 2011 at 9:42am
any luck on this? I tried some other form fields all referncing dataobjects which would work fine on a page but cause the same error when on a widget. anyone else had any success with this?
Call to a member function FormAction() on a non-object
cheers Will
| 808 Views | ||
|
Page:
1
|
Go to Top |

