Hi
I've made a widget for displaying some text and/or images.
It seems to work just fine, except one big problem.
It breaks the page .
I don't get any error messages, but it ruins the layout. The page can't be viewed at all in Internet Explorer, the content is all over the place. But it's viewebal in Chrome & Firefox, but the whole page is moved down about 20px..
I've compared my widget to other ones and I can't find what makes silverstripe behave so strange.
mysite/code/MyWidget.php
<?php
class MyWidget extends Widget {
static $db = array(
"Title" => "Varchar",
"Layout" => "Varchar",
"SecondTitle" => "Varchar",
"ImageCaption" => "Varchar",
"Text" => "Text",
"LinkUrl" => "Varchar",
"ExtraLinkUrl" => "Varchar"
);
static $has_one = array(
'LinkImage' => 'Image',
'ExtraLinkImage' => 'Image'
);
static $has_many = array();
static $many_many = array();
static $belongs_many_many = array();
static $defaults = array(
"Title" => "",
"Layout" => "Bluebox",
"SecondTitle" => "",
"ImageCaption" => "",
"Text" => "",
"LinkUrl" => "#",
"ExtraLinkUrl" => "#"
);
static $cmsTitle = "My Widget";
static $description = "En widget för titlar, text, bilder, samt länkar.";
function getCMSFields() {
$fields = parent::getCMSFields();
$options = array("Bluebox" => "Bluebox", "ImageLink" => "ImageLink and text", "ImageLink2" => "ImageLink and text with extra ImageLink bellow text.");
$fields->merge(
new FieldList(
new TextField("Title", "Titel"),
new DropdownField("Layout", "Layout (layouten 'bluebox' visar inga bilder)", $options),
new TextField("SecondTitle", "Extra title som visas om layout 'Bluebox' är valt."),
new WidgetImageField("LinkImageID", "Bild"),
new TextField("ImageCaption", "Fet text som visas direkt under bild"),
new TextAreaField("Text", "Text"),
new TextField("LinkUrl", "Länk"),
new WidgetImageField("ExtraLinkImageID", "Extra Bild som visas under texten."),
new TextField("ExtraLinkUrl", "Länk om bilden under texten skall länka.")
)
);
$this->extend('updateCMSFields', $fields);
return $fields;
}
function Title() {
return $this->Title;
}
}
class MyWidget_Controller extends Widget_Controller {
/**
* @var array
*/
public static $allowed_actions = array (
);
public function init() {
parent::init();
if (isset($this->LinkImageID) && is_numeric($this->LinkImageID)) {
$this->LinkImageTag = DataObject::get_by_id('Image',$this->LinkImageID);
}
if (isset($this->ExtraLinkImageID) && is_numeric($this->ExtraLinkImageID)) {
$this->ExtraLinkImageTag = DataObject::get_by_id('Image',$this->ExtraLinkImageID);
}
}
}
?>
mysite/templates/MyWidget.ss
<div class="$Layout">
<% if Layout == "Bluebox" %>
<h3>$SecondTitle</h3>
<% else %>
<a href="$LinkUrl" title="$Title">
$LinkImage
<% if ImageCaption %>
<h3 class="center">$ImageCaption</h3>
<% end_if %>
</a>
<% end_if %>
<p>$Text</p>
<% if Layout == "Bluebox" %>
<a href="$LinkUrl" title="Läs mer">Läs mer >>></a>
<% end_if %>
</div>
<% if Layout == "ImageLink2" %>
<a href="$ExtraLinkUrl" class="extra">
$ExtraLinkImage
</a>
<% end_if %>
Thanks, in advance, for any help that could help me find the "bug"
//Oscar