Jump to:

10979 Posts in 2722 Topics by 1815 members

All other Modules

SilverStripe Forums » All other Modules » Subsites module. SiteConfig extension hasmany issue

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 314 Views
  • Fraser
    Avatar
    Community Member
    46 Posts

    Subsites module. SiteConfig extension hasmany issue Link to this post

    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'
       );

    }

    314 Views
Page: 1
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.