mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
r52080, r52101, r52102 (merged from branches/roa)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@59897 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
8c05c9985a
commit
faeea52740
@ -1125,6 +1125,80 @@ class DataObject extends ViewableData implements DataObjectInterface {
|
|||||||
return isset($items) ? $items : null;
|
return isset($items) ? $items : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a SearchContext to be used for building and processing
|
||||||
|
* a generic search form for properties on this object.
|
||||||
|
*
|
||||||
|
* @usedby {@link ModelAdmin}
|
||||||
|
* @return SearchContext
|
||||||
|
*/
|
||||||
|
public function getDefaultSearchContext() {
|
||||||
|
$c = new SearchContext($this->class);
|
||||||
|
|
||||||
|
return $c;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine which properties on the DataObject are
|
||||||
|
* searchable, and map them to their default {@link FormField}
|
||||||
|
* representations. Useful for scaffolding a searchform for {@link ModelAdmin}.
|
||||||
|
*
|
||||||
|
* @usedby {@link SearchContext}
|
||||||
|
* @return FieldSet
|
||||||
|
*/
|
||||||
|
public function scaffoldSearchFields() {
|
||||||
|
$fields = new FieldSet();
|
||||||
|
foreach($this->databaseFields() as $fieldName => $fieldType) {
|
||||||
|
// @todo Pass localized title
|
||||||
|
$fields->push($this->dbObject($fieldName)->scaffoldSearchField());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scaffold a simple edit form for all properties on this dataobject,
|
||||||
|
* based on default {@link FormField} mapping in {@link DBField::scaffoldFormField()}
|
||||||
|
*
|
||||||
|
* @uses {@link DBField::scaffoldFormField()}
|
||||||
|
* @return FieldSet
|
||||||
|
*/
|
||||||
|
public function scaffoldFormFields() {
|
||||||
|
$fields = new FieldSet();
|
||||||
|
foreach($this->databaseFields() as $fieldName => $fieldType) {
|
||||||
|
// @todo Pass localized title
|
||||||
|
$fields->push($this->dbObject($fieldName)->scaffoldFormField());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Centerpiece of every data administration interface in Silverstripe,
|
||||||
|
* which returns a {@link FieldSet} suitable for a {@link Form} object.
|
||||||
|
* If not overloaded, we're using {@link scaffoldFormFields()} to automatically
|
||||||
|
* generate this set.
|
||||||
|
*
|
||||||
|
* <example>
|
||||||
|
* class MyCustomClass extends DataObject {
|
||||||
|
* static $db = array('CustomProperty'=>'Boolean');
|
||||||
|
*
|
||||||
|
* public function getCMSFields() {
|
||||||
|
* $fields = parent::getCMSFields();
|
||||||
|
* $fields->push(new CheckboxField('CustomProperty'));
|
||||||
|
* return $fields;
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* </example>
|
||||||
|
*
|
||||||
|
* @see Good example of complex FormField building: {@link SiteTree::getCMSFields()}
|
||||||
|
*
|
||||||
|
* @return FieldSet
|
||||||
|
*/
|
||||||
|
public function getCMSFields() {
|
||||||
|
return $this->scaffoldFormFields();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the given fields have been filled out.
|
* Checks if the given fields have been filled out.
|
||||||
* Pass this method a number of field names, it will return true if they all have values.
|
* Pass this method a number of field names, it will return true if they all have values.
|
||||||
|
@ -35,6 +35,10 @@ class Boolean extends DBField {
|
|||||||
user_error("DBField::saveInto() Called on a nameless '$this->class' object", E_USER_ERROR);
|
user_error("DBField::saveInto() Called on a nameless '$this->class' object", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scaffoldFormField($title = null) {
|
||||||
|
return new CheckboxField($this->name, $title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@ -3,6 +3,7 @@
|
|||||||
* Single field in the database.
|
* Single field in the database.
|
||||||
* Every field from the database is represented as a sub-class of DBField. In addition to supporting
|
* Every field from the database is represented as a sub-class of DBField. In addition to supporting
|
||||||
* the creation of the field in the database,
|
* the creation of the field in the database,
|
||||||
|
*
|
||||||
* @package sapphire
|
* @package sapphire
|
||||||
* @subpackage model
|
* @subpackage model
|
||||||
*/
|
*/
|
||||||
@ -102,6 +103,38 @@ abstract class DBField extends ViewableData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a FormField instance used as a default
|
||||||
|
* for form scaffolding.
|
||||||
|
*
|
||||||
|
* @usedby {@link SearchContext}
|
||||||
|
* @usedby {@link ModelAdmin}
|
||||||
|
* @usedby {@link DataObject::scaffoldFormFields()}
|
||||||
|
*
|
||||||
|
* @param string $title Optional. Localized title of the generated instance
|
||||||
|
* @return FormField
|
||||||
|
*/
|
||||||
|
public function scaffoldFormField($title = null) {
|
||||||
|
$field = new TextField($this->name, $title);
|
||||||
|
|
||||||
|
return $field;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a FormField instance used as a default
|
||||||
|
* for searchform scaffolding.
|
||||||
|
*
|
||||||
|
* @usedby {@link SearchContext}
|
||||||
|
* @usedby {@link ModelAdmin}
|
||||||
|
* @usedby {@link DataObject::scaffoldFormFields()}
|
||||||
|
*
|
||||||
|
* @param string $title Optional. Localized title of the generated instance
|
||||||
|
* @return FormField
|
||||||
|
*/
|
||||||
|
public function scaffoldSearchField($title = null) {
|
||||||
|
return $this->scaffoldFormField($title);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the field to the underlying database.
|
* Add the field to the underlying database.
|
||||||
*/
|
*/
|
||||||
|
@ -235,6 +235,10 @@ class Date extends DBField {
|
|||||||
return date("Y-m-d", mktime(0,0,0,$fmonth,$fday,$fyear-1));
|
return date("Y-m-d", mktime(0,0,0,$fmonth,$fday,$fyear-1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scaffoldFormField($title = null) {
|
||||||
|
return new DateField($this->name, $title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@ -39,6 +39,10 @@ if(!class_exists('Datetime')) {
|
|||||||
function requireField() {
|
function requireField() {
|
||||||
DB::requireField($this->tableName, $this->name, "datetime");
|
DB::requireField($this->tableName, $this->name, "datetime");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scaffoldFormField($title = null) {
|
||||||
|
return new PopupDateTimeField($this->name, $title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -36,6 +36,10 @@ class Decimal extends DBField {
|
|||||||
user_error("DBField::saveInto() Called on a nameless '" . get_class($this) . "' object", E_USER_ERROR);
|
user_error("DBField::saveInto() Called on a nameless '" . get_class($this) . "' object", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scaffoldFormField($title = null) {
|
||||||
|
return new NumericField($this->name, $title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@ -13,5 +13,9 @@ class Float extends DBField {
|
|||||||
function Nice() {
|
function Nice() {
|
||||||
return number_format($this->value, 2);
|
return number_format($this->value, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scaffoldFormField($title = null) {
|
||||||
|
return new NumericField($this->name, $title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
@ -65,6 +65,14 @@ class HTMLText extends Text {
|
|||||||
return $summary;
|
return $summary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scaffoldFormField($title = null) {
|
||||||
|
return new HTMLEditorField($this->name, $title);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scaffoldSearchField($title = null) {
|
||||||
|
return new TextField($this->name, $title);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@ -8,6 +8,13 @@
|
|||||||
*/
|
*/
|
||||||
class HTMLVarchar extends Varchar {
|
class HTMLVarchar extends Varchar {
|
||||||
|
|
||||||
|
public function scaffoldFormField($title = null) {
|
||||||
|
return new HTMLOneLineField($this->name, $title);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scaffoldSearchField($title = null) {
|
||||||
|
return new TextField($this->name, $title);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,9 @@ class Int extends DBField {
|
|||||||
return sprintf( '%d', $this->value );
|
return sprintf( '%d', $this->value );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scaffoldFormField($title = null) {
|
||||||
|
return new NumericField($this->name, $title);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,9 +34,8 @@ class SSDatetime extends Date {
|
|||||||
return date('Y-m-d%20H:i:s', strtotime($this->value));
|
return date('Y-m-d%20H:i:s', strtotime($this->value));
|
||||||
}
|
}
|
||||||
|
|
||||||
function __construct( $name ) {
|
public function scaffoldFormField($title = null) {
|
||||||
// Debug::show( 'Created SSDatetime: ' . $name );
|
return new PopupDateTimeField($this->name, $title);
|
||||||
parent::__construct( $name );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,5 +38,9 @@ class Time extends DBField {
|
|||||||
function requireField() {
|
function requireField() {
|
||||||
DB::requireField($this->tableName, $this->name, "time");
|
DB::requireField($this->tableName, $this->name, "time");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scaffoldFormField($title = null) {
|
||||||
|
return new TimeField($this->name, $title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
@ -34,5 +34,7 @@ class TextField extends FormField {
|
|||||||
if(!$this->value) $this->value = $this->Title();
|
if(!$this->value) $this->value = $this->Title();
|
||||||
return $this->Field();
|
return $this->Field();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
@ -1,6 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Standard basic search form
|
* Standard basic search form which conducts a fulltext search on all {@link SiteTree}
|
||||||
|
* objects.
|
||||||
|
*
|
||||||
|
* @see Use {@link ModelController} and {@link SearchContext} for a more generic search implementation based around {@link DataObject}
|
||||||
* @package sapphire
|
* @package sapphire
|
||||||
* @subpackage search
|
* @subpackage search
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user