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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Widgets /

Discuss SilverStripe Widgets.

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

PageContentWidget help needed ss3


Go to End


2 Posts   2243 Views

Avatar
haantje72

Community Member, 69 Posts

5 October 2012 at 2:55am

Edited: 11/10/2012 5:21am

Has anyone allready got PageContentWidget working on ss3.2?
The widget installs ok but when you add the widget to the page youll get an error. it does not give further info!
I found the problem should be somewhere in the dropdownfield but dont know in ss3 how to solve this! Been looking in docs for ages.. but found no good descriptions how to call a sitetree for selection.

Get error 568 in framework/model/MySQLdatabase.php

<?php

class PageContentWidget extends Widget {
static $db = array(
"WidgetTitle" => "Varchar(255)",
"PageID" => "Int"
);

static $defaults = array(
"WidgetTitle" => 'Page Content',
"PageID" => 0
);

static $title = "";
static $cmsTitle = "Pagina inhoud tonen in de zijbalk";
static $description = "Laat een pagina in de zijbalk zien van max 140px breed.";

function getCMSFields() {
$obj = 'SiteTree';
$filter = "Status = 'Published'";
//adding Sort != 0 will typically remove Blog Posts and Forum Topics (can be buggy)
//$filter = "Status = 'Published AND Sort != 0'";
$sort = 'Title ASC';
$join = '';
$limit = '';
$records = DataObject::get($obj, $filter, $sort, $join, $limit);

$dropDownArray = array();
if($records->exists()) foreach( $records as $record ) {
$dropDownArray[$record->ID] = $record->Title;
}

return new FieldSet(
new TextField("WidgetTitle", "Type de titel welke bovenaan in de kop moet komen"),
new TreeDropdownField(
$name = "PageID",
$title = "Kies de pagina welke je in de zijbalk wilt tonen:",
$source = $dropDownArray
)
);
}

function output() {

$obj = 'SiteTree';
$id = $this->PageID;
$record = DataObject::get_by_id($obj,$id);
return $record->Content;
}
}

How can i solve this problem so the widget works?

Avatar
haantje72

Community Member, 69 Posts

17 October 2012 at 7:31am

Edited: 17/10/2012 7:33am

dont know if im on the right way... but got anothe error but now from the widgets module

function getCMSFields() {
$obj = 'SiteTree';
$filter = "Status = 'Published'";
$sort = 'Title ASC';
$join = '';
$limit = '';
$records = DataObject::get($obj, $filter, $sort, $join, $limit);
}

public function AllPages() {
$gridField = new GridField('pages', 'All pages', SiteTree::get(), GridFieldConfig_RecordViewer::create());
return new Form($this, "AllPages", new FieldList($gridField), new FieldList());
}

function output() {
$obj = 'SiteTree';
$id = $this->PageID;
$record = DataObject::get_by_id($obj,$id);

return $record->Content;
}
------------------------------------------------------
Hope this way with gridfield the page selected in the fieldlistdropdown? would be saved?
------------------------------------------------------

the only thing now is i get from the module widgets an error:
Warning at line 163 widgets/code/model/Widget.php
wich is:

public function CMSEditor() {
$fields = $this->getCMSFields();
$outputFields = new FieldList();
foreach($fields as $field) {
$name = $field->getName();
$value = $this->getField($name);
if ($value) {
$field->setValue($value);
}
$name = preg_replace("/([A-Za-z0-9\-_]+)/", "Widget[" . $this->ID . "][\\1]", $name);
$field->setName($name);
$outputFields->push($field);
}
return $outputFields;
}

------------------------------------------------------------

Does anyone know how to solve this?