Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » 2.4 - DOM in SiteConfig not working for me

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2 3 4 5
Go to End
Author Topic: 6496 Views
  • mattclegg
    Avatar
    Community Member
    56 Posts

    Re: 2.4 - DOM in SiteConfig not working for me Link to this post

    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?

  • UncleCheese
    Avatar
    4085 Posts

    Re: 2.4 - DOM in SiteConfig not working for me Link to this post

    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.

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: 2.4 - DOM in SiteConfig not working for me Link to this post

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

    Thanks again, UncleCheese!

  • Ruud
    Avatar
    Community Member
    3 Posts

    Re: 2.4 - DOM in SiteConfig not working for me Link to this post

    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?

  • Ruud
    Avatar
    Community Member
    3 Posts

    Re: 2.4 - DOM in SiteConfig not working for me Link to this post

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

  • jizzman
    Avatar
    Community Member
    23 Posts

    Re: 2.4 - DOM in SiteConfig not working for me Link to this post

    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.

  • borriej
    Avatar
    Community Member
    267 Posts

    Re: 2.4 - DOM in SiteConfig not working for me Link to this post

    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

    6496 Views
Page: 1 2 3 4 5
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.