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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Widgets /

Discuss SilverStripe Widgets.

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

Slideshow widget

Go to End

10 Posts   6450 Views


Community Member, 1 Post

27 August 2009 at 7:44am

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!


Community Member, 54 Posts

28 December 2009 at 2:28am

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


Community Member, 63 Posts

2 February 2010 at 4:31pm

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


Community Member, 63 Posts

10 February 2010 at 12:47pm

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.


Community Member, 6 Posts

8 July 2010 at 2:34am

Over 1000 views and no follow up yet!

Is anyone still actively pursuing this?


Community Member, 78 Posts

8 July 2010 at 9:50pm

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.


Community Member, 4 Posts

10 August 2010 at 9:02pm

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;

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


Forum Moderator, 1899 Posts

13 August 2010 at 7:18am

Edited: 24/08/2010 3:08am

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

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

the implementation...

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(
					'selected' => $selected,
					'value' => $value

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

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

		return $html;

Go to Top