Jump to:

23550 Posts in 19336 Topics by 2890 members

General Questions

SilverStripe Forums » General Questions » Images not showing up in Uploadfields Filebrowser

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1059 Views
  • max5k
    Avatar
    Community Member
    8 Posts

    Images not showing up in Uploadfields Filebrowser Link to this post

    Hello,

    in multiple projects we extend the Image Class to add some Fields like "Caption" etc.

    class CustomImage extends Image{
    //add fields, override getCMSFields() etc.
    }

    Now on a PageType which has many of those CustomImages those are managed with an uploadField

    $has_many = array('CustomImages' => 'CustomImage')


    $fields->addFieldToTab("Root.Main", new UploadField('CustomImages', 'Custom Images'), 'Content');

    This works fine and Images upload via the uploadfield get the ClassName "CustomImage" in the "File" tab.

    Problem:
    When browsing for files to add, instead of uploading them directly, only Files with ClassName "CustomImage" show up.
    Files uploaded in the Files-section however got the default ClassName "Image" and are not showing up within folders.

    Is there any way to use my custom Image type while still being able to add Images in the uploadfield via the Browser which
    were added previously in the Files-section?

    Merci d'advance

    Cheers

    Max

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: Images not showing up in Uploadfields Filebrowser Link to this post

    It's better to use $many_many for linking to multiple images, otherwise it's impossible for an image to be linked in more than one place, which runs counter to the way the asset library is used elsewhere.

    If you do use $has_many, make sure that you have added the relevant $has_one to Image.

  • max5k
    Avatar
    Community Member
    8 Posts

    Re: Images not showing up in Uploadfields Filebrowser Link to this post

    true.

    Nevertheless i solved my actual problem by not extending image directly
    (which might not be such a good idea at all, as it messes up the classnames in the "File" table)
    but using the DataExtension Class:

    class ImageExtension extends DataExtension
    {

    static $db = array(
    'Alt' => 'Varchar'
    );

    public function updateCMSFields(FieldList $fields) {
    $fields->addFieldToTab('Root.Main', new TextField('Alt', 'Alt'), 'Name');
    }

    }

    Object::add_extension('Image', 'ImageExtension');

    This way i could have an extra Alt-Text Field directly on the Image, which allows me to manage it using the uploadfield without the need for an additional dataobject and a gridfied...

  • RuthAdele
    Avatar
    Community Member
    19 Posts

    Re: Images not showing up in Uploadfields Filebrowser Link to this post

    I'm having the same issue, slightly different, because I want to use $gd image manipulation functions within my extension.
    Right now I have:

    class CustomImage extends Image {
    function generateProfileImage($gd) {
    $gd->setQuality(80);
    return $gd->resizeByWidth(110);
    }
    }

    I don't think I will be able to use $gd functions if I change this to extend DataExtension...

    Does anyone know a way to get UploadField to query files with class name CustomImage AND Image?

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