Jump to:

794 Posts in 409 Topics by 304 members

Widgets

SilverStripe Forums » Widgets » Using a DataObjectManager in widget

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 754 Views
  • Ronaldo71
    Avatar
    Community Member
    10 Posts

    Using a DataObjectManager in widget Link to this post

    Hi,

    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:
    http://www.silverstripe.org/nivo-slider-silverstripe-extension-module/

    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

    http://mylocalsite.com/item/1/edit?ctf[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')),
                      'getCMSFields_forPopup'
                   )
                )
             )
       );
          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(){
        $image=class_exists('ImageUploadField')?'ImageUploadField':'FileIFrameField';
        $tree=class_exists('SimpleTreeDropdownField')?'SimpleTreeDropdownField':'HTMLDropdownField';
       
        $imager=new $image('PanelImage',_t('Image.SINGULARNAME')." ...");
       
        if($image=='ImageUploadField')$imager->uploadOnSubmit();   
       
          return new FieldSet(
             new TextField('Title',_t('SiteTree.METATITLE')),
             new TextField('Tagline',_t('SiteTree.METADESC')),
             $imager,
             new $tree("PanelLinkID",_t('RedirectorPage.REDIRECTTOPAGE'),"SiteTree")
          );
       }
    ....

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

    Best regards,
    Ronald

  • Aaron Brockhurst
    Avatar
    Community Member
    30 Posts

    Re: Using a DataObjectManager in widget Link to this post

    Did you find a solution to this?

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

    Aaron

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