Jump to content

Adding image or file field to a module configuration


Hari KT
 Share

Recommended Posts

Hi all,

I was trying to add an image field to `implements Module, ConfigurableModule ` . When uploading image I was getting error as TemplateFile: Invalid image<pre>#0 [internal function]: InputfieldFile->___processInputAddFile('fdd-1.jpg') #1 

public static function getModuleConfigInputfields(array $data) {

    $inputfields = new InputfieldWrapper();
    // $field = wire('modules')->get('InputfieldImage');
    // $field->attr('name', 'logo');
    // $field->label = __('Logo');
    // $field->addOption('logo', 'logo');
    // $field->attr('value', isset($data['logo']) ? $data['logo'] : '');
    $field = wire('modules')->get('InputfieldFile');
    $field->attr('name', 'logo');
    $field->label = __('Logo');
    $inputfields->add($field);

    return $inputfields;
}

I tried with file which gives me invalid extensions. Is there a way to fix it ?

Basic idea is to extend a template which can have upload functionality of logo etc.

Thank you.

Link to comment
Share on other sites

There was many changes to file or images and overall, I had once in ImageManager used a InputfieldFile on a process admin module, set the upload dir etc, and then loaded the file from there to create image pages.

But then since 2.5 I think it didn't work suddenly, and I couldn't get Ryan to explain what happens (as so many times) So I'm not sure what's working and what not anymore. Well after hours of trying and thinking I got it working, just something I can't make sense of it. 

All I remember was that the admin page is used to upload the image from a InputfieldImage, where before it wasn't.

This code is interesting, but as said I have no idea what worked and why.

https://github.com/somatonic/ImagesManager/blob/master/ImagesManager.module#L173


Ohhh, and you might be on a module settings config screen you are having this? There it won't work anyway as there's no page!

  • Like 2
Link to comment
Share on other sites

You may also find that you need to call getDatabaseSchema($field) to make sure the DB table is updated to include the extra required fields for image and file fields. One additional thing I noticed is that even though this is supposed to take care of adding the tags field, it doesn't seem to work, so I also do the following if I need the tags field added:

$sql = "ALTER TABLE `field_imaged` ADD `tags` TEXT NOT NULL";
$query = $this->wire('database')->prepare($sql);
$query->execute();
Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...