#2200 - Allowed subclasses in ComponentSet::add/remove

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@49708 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-02-18 05:19:22 +00:00
parent 1273671cdf
commit 5b1436eaa4

View File

@ -89,9 +89,8 @@ class ComponentSet extends DataObjectSet {
}
if(is_object($item)) {
// TODO Should this allow subclasses?
if($item->class != $this->childClass) {
user_error("ComponentSet::add() Tried to add an '{$item->class}' object, but '{$this->childClass}' expected", E_USER_ERROR);
if(!is_a($item, $this->childClass)) {
user_error("ComponentSet::add() Tried to add an '{$item->class}' object, but a '{$this->childClass}' object expected", E_USER_ERROR);
}
} else {
$id = $item;
@ -196,8 +195,8 @@ class ComponentSet extends DataObjectSet {
*/
function remove($item) {
if(is_object($item)) {
if($item->class != $this->childClass && !is_subclass_of($item, $this->childClass)) {
user_error("ComponentSet::remove() Tried to remove an '{$item->class}' object, but '{$this->childClass}' expected", E_USER_ERROR);
if(!is_a($item, $this->childClass)) {
user_error("ComponentSet::remove() Tried to remove an '{$item->class}' object, but a '{$this->childClass}' object expected", E_USER_ERROR);
}
} else {
$item = DataObject::get_by_id($this->childClass, $item);