mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCEMENT Added DataObjectDecorator->setOwner()
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@73882 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
6c70b10173
commit
697703aff8
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user