Skip to content

Commit

Permalink
#2200 - Allowed subclasses in ComponentSet::add/remove
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@49708 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
Sam Minnee committed Feb 18, 2008
1 parent 1273671 commit 5b1436e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions core/model/ComponentSet.php
Expand Up @@ -89,9 +89,8 @@ function add($item, $extraFields = null) {
}

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;
Expand Down Expand Up @@ -196,8 +195,8 @@ function setByIDList($idList) {
*/
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);
Expand Down

0 comments on commit 5b1436e

Please sign in to comment.