Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » History: Cannot use object of type DataObjectSet in CheckboxSetField

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1775 Views
  • xmedeko
    Avatar
    Community Member
    94 Posts

    History: Cannot use object of type DataObjectSet in CheckboxSetField Link to this post

    Hi,

    I have a BlogPost class, which has the relationsship:

    static $belongs_many_many = array(
              'Tags' => 'BlogTag'
              );

    and a CheckboxSetField of BlogTags is added in getCMSFields():

    $dataSet = DataObject::get('BlogTag');
    if( $dataSet ) {
    $theCheckboxFieldSet = new CheckboxSetField(
                       'Tags',
                       'Tags for this blog post',
                       $dataSet,
                       $idList);
    $fields->addFieldToTab('Root.Content.Tags', $theCheckboxFieldSet );
    }

    In the CMS, is I click to the history of any BlogPost page, I got the error:

    Fatal error: Cannot use object of type DataObjectSet as array in /var/www/xebidy/sapphire/forms/CheckboxSetField.php on line 130

    When I comment out the CheckboxSetField in the getCMSFields(), I can access the history of BlogPost. Do I do something wrong, or is this a SS bug?

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: History: Cannot use object of type DataObjectSet in CheckboxSetField Link to this post

    first, make sure you've got $many_many = array("BlogPosts"=>"BlogPost") on the other side (BlogPost.php).

    CheckboxSetField accepts DataObjectSets in the constructor, but it doesn't seem to process them correctly (I've filed a bug for that). please use an id-list instead:

    $theCheckboxFieldSet = new CheckboxSetField(
    'Tags',
    'Tags for this blog post',
    $dataSet->toDropDownMap(),
    $idList);

    CheckboxSetField actually extends DropdownField, so they share a lot of behaviour.

  • xmedeko
    Avatar
    Community Member
    94 Posts
    1775 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.