Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

Nested DOM popup not popping up


Go to End


19 Posts   5275 Views

Avatar
sphire

Community Member, 6 Posts

5 November 2009 at 7:54am

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;
}

Avatar
UncleCheese

Forum Moderator, 4102 Posts

5 November 2009 at 8:37am

Yeah, but if there are nested tabsets, you have to recurse down. I think I'll just leave out the possibility of nested tabsets in a dom popup, though.

I like your approach.. the only thing I'd change is I'd probably evaluate "instanceof CompositeField" rather than test the getChildren() method.

Avatar
sphire

Community Member, 6 Posts

5 November 2009 at 9:37am

As far as I can tell, this will recurse down as much as neccessary through any TabSets or other descendants of CompositeField. Am I missing something?

Whether to use instanceof or method_exists() boils down to personal taste IMO. Speaking for myself, I rather like the duck typing approach but the two options should be largely equivalent.

Go to Top