Giter VIP home page Giter VIP logo

Comments (8)

jasjitCheema avatar jasjitCheema commented on July 18, 2024 1

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;
		
	}
	
}

from silverstripe-widgets.

robbieaverill avatar robbieaverill commented on July 18, 2024

Would you mind sharing the code for your custom widget please?

from silverstripe-widgets.

jasjitCheema avatar jasjitCheema commented on July 18, 2024

from silverstripe-widgets.

robbieaverill avatar robbieaverill commented on July 18, 2024

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.

from silverstripe-widgets.

jasjitCheema avatar jasjitCheema commented on July 18, 2024

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

from silverstripe-widgets.

jasjitCheema avatar jasjitCheema commented on July 18, 2024

Any luck?

from silverstripe-widgets.

jasjitCheema avatar jasjitCheema commented on July 18, 2024

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()** )

from silverstripe-widgets.

dhensby avatar dhensby commented on July 18, 2024

closed as not a bug, then

from silverstripe-widgets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.