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.

Widgets /

Discuss SilverStripe Widgets.

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

Changing the Available Widgets field in the CMS

Go to End

2 Posts   1185 Views


Community Member, 3 Posts

5 August 2011 at 6:37am


I'm attempting to alter which widgets are displayed in the Available Widgets section of the CMS. I've set up two fields in the CMS, with a has_one relation for each WidgetAreaEditor.

public function getCMSFields() {
$f = parent::getCMSFields();
$f->addFieldToTab('Root.Content.WidgetsFacebook', new WidgetAreaEditor('Facebook'));
$f->addFieldToTab('Root.Content.WidgetsTwitter', new WidgetAreaEditor('Twitter'));
return $f;

In the CMS however, both widgets are available under the Available Widgets section on both tabs. I know that I'll need to extend or overwrite the AvailableWidgets method, but I'm not quite sure how. I can see that the method currently loops through everything as an array and then spits them out to the CMS, and I'd like to be able to assign a widget to a Widget field tab.

Any suggestions greatly appreciated, thanks!


Forum Moderator, 1890 Posts

19 September 2011 at 8:56pm

Hi primer,


The method I use for this is...

class MyWidgetAreaEditor extends WidgetAreaEditor {

	function AvailableWidgets() {
		$arrAllowedWidgets = array('WidgetOne','WidgetTwo');

		$dosWidgets= new DataObjectSet();
		foreach ($arrAllowedWidgets as $class) {
		return $dosWidgets;

then use that in your Page.php instead of the regular one...

$fields->addFieldToTab("Root.Content.Widgets", new MyWidgetAreaEditor("SideBar"));