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:

Customising the CMS /

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

A Few Questions About Extending A Custom Image Type Across All Pages

Go to End

2 Posts   601 Views


Community Member, 138 Posts

29 November 2011 at 12:39pm

This linked code creates a CustomImage type which has a Caption and Location added to the object:

I want to achieve a number of enhancements and outcomes with this code:

1. When "Add An Image" is clicked in the CMS a window (getCMSFields_forPopup) appears and an image can be uploaded and caption added. When the new image has been saved, and the popup closed I want to have the image automatically added to the page.

2. The Location value specifies where the image is displayed on a page. For example the Location "sidebar" would make the image appear in the sidebar or "below-article" would make the image appear below the article. I want to be able to specify the list of available locations so it relates to the Page type. For example a MapPage might have the locations "above-map" and "below-map" while NewsPage might have "top-right", "bottom-left" and "bottom-right". How do I specify the location options in the getCMSFields_forPopup so they can be set by each Page type?

3. I'd like to make it so a Page can have many CustomImages but only one CustomImage can be "Featured". What is the best way of setting up and controlling this relationship?

4. Currently all of the CustomImages are displayed in the CMS on every single page. Ideally I'd just like to display those CustomImages attached to the Page. If that isn't possible I'd like to sort the table with the attached images at the top.

Thank you in advance.



Forum Moderator, 1391 Posts

29 November 2011 at 11:39pm

just off the top of my head - you could define a has_may relation from your Page to your SpecialImage, use a sortable listfield like the DataObjectManager, or ajshort's Orderable module.

You could have a 'Location' array variable in your SpecialImage class that you could then set from your PageType's getCMSFunction, and use to display as a dropdown in your listfields popup.

Then, since you are using a sortable listfield, the one on top could always be the featured one, so you can easily change it. (order by SortOrder, limit 1)

Something like that?