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

Avatar
klikhier

Community Member, 150 Posts

2 August 2010 at 8:13am

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

Community Member, 8 Posts

4 August 2010 at 9:52pm

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

Community Member, 2 Posts

5 August 2010 at 12:00pm

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

Forum Moderator, 4096 Posts

5 August 2010 at 12:29pm

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

Avatar
mattclegg

Community Member, 56 Posts

6 September 2010 at 8:55am

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

Community Member, 145 Posts

6 September 2010 at 3:43pm

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

Forum Moderator, 4096 Posts

6 September 2010 at 4:09pm

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

Community Member, 145 Posts

6 September 2010 at 4:29pm

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