Jump to:

796 Posts in 409 Topics by 304 members

Widgets

SilverStripe Forums » Widgets » Slideshow widget

Discuss SilverStripe Widgets.

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

Page: 1 2
Go to End
Author Topic: 4590 Views
  • henriquecruz
    Avatar
    Community Member
    1 Post

    Slideshow widget Link to this post

    Hi all!

    I'm developing a slideshow widget to provide a swf file with an xml created thru the cms (acronyms make our lives so much easier) but I wanted to be able to upload images thru the cms configuration panel for the widget and can't seem to find a solution.

    When I have the following:

    (...)
       function getCMSFields(){
       
          return new FieldSet(
             new FileField("Image1", "Slideshow Image 1"),
    (...)

    ...I can select a file but it won't upload when I save/publish the page.

    If I use:

    (...)
       function getCMSFields(){
       
          return new FieldSet(
             new ImageField("Image1", "Slideshow Image 1"),
    (...)

    ... it gives me an error right when I try to open any page for editing:
    "Fatal error: Call to a member function getRecord() on a non-object in /home/userDir/public_html/sapphire/forms/ImageField.php on line 14"

    Any chance I can select an image for my widget to display in the front end?

    Thank you so much!

  • dospuntocero
    Avatar
    Community Member
    54 Posts

    Re: Slideshow widget Link to this post

    i have the exactly same problem... i was wondering if anyone knows a fix for this one!!

  • teejay
    Avatar
    Community Member
    63 Posts

    Re: Slideshow widget Link to this post

    I have the same issue in 2.3.5. Can someone from the admins or core developer check this issue. I have found a 2 year old thread with the same issue. I mean this must be known, and eventually there is a fix somewhere which I really need.

    Thx in advance

  • teejay
    Avatar
    Community Member
    63 Posts

    Re: Slideshow widget Link to this post

    It is really unsatisfying to get no answers at all, I mean it would be nice to hear something like, " These fields are not supported in widgets. ". Me for my part try to post more, and hope that helps someone.

  • illektr1k
    Avatar
    Community Member
    6 Posts

    Re: Slideshow widget Link to this post

    Over 1000 views and no follow up yet!

    Is anyone still actively pursuing this?

  • Mad_Clog
    Avatar
    Community Member
    78 Posts

    Re: Slideshow widget Link to this post

    I'm also in need of this...
    At this point I'd even do with a work-around until this gets fixed.

    Any help would be much appreciated.

  • puredevotion
    Avatar
    Community Member
    4 Posts

    Re: Slideshow widget Link to this post

    I've never developped a widget (or anything for SS for that matter), however I do know PHP (personally, great guy ;) )

    The code you provide is by far not enough to help you.
    apparently getRecord() is getting called on a non-object. in other words, you have this class (which for example we call SlideShow() )
    this class has a function getRecord (thus SlideShow.getRecord())

    What you are trying to do is call getRecord on a static (thus not an instance of the class SlideShow) variable. Thus something like:

    $x =1;
    $x.getRecord();

    That doesn't work. Now, the issue is, that is a severly oversimplified example and your problem is probably more complex.
    Eitherwise supply a bunch more code (the flow from getCMSFields to getRecord would give us some idea of what is going on), or (or actually 'and') check what is being suplied to, and getRecords and what is calling it.

    Hope this helps a bit.

    ps. i guess the huge number of views just means everybody is waiting for some kind of slideshow widget

  • swaiba
    Avatar
    Forum Moderator
    1796 Posts

    Re: Slideshow widget Link to this post

    I have created some code to add images to my widgets and also I have the example widget right here... I went for an easy / good / fast solution for this, I hope this helps others too.

    It assumes a 'widgets' folder in the uploads and the image you want is in there and it uses the simple image field type stuff mixed with dropdown field stuff to show the currently selected one and you need to save it to change the current - but then you get the preview of the new image... no uploading... all of that is done in the files&images...

    enjoy...
    (and feedback welcome as I might make a widget /mod out of it)

    the implementation...

    <?php
    class WidgetImageField extends FormField
    {
       function Field()
       {
          $html = "<div class=\"mysimpleimage\">";

          if($this->value != 0)
          {
             $doImage = DataObject::get_by_id('Image',$this->value);

             $html .= '<div class="thumbnail">';
             if($doImage->hasMethod('Thumbnail') && $doImage->Thumbnail())
             {
              $html .= "<img src=\"".$doImage->Thumbnail()->getURL()."\" />";
             }
             else if($doImage->CMSThumbnail())
             {
                $html .= "<img src=\"".$doImage->CMSThumbnail()->getURL()."\" />";
             }
             $html .= '</div>';
          }

          $source = array();

          $doWidgetFolder = DataObject::get_one("File","ClassName = 'Folder' AND Name = 'widgets'");
          if ($doWidgetFolder)
          {
             $dosImages = DataObject::get("Image","ParentID = ".$doWidgetFolder->ID);
             if ($dosImages)
             {
                $source = $dosImages->toDropdownMap('ID','Name');
             }
          }

          $options = array();

          foreach($source as $value => $title)
          {
             // Blank value of field and source (e.g. "" => "(Any)")
             if($value === '' && ($this->value === '' || $this->value === null)) {
                $selected = 'selected';
             } else {
                // Normal value from the source
                if($value) {
                   $selected = ($value == $this->value) ? 'selected' : null;
                } else {
                   // Do a type check comparison, we might have an array key of 0
                   $selected = ($value === $this->value) ? 'selected' : null;
                }

                $this->isSelected = ($selected) ? true : false;
             }

             $options .= $this->createTag(
                'option',
                array(
                   'selected' => $selected,
                   'value' => $value
                ),
                Convert::raw2xml($title)
             );
          }

          $attributes = array(
             'id' => $this->id(),
             'name' => $this->name,
             'tabindex' => $this->getTabIndex()
          );

          $html .= $this->createTag('select', $attributes, $options);
          $html .= "</div>";

          return $html;
       }
    }

    4590 Views
Page: 1 2
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.