Reputation: 1199
I'd like to create a loopable list of dataobjects with different classes.
Something like that, but functioning
DataObject::get()->filter('ClassName, ['MyClass', 'MyOtherClass']);
Is there a way to achieve that without subclassing?
Upvotes: 1
Views: 57
Reputation: 476
csy_dot_io you can create an ArrayList
with both object lists:
public function getCombinedList()
{
$list = ArrayList::create();
$pushToList = function($object) use (&$list)
{
$list->push($object);
};
MyClass::get()->each($pushToList);
MyOtherClass::get()->each($pushToList);
return $list;
}
If you're looking to manage multiple objects in one GridField then you could check out gridfieldextensions, specifically the GridFieldAddNewMultiClass
component.
Upvotes: 2