silverstripe-framework/widgets/WidgetArea.php
Ingo Schommer 1d3feb9386 MINOR added stubs to allow widgets to use treedropdown fields (from r91850)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@92456 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-11-21 01:42:44 +00:00

67 lines
1.4 KiB
PHP

<?php
/**
* Represents a set of widgets shown on a page.
* @package sapphire
* @subpackage widgets
*/
class WidgetArea extends DataObject {
static $db = array();
static $has_one = array();
static $has_many = array(
"Widgets" => "Widget"
);
static $many_many = array();
static $belongs_many_many = array();
/**
* Used in template instead of {@link Widgets()}
* to wrap each widget in its controller, making
* it easier to access and process form logic
* and actions stored in {@link Widget_Controller}.
*
* @return DataObjectSet Collection of {@link Widget_Controller}
*/
function WidgetControllers() {
$controllers = new DataObjectSet();
// var_dump($this->Items());
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 Items() {
return $this->Widgets();
}
function ItemsToRender() {
return $this->Items();
}
function forTemplate() {
return $this->renderWith($this->class);
}
function onBeforeDelete() {
parent::onBeforeDelete();
foreach($this->Widgets() as $widget) {
$widget->delete();
}
}
}
?>