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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Adding Files to Images within Image Gallery


Go to End


21 Posts   6417 Views

Avatar
mattclegg

Community Member, 56 Posts

7 September 2010 at 12:40am

Hey Adrian

It seems you cant use FileDataObjectManager in this way, but you can use regular DataObjectManager to do the same thing, ie;

<?php
class CaseStudy extends Page {
 
	static $has_many = array ('CaseStudyImages' => 'CaseStudy_Image');
 
	public function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->addFieldToTab("Root.Content.Object",$manager = new DataObjectManager($this,'CaseStudyImages','CaseStudy_Image',array('Name' => 'Name','CMSThumbnail'=>'Preview'),'getCMSFields_forPopup',null,"Name Asc")); 
      	return $fields;
	}
}
class CaseStudy_Image extends DataObject 
{ 
   static $db = array ( 
      'Name' => 'Varchar'    
   ); 
    
   static $has_one = array ( 
      'Attachment' => 'Image', 
      'Thumbnail' => 'Image', 
      'CaseStudy' => 'CaseStudy' 
   );
   
   public function getCMSFields_forPopup() 
   { 
      return new FieldSet(
      	new ImageField('Thumbnail'),
      	new TextField('Name'),
      	new ImageField('Attachment')
      ); 
   }
	function CMSThumbnail() {
		if ($image=$this->Thumbnail())return $image->CMSThumbnail();
		return null;
	}
}

This should work regardless of what version you have

Avatar
adesweb

Community Member, 39 Posts

7 September 2010 at 12:57am

OK cool, slightly different user journey, but essentially it will work, and it won't mean having to re-upload all of the images again!

Thanks for your help

Avatar
mattclegg

Community Member, 56 Posts

7 September 2010 at 1:14am

WHAT? Why upload the images again?

You can still attach any images that have already been uploaded to the SS filestore.

Or you could even use a RAW SQL query to update your objects, if the structure has changed soo much?

Avatar
adesweb

Community Member, 39 Posts

7 September 2010 at 1:48am

No, I don't need to upload the images. Note the negative :)

Thanks,
Adrian

Avatar
mattclegg

Community Member, 56 Posts

7 September 2010 at 1:48am

Ah sorry, TLDR

Go to Top