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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Using setCustomSourceItems with the DOM


Reply

6 Posts   829 Views

Avatar
MarcusDalgren

24 March 2010 at 3:22am Community Member, 288 Posts

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?

Avatar
MarcusDalgren

24 March 2010 at 3:26am Community Member, 288 Posts

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?

Avatar
UncleCheese

24 March 2010 at 3:43am 4085 Posts

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.

Avatar
MarcusDalgren

24 March 2010 at 3:45am Community Member, 288 Posts

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

Avatar
MarcusDalgren

24 March 2010 at 4:15am Community Member, 288 Posts

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().

Avatar
UncleCheese

24 March 2010 at 4:49am 4085 Posts

Nice!!