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

2.4 - DOM in SiteConfig not working for me


Go to End


39 Posts   13221 Views

Avatar
Deklin

Community Member, 16 Posts

13 July 2010 at 3:05am

Where should it go? I tried to follow Aram's tutorial as closely as possible but I must have missed something.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

13 July 2010 at 3:08am

I'm not familiar with it, but it seems to me those functions need to be defined in the CTF or a subclass thereof. You've defined them in your site config decorator, but they're not doing anything as far as I can see.

Avatar
Carbon Crayon

Community Member, 598 Posts

13 July 2010 at 3:13am

Hi Delkin,

If you look a little closer at the code in the tutorial you'll see that we actually need to create a new class which extends DataObjectManager to put our new function into.

In this case you need to create a class that extends HadManyComplexTableField which might look like this:


class SiteConfig_HasManyComplexTableField extends HasManyComplexTableField {
function setSourceID($val) {
if (is_numeric($val)) {
$this->sourceID = $val;
}
}
function sourceID() {
if (isset($this->sourceID) && $this->sourceID !== null && is_numeric($this->sourceID)) {
return $this->sourceID;
}
return parent::sourceID();
}
}

then in getCMS fields make sure you create a SiteConfig_HasManyComplextTableField instead of just a standard one.

Out of interest why are you using a CTF over a DOM? I din't realise there was any compelling reason to do so! :)

Aram

www.SSBits.com - SilverStripe Tutorials, Tips and other bits

Avatar
UncleCheese

Forum Moderator, 4102 Posts

13 July 2010 at 3:37am

Ha... Thanks for the promo, Aram.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

13 July 2010 at 3:38am

By the way, would it make sense to roll those functions into the DOM source so you don't have to subclass it? Seems odd to have to create a subclass for something to fundamental.

Avatar
Carbon Crayon

Community Member, 598 Posts

13 July 2010 at 3:44am

Ha... Thanks for the promo, Aram."

No need for thanks, just saying it how it is :)

By the way, would it make sense to roll those functions into the DOM source so you don't have to subclass it? Seems odd to have to create a subclass for something to fundamental.

Yea that would be awesome, would mean it could be used in SiteConfig without any extra work, except for actually setting the SourceID. In fact would explicitly calling that function in the DOM code adversely effect the DOM when used on a regular page? If not then that would allow it to be used in SiteConfig without any extra code at all....

Avatar
UncleCheese

Forum Moderator, 4102 Posts

13 July 2010 at 4:15am

You want to try it and report your findings? I think what you want is somewhere in the constructor to add $this->setSourceID($this->controller->ID);

Man, that DOM code is such a mess. I hate going in there. Amazing how an extra year's worth of experience really changes your perception.

Avatar
Carbon Crayon

Community Member, 598 Posts

13 July 2010 at 5:51am

implemented and tested, diff atta...oh can't attach files anymore? Ok you can find it here: http://aabweb.co.uk/assets/Uploads/DataObjectManager.php.diff :)

I havnt tested extensively (i.e. with all the different DOM types), though as you'll see from the code I haven't done anything that will effect the sourceID function on normal pages, just added a condition to fetch the sourceID if it can't get it the normal way.

Let me know if that looks ok

Thanks UC!

Aram