mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Improved support for DataObjectInterface implementors in forms
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@46307 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
f141fbe5ad
commit
395da98591
@ -1591,10 +1591,15 @@ class DataObject extends Controller implements DataObjectInterface {
|
||||
*/
|
||||
public static function get_by_id($callerClass, $id) {
|
||||
if(is_numeric($id)) {
|
||||
$tableClasses = ClassInfo::dataClassesFor($callerClass);
|
||||
$baseClass = array_shift($tableClasses);
|
||||
|
||||
return DataObject::get_one($callerClass,"`$baseClass`.`ID` = $id");
|
||||
if(singleton($callerClass) instanceof DataObject) {
|
||||
$tableClasses = ClassInfo::dataClassesFor($callerClass);
|
||||
$baseClass = array_shift($tableClasses);
|
||||
return DataObject::get_one($callerClass,"`$baseClass`.`ID` = $id");
|
||||
|
||||
// This simpler code will be used by non-DataObject classes that implement DataObjectInterface
|
||||
} else {
|
||||
return DataObject::get_one($callerClass,"`ID` = $id");
|
||||
}
|
||||
} else {
|
||||
user_error("DataObject::get_by_id passed a non-numeric ID #$id", E_USER_WARNING);
|
||||
}
|
||||
|
@ -44,4 +44,17 @@ interface DataObjectInterface {
|
||||
*/
|
||||
function delete();
|
||||
|
||||
/**
|
||||
* Get the named field.
|
||||
* This function is sometimes called explicitly by the form system, so you need to define it, even if you use the
|
||||
* default field system.
|
||||
*/
|
||||
function __get($fieldName);
|
||||
|
||||
/**
|
||||
* Save content from a form into a field on this data object.
|
||||
* Since the data comes straight from a form it can't be trusted and will need to be validated / escaped.'
|
||||
*/
|
||||
function setCastedField($fieldName, $val);
|
||||
|
||||
}
|
@ -529,7 +529,7 @@ class Form extends ViewableData {
|
||||
* Save the contents of this form into the given data object.
|
||||
* It will make use of setCastedField() to do this.
|
||||
*/
|
||||
function saveInto(DataObject $dataObject) {
|
||||
function saveInto(DataObjectInterface $dataObject) {
|
||||
$dataFields = $this->fields->dataFields();
|
||||
$lastField = null;
|
||||
|
||||
|
@ -96,7 +96,7 @@ class FormField extends ViewableData {
|
||||
* Method to save this form field into the given data object.
|
||||
* By default, makes use of $this->dataValue()
|
||||
*/
|
||||
function saveInto(DataObject $record) {
|
||||
function saveInto(DataObjectInterface $record) {
|
||||
if($this->name) {
|
||||
$record->setCastedField($this->name, $this->dataValue());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user