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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

[SOLVED] Show SiteTree inside getCMSFields_forPopup()


Go to End


1469 Views

Avatar
Mrfixer

Community Member, 49 Posts

4 July 2011 at 9:59am

Edited: 04/07/2011 10:10pm

Hi im trying to get the sitetree to show inside the dataobjectmanager popup, heres what im hoping to achieve

1) upload a set of images
2) apply captions and titles to each
3) add an internal link that echos out on page inside a span. (like a "read more")

1) and 2) are no problem, working great, applying the sitetree however is giving me grief, this is what i have..

My Class file:

<?php 
class HomepageImageResource extends DataObject
{
    static $db = array (
        'HomepageTitle' => 'Text',
        'HomepageCaption' => 'Text'
    );
 
    static $has_one = array (
        'HomepageAttachment' => 'Image',
        'HomepageInternalLink' => "SiteTree"  
    );
 
    public function getCMSFields_forPopup()
    {
        return new FieldSet(
            new TextField('HomepageTitle'),
            new TextareaField('HomepageCaption'),
            new FileIFrameField('HomepageAttachment')
        //    new SimpleTreeDropdownField( 'HomepageInternalLinkID', 'HomepageInternalLink', 'SiteTree' )
       );
    }
}

now onto my HomePage extends Page: (note the "// this causes me the error" comment) without that line all works ok but no sitetree

class HomePage extends Page {
   static $db = array( 
   );
   static $has_one = array(
   );
   
   static $has_many = array (
        'HomepageImages' => 'HomePageImageResource'
    );
   
   function getCMSFields() {
       
      $fields = parent::getCMSFields();
      
      $fields->removeFieldFromTab('Root.Content.Main', 'Content');
      
       $fields = parent::getCMSFields();
        $homepagemanager = new ImageDataObjectManager(
            $this, // Controller
            'HomepageImages', 
            'HomepageImageResource',
            'HomepageAttachment',
            'HomepageInternalLink',                   // this causes me the error"
      
            array(
                'HomepageTitle' => 'HomepageTitle', 
                'HomepageCaption' => 'HomepageCaption'
            ), // Headings 
            'getCMSFields_forPopup'
        );
        $fields->addFieldToTab("Root.Content.Main",$homepagemanager);
        
        $fields->removeFieldFromTab('Root.Content.Main', 'MainPageContent'); 

   return $fields;
 }
   
   
}

UPDATE: Marked as Solved
this is what i needed to do to get it working if anyone else comes across this issue:

In HomePage.php i changed the getCMSFields() function to:

function getCMSFields() {
       
      $fields = parent::getCMSFields();
      
      $fields->removeFieldFromTab('Root.Content.Main', 'Content');
      
       $fields = parent::getCMSFields();
        $homepagemanager = new ImageDataObjectManager(
            $this, // Controller
            'HomepageImages', // Source name
            'HomepageImageResource', // Source class
            'HomepageAttachment', // File name on DataObject
            //'HomepageInternalLink',
      
            array(
                'HomepageTitle' => 'HomepageTitle', 
                'HomepageCaption' => 'HomepageCaption'
            ),  
            'getCMSFields_forPopup'
        );
        
        $homepagemanager->setRelationAutoSetting(false);
        
        $fields->addFieldToTab("Root.Content.Main",$homepagemanager);
        
        $fields->removeFieldFromTab('Root.Content.Main', 'MainPageContent'); 

   return $fields;
 }

overriding default setRelationAutoSetting to false