644 Posts in 175 Topics by 245 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 376 Views |
-
Changing the Available Widgets field in the CMS

5 August 2011 at 6:37am
Hello,
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!
-
Re: Changing the Available Widgets field in the CMS

19 September 2011 at 8:56pm
Hi primer,
Welcome!
The method I use for this is...
class MyWidgetAreaEditor extends WidgetAreaEditor {
function AvailableWidgets() {
$arrAllowedWidgets = array('WidgetOne','WidgetTwo');$dosWidgets= new DataObjectSet();
foreach ($arrAllowedWidgets as $class) {
$dosWidgets->push(singleton($class));
}
return $dosWidgets;
}
}then use that in your Page.php instead of the regular one...
$fields->addFieldToTab("Root.Content.Widgets", new MyWidgetAreaEditor("SideBar"));
| 376 Views | ||
|
Page:
1
|
Go to Top |


