I’d say recursion would be the way to go. Below is my proposal which seems to work for me. Of course, DataObjectManager’s constructor still does the shallow check so the popup size is not right but that’s another (slightly less serious) problem.
public function getNestedDOMs($fields = Null)
{
if (!$fields) {
$fields = $this->Fields();
}
$dom_fields = array();
foreach ($fields as $field) {
if ($field instanceof DataObjectManager) {
$field->isNested = true;
$dom_fields[] = $field;
}
if (method_exists($field, 'getChildren')) {
if ($maybeFields = $this->getNestedDOMs($field->getChildren())) {
$dom_fields[] = $maybeFields;
}
}
}
return !empty($dom_fields)? $dom_fields : false;
}