Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » remove image, not delete from folder

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

Page: 1
Go to End
Author Topic: 1552 Views
  • JMagnusson
    Avatar
    Community Member
    29 Posts

    remove image, not delete from folder Link to this post

    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

  • martimiz
    Avatar
    Forum Moderator
    1036 Posts

    Re: remove image, not delete from folder Link to this post

    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...

  • JMagnusson
    Avatar
    Community Member
    29 Posts

    Re: remove image, not delete from folder Link to this post

    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

  • martimiz
    Avatar
    Forum Moderator
    1036 Posts

    Re: remove image, not delete from folder Link to this post

    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

  • JMagnusson
    Avatar
    Community Member
    29 Posts

    Re: remove image, not delete from folder Link to this post

    Thanks, worked for me too.

    1552 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.