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.

Archive /

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

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

has_many editor


Go to End


15 Posts   8239 Views

Avatar
Ingo

Forum Moderator, 801 Posts

27 September 2007 at 3:42am

> 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

Community Member, 791 Posts

25 November 2007 at 4:05am

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

121 Posts

25 November 2007 at 11:14am

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 http://www.peterpetrou.com/

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

Community Member, 245 Posts

18 July 2008 at 3:55am

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

121 Posts

18 July 2008 at 7:31am

Did you db/build?flush=1

Avatar
Garrett

Community Member, 245 Posts

18 July 2008 at 7:36am

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
bummzack

Community Member, 904 Posts

2 August 2008 at 11:23pm

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:
http://www.silverstripe.com/extending-hacking-silverstripe-forum/flat/134180

Cheers

Go to Top