From 697703aff8060b68e8a03f26760e7de05c442c8f Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 31 Mar 2009 19:31:21 +0000 Subject: [PATCH] ENHANCEMENT Added DataObjectDecorator->setOwner() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@73882 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/DataObjectDecorator.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/core/model/DataObjectDecorator.php b/core/model/DataObjectDecorator.php index 31e9f8273..ee24347a9 100755 --- a/core/model/DataObjectDecorator.php +++ b/core/model/DataObjectDecorator.php @@ -27,16 +27,35 @@ abstract class DataObjectDecorator extends Extension { 'searchable_fields', ); + /** + * Set the owner of this decorator. + * @param DataObject $owner + */ + function setOwner(Object $owner) { + if(!($owner instanceof DataObject)) { + user_error(sprintf( + "DataObjectDecorator->setOwner(): Trying to decorate an object of class '%s' with '%s', + only Dataobject subclasses are supported.", + get_class($owner), $this->class), + E_USER_ERROR + ); + return false; + } + + parent::setOwner($owner); + } + /** * Load the extra database fields defined in extraStatics. */ function loadExtraStatics() { // Don't apply DB fields if the parent object has this extension too if(Object::has_extension($this->owner->parentClass(), $this->class)) return; - + if($fields = $this->extraStatics()) { foreach($fields as $relation => $fields) { if(in_array($relation, self::$decoratable_statics)) { + // Can't use add_static_var() here as it would merge the array rather than replacing Object::set_static ( $this->owner->class, $relation,