Jump to content

File field thumbnail in form array


Recommended Posts

Hi,

 

Does anyone know how to change the thumbnail images for new image upload fields?

 

The 'thumb' variable in the form array does not seem to have any effect on the individual fields, and I can't seem to find documentation on what fields are available for this array/field options. Each of the fields seems to only pull through the thumbnail image of the first 'image' field.

 

Thanks for any help

Link to comment
Share on other sites

I have looked into it more and the fields are getting their thumbnail set by the $this->fields_value array. I have tried setting the values as follows but they are still being set to the 'image' field. Does anyone know how to change this?

 

Thanks for any help

 


$image = ImageManager::thumbnail(_PS_CAT_IMG_DIR_.'/'.$obj->id.'.' . $this->imageType, $this->table.'_'.(int)$obj->id.'.'.$this->imageType, 350, $this->imageType, true);
       $smallTile = ImageManager::thumbnail(_PS_CAT_IMG_DIR_.'/'.$obj->id.'-smallTile.' . $this->imageType, $this->table.'_'.(int)$obj->id.'.smallTile', 350, 'png', true);
       $bigBan = ImageManager::thumbnail(_PS_CAT_IMG_DIR_.'/'.$obj->id.'-bigBan.' . $this->imageType, $this->table.'_'.(int)$obj->id.'.bigBan', 350, 'png', true);

       $this->fields_value = array(
           'image' => $image ? $image : false,
           'size' => $image ? filesize(_PS_CAT_IMG_DIR_.'/'.$obj->id.'.' . $this->imageType) / 1000 : false,
           'smallTile' => $smallTile ? $smallTile : false,
           'bigBan' => $bigBan ? $bigBan : false
       );

Link to comment
Share on other sites

This is possible to do but you will need to change the default admin theme. (If anyone has a better/cleaner way of doing this please let me know)

 

The fille you need to change is admin/themes/default/template/helpers/form/form.tpl and you need to add in extra values for the image and size of each image field as follows

 

{if isset($input.image) && $input.image}
   <div id="image">
 {$input.image}
 <p align="center">{l s='File size'} {$input.size}kb</p>
 {if $shared_category}
  <p class="warn">{l s='If you delete this picture it\'s will be deleted for all shared shop'}</p>
 {/if}
 <br>
 <a href="{$current}&{$identifier}={$form_id}&token={$token}&{if $shared_category}forcedeleteImage=1{else}deleteImage=1{/if}">
  <img src="../img/admin/delete.gif" alt="{l s='Delete'}" /> {l s='Delete'}
 </a>
   </div><br />
  {elseif isset($fields_value.image) && $fields_value.image}
   <div id="image">
 {$fields_value.image}
 <p align="center">{l s='File size'} {$fields_value.size}kb</p>
 {if $shared_category}
  <p class="warn">{l s='If you delete this picture it\'s will be deleted for all shared shop'}</p>
 {/if}
 <br>
 <a href="{$current}&{$identifier}={$form_id}&token={$token}&{if $shared_category}forcedeleteImage=1{else}deleteImage=1{/if}">
  <img src="../img/admin/delete.gif" alt="{l s='Delete'}" /> {l s='Delete'}
 </a>
   </div><br />
  {/if}

 

Then you can add the fields to your form_fields array as follows

 

   array(
 'type' => 'file',
 'label' => $this->l('Product Type Image:'),
 'name' => 'image',
 'display_image' => true,
 'image' => $image ? $image : false,
 'size' => $image ? filesize(_PS_CAT_IMG_DIR_.'/'.$obj->id.'.' . $this->imageType) / 1000 : false,
 'desc' => $this->l('Upload category type image ()')
   ),

Link to comment
Share on other sites

×
×
  • Create New...