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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

SS3: upload image to Widget


Reply


2 Posts   733 Views

Avatar
Fraser

Community Member, 47 Posts

17 September 2012 at 3:38pm

I'm creating a few widgets for a project I'm working on and it seems widgets do not have access to any of the other classes from outside the widget. I've tried adding a has_one static for both image and SiteTree classes (see example below for image example) and I am getting the same error when I try and add the cms field: Fatal error: Call to a member function FormAction() on a non-object in /..../sapphire/forms/FormField.php on line 139

<?php
class AdBoxWidget extends Widget{
   static $title = "";
   static $cmsTitle = "Ad Box Widget";
   static $description = "Ad Box widget. To add an image, Title and Link";

   static $db = array(
      "Title" => "Text",
      "Link" => "Text",
      "AdLinkText" => "Text"
   );
   
   static $defaults = array(
      "Title" => 'Ad Title',
      "Link" => 'http://',      
      "AdLinkText" => 'Click here for more info',
   );
   
   static $has_one = array(
      'AdImage' => 'Image'
   );

   function getCMSFields(){
      return new FieldList(
         new TextField("Title", "Ad Title"),
         new TextField("Link", "Ad Link"),
         new TextField("AdLinkText", "Text for Link"),
         new UploadField("AdImage", "Ad image")
      );
   }
   
   function getAd(){
      $output = new ArrayList();
      $output->push(
         new ArrayData(
            array(
               "Title" => $this->Title,
               "Link" => $this->Link,
               "AdLinkText" => $this->AdLinkText
            )
         )
      );
      return $output;
   }
   
   
}

Avatar
swaiba

Forum Moderator, 1808 Posts

18 September 2012 at 11:46pm

I've no idea (helpful eh?) about SS3, but since widgets barely have made it as working and seem to be in teh same structure I can image it isn't better than the situation 2 years ago when I made this to work arroun the issue...

http://www.silverstripe.org/imagelinkwidget-widget/

The other solution is to use BBcode parser on the widget.

However both workaround that require uploading the image first in file & images... would be very intrested to here these workarounds are not required in SS3 widgets...