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

2.4 - DOM in SiteConfig not working for me


Reply

39 Posts   6568 Views

Avatar
mattclegg

6 September 2010 at 10:25pm Community Member, 56 Posts

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?

Avatar
UncleCheese

7 September 2010 at 1:39am 4085 Posts

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.

Avatar
Juanitou

4 January 2012 at 12:55am Community Member, 323 Posts

For your information, I had to add the setSourceID call for this to work.

Thanks again, UncleCheese!

Avatar
Ruud

22 February 2012 at 10:02pm Community Member, 3 Posts

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?

Avatar
Ruud

22 February 2012 at 10:26pm Community Member, 3 Posts

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();
}

Avatar
jizzman

2 March 2012 at 2:14am Community Member, 23 Posts

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.

Avatar
borriej

22 January 2013 at 5:01am (Last edited: 22 January 2013 5:20am), Community Member, 267 Posts

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