7911 Posts in 1354 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Using setCustomSourceItems with the DOM
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 696 Views |
-
Using setCustomSourceItems with the DOM

24 March 2010 at 3:22am
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? -
Re: Using setCustomSourceItems with the DOM

24 March 2010 at 3:26am
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? -
Re: Using setCustomSourceItems with the DOM

24 March 2010 at 3:43am
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.
-
Re: Using setCustomSourceItems with the DOM

24 March 2010 at 3:45am
Thanks for the info, I'm really looking forward to DOM 2.0!
-
Re: Using setCustomSourceItems with the DOM

24 March 2010 at 4:15am
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().
| 696 Views | ||
|
Page:
1
|
Go to Top |

