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.

Archive

Our old forums are still available as a read-only archive.

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

has_many editor


Reply

15 Posts   6765 Views

Avatar
Ingo

27 September 2007 at 3:42am Forum Moderator, 801 Posts

> 1) Is it easy to get rid of the checkboxes (as I am filtering the source they are always checked)? Maybe subclass and override the function?
other way around, use the parentclass ComplexTableField instead if you don't need the relation-setting through checkboxes :)

> 2) I'd like to show values from the Image class in the table somehow (e.g. filename).
you can show any properties that can be accessed on the normal object (or more with setCustomQuery())

> 3) The ImageField control seems to require that the record is added before the image can be selected. This is a pain because you have to add a PortfolioImage and then edit it to choose an image.
thats by design, nothing you can easily change without rebuilding the ImageField, as its using iframes for upload. i agree that usability could be better in this use-case...

Avatar
Fuzz10

25 November 2007 at 4:05am Community Member, 787 Posts

Hi Jam,

Did you get these things fixed in the meantime ? Working on a little app. which needs the same kind of functionalities.

Thanks.....

>1) Is it easy to get rid of the checkboxes (as I am filtering the source they are always >checked)? Maybe subclass and override the function?

>3) The ImageField control seems to require that the record is added before the image can be >selected. This is a pain because you have to add a PortfolioImage and then edit it to choose >an image.

Avatar
jam13

25 November 2007 at 11:14am 121 Posts

No - not really. I still haven't found a satisfactory way of attaching multiple images to a page as none of the CMS controls are really designed for it.

The best solution I've found so far is to create folders of images and then link a page to a folder, although this doesn't allow much control of image order. Here's the (simplified) code for a "Gallery Page" that we did for [url]http://www.peterpetrou.com/[/url]

class GalleryPage extends Page {
static $has_one = array(
'Image' => 'Image'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Images', new ImageField('Image','Main Image'));
return $fields;
}
}

class GalleryPage_Controller extends Page_Controller {
function Images() {
$imageFolder = $this->Image()->ParentID;
$images = DataObject::get("File", "ParentID = '$imageFolder'");
return $images;
}
}

Each page has_one primary image, and all the other images that are in the same folder as the primary image are available using the Images function.

This idea was blatantly stolen from the Gallery module ;)

Avatar
Garrett

18 July 2008 at 3:55am Community Member, 245 Posts

Hi,

I copied your code-- thanks A LOT for that! I've been havnig a heck of a time trying to do the same thing.

My Images tab is showing up nicely, my popup's got the right fields, I can enter the title and upload the image and all that. However, one small problem:

After I click SAVE and close the popup, I see that it does not appear on the list, which I assume means it has not been saved to the Database?

What could I be doing wrong here?

Thanks,
Garrett

Avatar
jam13

18 July 2008 at 7:31am 121 Posts

Did you db/build?flush=1

Avatar
Garrett

18 July 2008 at 7:36am Community Member, 245 Posts

I did, I did, yes.... You know what it was? It was this line:

"PortFolioID = {$this->ID}"

Mine needed to be "ProjectPageID = {$this->ID}".

Thanks! Image gallery is rocking now!

//Garrett

Avatar
banal

2 August 2008 at 11:23pm Community Member, 901 Posts

Hi.
I developed a cms extension that allows you to attach multiple files/images to a Page. You seem to have resolved your problem, but maybe this could still be of interest for you:
[url]http://www.silverstripe.com/extending-hacking-silverstripe-forum/flat/134180[/url]

Cheers