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?