Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Widgets /

Discuss SilverStripe Widgets.

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

Using a DataObjectManager in widget


2 Posts   798 Views


Community Member, 10 Posts

23 November 2011 at 3:26am

Edited: 23/11/2011 3:28am


I'm trying to convert the Nivo Slider extension into a widget, because I don't like it to mix up page types just for something I'd like to use on multiple page types. The original Nivo Slider extension can be found here:

Anyway, as can be seen in the attached screenshot, it all seems to work, except for the edit link of an item.
The edit link refers to[NivoSliderItems][start]=0&ctf[NivoSliderItems][per_page]=10&ctf[NivoSliderItems][showall]=0&ctf[NivoSliderItems][sort]=&ctf[NivoSliderItems][sort_dir]=&ctf[NivoSliderItems][search]=&ctf[NivoSliderItems][filter]=

And that link just doesn't work.
Is it possible at all to use the DataObjectManager in the widget area? Are there any examples out there?

Here's the relevant code for the widget

class NivoSliderWidget extends Widget {

   static $db = array(
      'effect' => "Enum('sliceDown,sliceDownLeft,sliceUp,sliceUpLeft,sliceUpDown,sliceUpDownLeft,fold,fade,random','random')",

   static $has_many = array('NivoSliderItems' => 'NivoSliderItem');
   public function getCMSFields() {
      $f = new FieldSet(
         new DropdownField('effect',"Effect", singleton('NivoSliderWidget')->dbObject('effect')->enumValues()),
         new TextField('captionOpacity','Universal caption opacity 0-1'),
         new TabSet("Tabs",
            new Tab("Items",
               new DataObjectManager($this, 'NivoSliderItems', 'NivoSliderItem', array(
                  'Thumbnail' => _t('Image.PLURALNAME'),
                  'Title' => _t('SiteTree.METATITLE'),
                  'Tagline' => _t('SiteTree.METADESC')),
      return $f;

And the DataObject for the NivoSliderItem looks like:

class NivoSliderItem extends DataObject {
   static $db = array (
      'Title' => 'Text',
      'Tagline' => 'Text'

   static $has_one = array(
      'NivoSliderWidget' => 'NivoSliderWidget',
      'PanelImage' => 'Image',
   'PanelLink' => 'SiteTree'
   static $api_access = true;
   public function getCMSFields_forPopup(){
    $imager=new $image('PanelImage',_t('Image.SINGULARNAME')." ...");
      return new FieldSet(
         new TextField('Title',_t('SiteTree.METATITLE')),
         new TextField('Tagline',_t('SiteTree.METADESC')),
         new $tree("PanelLinkID",_t('RedirectorPage.REDIRECTTOPAGE'),"SiteTree")

Any idea's?
Btw, the item show is added manually to the database :)

Best regards,

Aaron Brockhurst

Community Member, 30 Posts

15 December 2011 at 7:45pm

Did you find a solution to this?

Is it possible to have either a DataobjectManager or ComplexTableField in a widget?