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.

General Questions /

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

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

Images not showing up in Uploadfields Filebrowser


Go to End


4 Posts   2115 Views

Avatar
mgherkins

Community Member, 8 Posts

18 October 2012 at 7:00am

Edited: 18/10/2012 7:20am

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

Avatar
Sam

Administrator, 690 Posts

19 October 2012 at 12:26pm

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.

Avatar
mgherkins

Community Member, 8 Posts

22 October 2012 at 6:54am

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

Avatar
RuthAdele

Community Member, 21 Posts

16 November 2012 at 6:03pm

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?