Jump to:

794 Posts in 409 Topics by 304 members

Widgets

SilverStripe Forums » Widgets » PageContentWidget help needed ss3

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 842 Views
  • haantje72
    Avatar
    Community Member
    69 Posts

    PageContentWidget help needed ss3 Link to this post

    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?

  • haantje72
    Avatar
    Community Member
    69 Posts

    Re: PageContentWidget help needed ss3 Link to this post

    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?

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