In Site Config, do you still need to use;
$manager->setParentClass('SiteConfig');
$manager->setSourceID($this->owner->ID);
or is it just;
$manager->setParentClass('SiteConfig');
What about if using it from another object decorator?
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba
In Site Config, do you still need to use;
$manager->setParentClass('SiteConfig');
$manager->setSourceID($this->owner->ID);
or is it just;
$manager->setParentClass('SiteConfig');
What about if using it from another object decorator?
Probably not. If you have a corresponding $has_many and $has_one, you shouldn't need any of that. Maybe the sourceID() call.. cause I know SiteConfig is a bit of a different animal.
For your information, I had to add the setSourceID call for this to work.
Thanks again, UncleCheese!
The solution offered in this topic works for me, but somehow not totally:
In my customsiteconfig.php i have this code:
$manager = new DataObjectManager(
$this->owner,
'Quotes',
'Quote',
array(
'Quote' => 'Quote'
),
'getCMSFields_forPopup'
);
$manager->setSourceID($this->owner->ID);
$manager->setParentClass('SiteConfig');
$fields->addFieldToTab("Root.Quotes",$manager);
Then, in my Quote.php i have:
class Quote extends DataObject
{
static $db = array (
'Quote' => 'HTMLText'
);
static $has_one = array (
'SiteConfig' => 'SiteConfig'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new SimpleHTMLEditorField('Quote','Quote')
);
}
}
I use this on a multilanguage site, so in my _config.php i have:
Object::add_extension('SiteConfig', 'Translatable');
At first, the dataobjectmanager loads the items for the language that has been selected. When I click the "add quote" button and click away or save, the dataobjectmanager loads the items for the default language. Somehow, it loses the reference to the loaded siteconfig. Does anyone else have troubles with DOM in CustomSiteConfig with multiple languages?
it seems the siteconfig and locale stuff doesn't work very well. I hacked the DataObjectManager class in the following way, and now it works:
public function Link($action = null)
{
return Controller::join_links(parent::Link($action),'?'.$this->getQueryString()."&locale=".Translatable::get_current_locale());
}
public function BaseLink()
{
return parent::Link()."&locale=".Translatable::get_current_locale();
}
I'm currently having a battle with SiteConfig ...
FYI: I found that I had to do what Juanitou did and also add "$manager->setSourceID($this->owner->ID);" to get a complete solution: add items, retrieve component set.
Without the setSourceID() call, any query on a 'has_many' set (i.e. SiteConfig::current_site_config()->MyHasManyItems()) would return an empty ComponentSet; even though in the CMS I could see all the items.
J.
Sorry for pulling this thread up, but what is the final piece of code to make DOM work on a siteconfig using SS 2.4.9 and the latest DOM from github? See my attempt which doesn't work: http://paste2.org/p/2782785
Update works now: http://paste2.org/p/2782858