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   6597 Views

Avatar
klikhier

2 August 2010 at 8:13am Community Member, 150 Posts

thanks, Uncle Cheese. I tried adding that:

...
$idom->setSourceID($this->owner->ID);
$idom->setParentClass('SiteConfig');
$fields->addFieldToTab("Root.Photos", $idom);
}

but still I receive

[User Error] Couldn't run query: SELECT "SlideshowPhoto"."ClassName", "SlideshowPhoto"."Created", "SlideshowPhoto"."LastEdited", "SlideshowPhoto"."Caption", "SlideshowPhoto"."ImageID", "SlideshowPhoto"."CustomSiteConfigID", "SlideshowPhoto"."ID", CASE WHEN "SlideshowPhoto"."ClassName" IS NOT NULL THEN "SlideshowPhoto"."ClassName" ELSE 'SlideshowPhoto' END AS "RecordClassName" FROM "SlideshowPhoto" WHERE ("ParentID" = '1') Unknown column 'ParentID' in 'where clause'

Avatar
silverstriper

4 August 2010 at 9:52pm Community Member, 8 Posts

I had this same problem and I solved it by setting a relation back to SiteConfig on the DataObject I was trying to edit in the DOM, so my SiteConfig looks like this:

   function extraStatics() {
      return array(
         'has_many' => array(
            'Notices' => 'Notice'
         )
      );
   }

   public function updateCMSFields(FieldSet &$fields) {

      
      //Notices
      $Manager = new SiteConfig_DataObjectManager(
         $this->owner,
         'Notices',
         'Notice',
         Notice::$summary_fields
      );
      
      $Manager->setParentClass('SiteConfig');
      $Manager->setSourceID($this->owner->ID);
      $fields->addFieldToTab('Root.Notice', $Manager);

      return $fields;   
   }

and my DataObject has this:

   static $has_one = array(
      'MyCustomSiteConfig' => 'SiteConfig'
   );

Hope this helps!

Avatar
Zomba

5 August 2010 at 12:00pm Community Member, 2 Posts

You are using $Manager = new SiteConfig_DataObjectManager, is there a way to avoid this?
When i use a $manager, i get a white screen.

And what do you mean by 'my DataObject'?

I am trying hard to add a tab called "Banner" where the editor can upload multiple images into the banner which is visible on the entire website. Based on the topic 'adding multiple images to a page type'.

It works fine in a page type, but because it is different to add it to the SiteConfig, i get stuck.
What am i doing wrong?

<?php

class CustomSiteConfig extends DataObjectDecorator {
   
   function extraStatics() {
      return array(
         'has_many' => array(
             'GalleryImages' => 'GalleryImage'
         )
      );
   }
   

   public function updateCMSFields(FieldSet &$fields) {      
      
      $manager = new SiteConfig_DataObjectManager(
$this->owner,
'GalleryImages',
'GalleryImage',
       'MyGalleryImage',
array(
'GalleryImageTitle' => 'GalleryImageTitle'
),
'getCMSFields_forPopup'
);

$manager->setParentClass('SiteConfig');
$manager->setSourceID($this->owner->ID);
$fields->addFieldToTab('Root.GalleryImage', $manager);
return $fields;
   }
}

Avatar
UncleCheese

5 August 2010 at 12:29pm 4085 Posts

You don't need to subclass DataObjectManager anymore. Those two sourceID() functions were rolled into the core a few revs ago.

Avatar
mattclegg

6 September 2010 at 8:55am Community Member, 56 Posts

Hey Uncle Cheese,

I noticed the two sourceID() functions are in rev.418, but

function setSourceID($val)


seems to have been removed in rev.419?

Im guessing its a typo?

Avatar
AdamJ

6 September 2010 at 3:43pm Community Member, 145 Posts

So I downloaded DOM and Uploadify from leftandmain.com today, and am trying to get a ImageDataObjectManager working with SiteConfig, but am hitting a similar issue as an earlier poster. Adding images seems to work fine, but if I click on any to edit them, I get the following error:

[User Error] Couldn't run query: SELECT "BannerImages"."ClassName", "BannerImages"."Created", "BannerImages"."LastEdited", "BannerImages"."Title", "BannerImages"."myImageID", "BannerImages"."ID", CASE WHEN "BannerImages"."ClassName" IS NOT NULL THEN "BannerImages"."ClassName" ELSE 'BannerImages' END AS "RecordClassName" FROM "BannerImages" WHERE ("ParentID" = '1') Unknown column 'ParentID' in 'where clause'

Here is my code:

CustomSiteConfig.php

<?php

class CustomSiteConfig extends DataObjectDecorator {

function extraStatics() {
return array(
'has_many' => array(
'Images' => 'BannerImages'
)
);
}
public function updateCMSFields(FieldSet &$fields) {

$manager = new ImageDataObjectManager(
$this->owner,
'Images',
'BannerImages',
'myImage',
array('Title' => 'Title'),
'getCMSFields_forPopup'
);

$manager->setParentClass("SiteConfig");
$manager->setPluralTitle('Images');
$fields->addFieldToTab("Root.Images", $manager);

}
}

BannerImages.php

<?php
class BannerImages extends DataObject
{
   static $db = array (
      'Title' => 'Text'
   );
   
   static $has_one = array (
      'myImage' => 'Image'
   );
   
   public function getCMSFields_forPopup()
   {
      return new FieldSet(
         new TextField('Title'),
         new FileIFrameField('myImage')
      );
   }
}

Any ideas?

Avatar
UncleCheese

6 September 2010 at 4:09pm 4085 Posts

Your BannerImage object needs to reciprocate a $has_one to SiteConfig, otherwise, there's no relationship between the two.

-------
Silverstripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Avatar
AdamJ

6 September 2010 at 4:29pm Community Member, 145 Posts

Yeah, I was just about to post that Silverstriper's fix fixed it for me. Thanks!