diff --git a/core/model/DataObject.php b/core/model/DataObject.php index 0b43a66b7..4ad36d799 100644 --- a/core/model/DataObject.php +++ b/core/model/DataObject.php @@ -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); } diff --git a/core/model/DataObjectInterface.php b/core/model/DataObjectInterface.php index 8b8b4f178..de9a7c172 100755 --- a/core/model/DataObjectInterface.php +++ b/core/model/DataObjectInterface.php @@ -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); + } \ No newline at end of file diff --git a/forms/Form.php b/forms/Form.php index 624353cda..5d006d9e3 100644 --- a/forms/Form.php +++ b/forms/Form.php @@ -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; diff --git a/forms/FormField.php b/forms/FormField.php index a843c9075..c8ad27f8b 100644 --- a/forms/FormField.php +++ b/forms/FormField.php @@ -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()); }