mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Moved widgets into core
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@39562 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
5308e76142
commit
f545953c18
3
templates/WidgetArea.ss
Normal file
3
templates/WidgetArea.ss
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<% control Widgets %>
|
||||||
|
$WidgetHolder
|
||||||
|
<% end_control %>
|
2
templates/WidgetHolder.ss
Normal file
2
templates/WidgetHolder.ss
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<h3>$Title</h3>
|
||||||
|
$Content
|
89
widgets/Widget.php
Normal file
89
widgets/Widget.php
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Widget extends DataObject {
|
||||||
|
static $db = array(
|
||||||
|
"ParentID" => "Int",
|
||||||
|
"Sort" => "Int"
|
||||||
|
);
|
||||||
|
|
||||||
|
static $default_sort = "Sort";
|
||||||
|
|
||||||
|
static $title = "Widget Title";
|
||||||
|
static $cmsTitle = "Name of this widget";
|
||||||
|
static $description = "Description of what this widget does.";
|
||||||
|
|
||||||
|
function getCMSFields() {
|
||||||
|
return new FieldSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
function WidgetHolder() {
|
||||||
|
return $this->renderWith("WidgetHolder");
|
||||||
|
}
|
||||||
|
|
||||||
|
function Content() {
|
||||||
|
return $this->renderWith($this->class);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Title() {
|
||||||
|
$instance = singleton($this->class);
|
||||||
|
return $instance->uninherited('title', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function CMSTitle() {
|
||||||
|
$instance = singleton($this->class);
|
||||||
|
return $instance->uninherited('cmsTitle', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Description() {
|
||||||
|
$instance = singleton($this->class);
|
||||||
|
return $instance->uninherited('description', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DescriptionSegment() {
|
||||||
|
return $this->renderWith('WidgetDescription');
|
||||||
|
}
|
||||||
|
|
||||||
|
function EditableSegment() {
|
||||||
|
return $this->renderWith('WidgetEditor');
|
||||||
|
}
|
||||||
|
|
||||||
|
function CMSEditor() {
|
||||||
|
$output = '';
|
||||||
|
|
||||||
|
$fields = $this->getCMSFields();
|
||||||
|
foreach($fields as $field) {
|
||||||
|
$name = $field->Name();
|
||||||
|
$field->setValue($this->getField($name));
|
||||||
|
$renderedField = $field->FieldHolder();
|
||||||
|
$renderedField = ereg_replace("name=\"([A-Za-z0-9\-_]+)\"", "name=\"Widget[" . $this->ID . "][\\1]\"", $renderedField);
|
||||||
|
$renderedField = ereg_replace("id=\"([A-Za-z0-9\-_]+)\"", "id=\"Widget[" . $this->ID . "][\\1]\"", $renderedField);
|
||||||
|
$output .= $renderedField;
|
||||||
|
}
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ClassName() {
|
||||||
|
return $this->class;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Name() {
|
||||||
|
return "Widget[".$this->ID."]";
|
||||||
|
}
|
||||||
|
|
||||||
|
function populateFromPostData($data) {
|
||||||
|
foreach($data as $name => $value) {
|
||||||
|
if($name != "Type") {
|
||||||
|
$this->setField($name, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->write();
|
||||||
|
|
||||||
|
// The field must be written to ensure a unique ID.
|
||||||
|
$this->Name = $this->class.$this->ID;
|
||||||
|
$this->write();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
15
widgets/WidgetArea.php
Normal file
15
widgets/WidgetArea.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class WidgetArea extends DataObject {
|
||||||
|
static $db = array();
|
||||||
|
|
||||||
|
static $has_many = array(
|
||||||
|
"Widgets" => "Widget"
|
||||||
|
);
|
||||||
|
|
||||||
|
function forTemplate() {
|
||||||
|
return $this->renderWith("WidgetArea");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in New Issue
Block a user