I'm trying to limit the number of Widgets which get displayed in a WidgetArea.
This always needs to be 6 widgets.
I can edit WidgetArea in core to have a maximum of 6 in the getComponents method but i prefer to decorate WidgetArea.
I did the following:
MyWidgetAreaDecorator.php
class MyWidgetAreaDecorator extends DataObjectDecorator {
function extraStatics() {
return array("db" => array('Dummy' => 'Varchar(8)'));
}
function WidgetControllers() {
$controllers = new DataObjectSet();
foreach($this->ItemsToRender() as $widget) {
// find controller
$controllerClass = '';
foreach(array_reverse(ClassInfo::ancestry($widget->class)) as $widgetClass) {
$controllerClass = "{$widgetClass}_Controller";
if(class_exists($controllerClass)) break;
}
$controller = new $controllerClass($widget);
$controller->init();
$controllers->push($controller);
}
return $controllers;
}
function ItemsToRender() {
return $this->getComponents('Widgets', "\"Widget\".\"Enabled\" = 1", "", "", 6);
}
}
in _config.php:
Object::add_extension('WidgetArea', 'MyWidgetAreaDecorator');
Upon dev/build the Dummy varchar gets added, so the decorator is active. Why doest my limit not work? Any clues?
Best regards,
Bart