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.

All other Modules /

Discuss all other Modules here.

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

Subsites module. SiteConfig extension hasmany issue


Reply


334 Views

Avatar
Fraser

Community Member, 47 Posts

6 July 2012 at 1:17pm

Edited: 06/07/2012 1:35pm

I'm having an issue with the subsites module:

In my site, I am extending SiteConfig to add a number of site-wide options. I am able to set all of these on a persite basis with the exception of the BackgroundImages dataobjectmanager. For some reason, every background I add to each site is added to all the other sites as well. Not just the active one. Is there anything I am doing wrong in my code:

<?php

class SiteConfigExtension extends DataObjectDecorator {

   function extraStatics() {
      return array(
         'db' => array(
            'FooterContent' => 'HTMLText',
            'PrimaryColour' => 'Varchar',
            'SecondaryColour' => 'Varchar',
            'Identifier' => 'Varchar'
         ),
         'has_one' => array(
            'Logo' => 'Photo',
            'HeaderPhoto' => 'Photo',
            'DefaultBG' => 'Photo',
            'ToggleTab' => 'Photo'
         ),
         'has_many' => array(
            'BackgroundImages' => 'BackgroundImage'
         )
      );
   }
   static $default_child = "Gallery";
   
   function updateCMSFields(FieldSet &$fields) {
      $fields->addFieldToTab('Root.Footer', new HTMLEditorField('FooterContent', 'Footer Content'));
      $fields->addFieldToTab('Root.DefaultBackground', new ImageUploadField('DefaultBG', 'DefaultBG'));
      $fields->addFieldToTab('Root.Backgrounds', new ImageDataObjectManager($this->owner, 'BackgroundImages', 'BackgroundImage'));
      $fields->addFieldToTab('Root.Styling', new TextField('PrimaryColour', 'Primary Colour'));
      $fields->addFieldToTab('Root.Styling', new TextField('SecondaryColour', 'Secondary Colour'));
      $fields->addFieldToTab('Root.Styling', new ImageField('ToggleTab', 'Toggle Tab'));
      $fields->addFieldToTab('Root.Styling', new TextField('Identifier', 'Identifier'));
      
      $fields->addFieldToTab('Root.Main', new ImageField('Logo', 'Logo'));
      
      $fields->removeByName('Tagline');
      $fields->removeByName('Theme');
   }
   
}

Update: I am getting the expected result in the front end of the site (the site they were added from in subsites is displaying the correct background images ), however it is just in the imagedataobjectmanager in the CMS where it is displaying them all together.

Here is the code for the BackgroundImage class:

<?php

class BackgroundImage extends Photo {
   
   static $has_one = array(
      'SiteConfig' => 'SiteConfig'
   );

}