Closed jasjitCheema closed 4 years ago
Would you mind sharing the code for your custom widget please?
Yes! Sure
I don't have Skype. If possible, you could remove any sensitive code from the file and post it here or in a GitHub Gist. If not, you can reach me on the Silverstripe Community Slack channel.
Here is the come to create new Widget:-
<?php
namespace Widgets\NewsUpdates;
use SilverStripe\Widgets\Model\Widget;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\TextareaField;
use SilverStripe\Forms\NumericField;
use SilverStripe\Forms\ListboxField;
use SilverStripe\ORM\ArrayList;
use SilverStripe\View\ArrayData;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Forms\DropdownField;
use News\NewsDetailPage;
class NewsUpdates extends Widget{
private static $db = array(
'WidgetTitle' => 'Varchar',
'NewsPagesId_A' => 'Text',
'WidgetWidth' => 'Varchar',
'ViewAll' => 'Varchar'
);
private static $title = 'NewsUpdates HALF';
private static $cmsTitle = 'NewsUpdates';
private static $description = 'Description goes here';
private static $many_many = [
//'NewsPagesId' => NewsDetailPage::class,
];
public function getCMSFields(){
$news_detail = NewsDetailPage::get()->map('ID','Title')->toArray();
//print_r( $news_detail );
//print_r($this->NewsPagesId_A);exit;
//$news_detail = array("1"=>"one","2"=>"two","3"=>"three");
$f = new FieldList(
new TextField('WidgetTitle', 'Title'),
new TextField('ViewAll', 'View all link'),
ListboxField::create('NewsPagesId_A','Select newsfff',$news_detail),
DropdownField::create('WidgetWidth','Widget Width',[
'12' => 'FULL',
'6' => 'HALF',
'4' => '1/3'
])
);
return $f;
}
}
I don't have Skype. If possible, you could remove any sensitive code from the file and post it here or in a GitHub Gist. If not, you can reach me on the Silverstripe Community Slack channel.
Okay! Thanks for your response
Any luck?
Got my mistake. To fix this i have to use "many many" relationship.
private static $many_many = [
'NewsPagesId' => NewsDetailPage::class,
];
Add following cms field:-
ListboxField::create('NewsPagesId','Select news',$news_detail, **$this->NewsPagesId()** )
closed as not a bug, then
Steps to follow:-
*Checked in Database and these values are getting saved in string form eg. ["45","50"]
Please let me know, if any idea