Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Using setCustomSourceItems with the DOM

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 813 Views
  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Using setCustomSourceItems with the DOM Link to this post

    Hi Uncle Cheese!

    Today I ended up in the situation where I would like to provide the relevant data objects to the DOM myself instead of letting DOM handle the get itself through the relationship. Normally I'd do the filtering in the where clause but in this case I have to do several queries to figure out which data objects to use.

    I went digging in the classes and found setCustomSourceItems() in TableListField and it seemed to be exactly what I needed. However using this function had no effect whatsoever on the data objects that showed up in the DOM list.

    My question is if there's any way to handle this kind of scenario in the DOM?
    Is there some other method I've missed or something perhaps?

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Using setCustomSourceItems with the DOM Link to this post

    On a whim I actually tried this with HasManyComplexTableField and the functionality seems to work there.
    Is this something you removed or maybe didn't transfer over to the DOM?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Using setCustomSourceItems with the DOM Link to this post

    customSourceItems will be available in the next release of DOM. Over the next few months you'll be hearing a lot about the next version, and one of the focus points is to start from the ground up and include some of those fundamental features so that DOM is not just for managing relationships, but also for showing arbitrary data sets.

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Using setCustomSourceItems with the DOM Link to this post

    Thanks for the info, I'm really looking forward to DOM 2.0!

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Using setCustomSourceItems with the DOM Link to this post

    For anyone else that needs this feature I managed to roll this in by doing the following:

    class FKGHasManyDataObjectManager extends HasManyDataObjectManager {
       function sourceItems() {
          if(isset($this->customSourceItems)) {
             if($this->showPagination && $this->pageSize) {
                (isset($_REQUEST[ 'ctf' ][ $this->Name() ][ 'start' ]) && is_numeric($_REQUEST[ 'ctf' ][ $this->Name() ][ 'start' ])) ? $start = $_REQUEST[ 'ctf' ][ $this->Name() ][ 'start' ] : $start = 0;
                $items = $this->customSourceItems->getRange($start, $this->pageSize);
             } else {
                $items = $this->customSourceItems;
             }
             $this->unpagedSourceItems = $this->customSourceItems;
             return $items;
          }
          else {
             return parent::sourceItems();
          }      
       }
    }

    This will allow you to provide a DataObjectSet of the type that you declare when you instance it and then add in your own custom filtered set with setCustomSourceItems().

  • UncleCheese
    Avatar
    4085 Posts

    Re: Using setCustomSourceItems with the DOM Link to this post

    Nice!!

    813 Views
Page: 1
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.