Jump to:

791 Posts in 369 Topics by 303 members

Widgets

SilverStripe Forums » Widgets » Using HasManyComplexTableField in a Widget

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 977 Views
  • Zooney
    Avatar
    Community Member
    9 Posts

    Using HasManyComplexTableField in a Widget Link to this post

    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?

  • Zooney
    Avatar
    Community Member
    9 Posts

    Re: Using HasManyComplexTableField in a Widget Link to this post

    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.

  • vancouverWill
    Avatar
    Community Member
    121 Posts

    Re: Using HasManyComplexTableField in a Widget Link to this post

    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

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