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.

Customising the CMS /

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

remove image, not delete from folder


Go to End


5 Posts   2518 Views

Avatar
JMagnusson

Community Member, 29 Posts

14 January 2011 at 2:55am

I let my users chose an image for every page to use as a banner. But when someone has chosed an image from the assets folder, and then want to delete it (removes the banner) instead of just change it, the image is deleted from the folder, and from every other page.

How to just set the database field to zero, and don't remove the image?

/Johan

Avatar
martimiz

Forum Moderator, 1391 Posts

16 January 2011 at 4:08am

In 2.4 I at least found no no 'disableFileDelete' kind of option for the ImageField. But if you were to block the FileIframeField.js from the requirements, it would prevent the popup, and just immediately unattach the image, without deleting it (which seems not so bad, since you can always re-attach it if you wish).

So you could maybe extend the ImageField to 'BannerImageField', and override the function iframe() (copy it from the FileIFrame class) and block the FileIframeField.js from loading...

Other options:
- present a simple dropdown of banner names from the
- use a treedropdown
- use a radiogroup with banner-image thumbnails

Hope this helps - but I've not needed this before, so others might have far better solutions... :-)

Avatar
JMagnusson

Community Member, 29 Posts

16 January 2011 at 6:59am

Oh, thanks for more than one solution :)
I dont understand all of it...can I put the extended class in my mysite/code folder, and just write the function iframe(), like:

public function iframe() {
// clear the requirements added by any parent controllers
Requirements::clear();
Requirements::add_i18n_javascript('sapphire/javascript/lang');
Requirements::javascript(THIRDPARTY_DIR . '/prototype/prototype.js');
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
//Requirements::javascript('sapphire/javascript/FileIFrameField.js');

Requirements::css('cms/css/typography.css');
Requirements::css('sapphire/css/FileIFrameField.css');

return $this->renderWith('FileIFrameField');
}

You se, I'm not a programmer :)

Avatar
martimiz

Forum Moderator, 1391 Posts

16 January 2011 at 11:40am

mysite/code/BannerImageField.php:

<?php 

class BannerImageField extends ImageField {
	public function iframe() {
		// clear the requirements added by any parent controllers
		Requirements::clear();
		Requirements::add_i18n_javascript('sapphire/javascript/lang');
		Requirements::javascript(THIRDPARTY_DIR . '/prototype/prototype.js');
		Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
		//Requirements::javascript('sapphire/javascript/FileIFrameField.js');
		
		Requirements::css('cms/css/typography.css');
		Requirements::css('sapphire/css/FileIFrameField.css');
		
		return $this->renderWith('FileIFrameField');
	}
}

And in your Pages/Objects getCMSFields():

$imageField = new BannerImageField( ... 

works, tested it :-)

Avatar
JMagnusson

Community Member, 29 Posts

20 January 2011 at 4:29am

Thanks, worked for me too.