Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Nested DOM popup not popping up

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2 3
Go to End
Author Topic: 3035 Views
  • sphire
    Avatar
    Community Member
    6 Posts

    Re: Nested DOM popup not popping up Link to this post

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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Nested DOM popup not popping up Link to this post

    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.

  • sphire
    Avatar
    Community Member
    6 Posts

    Re: Nested DOM popup not popping up Link to this post

    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.

    3035 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.