Skip to content

Commit

Permalink
setting up raw values for image and file fields
Browse files Browse the repository at this point in the history
  • Loading branch information
janhartigan committed Jan 23, 2015
1 parent e302f0c commit 83c939f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Changelog

- It's now possible to use the raw value of a file/image field to help with storing files on remote servers.

### 4.15.0
- New uneditable states for color, password, enum, and wysiwyg fields for when the editable option resolves to false
- New translations (sk)
Expand Down
3 changes: 3 additions & 0 deletions docs/field-type-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The `file` field type should be a text-like type in your database. The file's na
'naming' => 'random',
'length' => 20,
'size_limit' => 2,
'display_raw_value' => false,
'mimes' => 'pdf,psd,doc',
)

Expand All @@ -29,4 +30,6 @@ The optional `length` option lets you define size of file name in case `random`

The optional `size_limit` option lets you set an integer size limit counted in megabytes. This only affects the JavaScript file uploading dialog, it doesn't limit your PHP upload sizes (which you can do in your php.ini).

The optional `display_raw_value` option lets you put the raw value of the saved file source string into the displayed file link. This is useful if you're using accessors, mutators, and [`setter fields`](/docs/fields#setter-option) to skip storing the file on your local server and instead upload it to a remote public file server.

The optional `mimes` option by default allows all file types. This uses Laravel's [mimes validation](http://laravel.com/docs/validation#rule-mimes), which in turn uses the PHP Fileinfo extension to read the contents of the file and determine the actual MIME type.
3 changes: 3 additions & 0 deletions docs/field-type-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The `image` field type should be a text-like type in your database. The image's
'naming' => 'random',
'length' => 20,
'size_limit' => 2,
'display_raw_value' => false,
'sizes' => array(
array(65, 57, 'crop', public_path() . '/uploads/products/thumbs/small/', 100),
array(220, 138, 'landscape', public_path() . '/uploads/products/thumbs/medium/', 100),
Expand All @@ -33,4 +34,6 @@ The optional `length` option lets you define size of file name in case `random`

The optional `size_limit` option lets you set an integer size limit counted in megabytes. This only affects the JavaScript file uploading dialog, it doesn't limit your PHP upload sizes.

The optional `display_raw_value` option lets you put the raw value of the saved image source string into the image input. This is useful if you're using accessors, mutators, and [`setter fields`](/docs/fields#setter-option) to skip storing the image on your local server and instead upload it to a remote public image server.

The optional `sizes` option lets you define as many resizes as you want. The format for these is: `array([width], [height], [method], [save path], [quality])`. The different methods are `exact`, `portrait`, `landscape`, `fit`, `auto`, and `crop`.
1 change: 1 addition & 0 deletions src/Frozennode/Administrator/Fields/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class File extends Field {
'length' => 32,
'mimes' => false,
'size_limit' => 2,
'display_raw_value' => false,
);

/**
Expand Down
16 changes: 14 additions & 2 deletions src/views/templates/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,13 @@
<!-- /ko -->
<!-- ko if: $root[field_name]() && !$root.loadingItem() -->
<div class="image_container">
<img data-bind="attr: {src: file_url + '?path=' + location + $root[field_name]()}" onload="window.admin.resizePage()" />
<!-- ko if: display_raw_value -->
<img data-bind="attr: {src: $root[field_name]()}" onload="window.admin.resizePage()" />
<!-- /ko -->
<!-- ko ifnot: display_raw_value -->
<img data-bind="attr: {src: file_url + '?path=' + location + $root[field_name]()}" onload="window.admin.resizePage()" />
<!-- /ko -->

<!-- ko if: editable -->
<input type="button" class="remove_button" data-bind="click: function() {$root[field_name](null)}" value="x" />
<!-- /ko -->
Expand All @@ -221,8 +227,14 @@
<!-- /ko -->
<!-- ko if: $root[field_name] -->
<div class="file_container">
<a data-bind="attr: {href: file_url + '?path=' + location + $root[field_name](), title: $root[field_name]},
<!-- ko if: display_raw_value -->
<a data-bind="attr: {href: $root[field_name](), title: $root[field_name]}, text: $root[field_name]"></a>
<!-- /ko -->
<!-- ko ifnot: display_raw_value -->
<a data-bind="attr: {href: file_url + '?path=' + location + $root[field_name](), title: $root[field_name]},
text: $root[field_name]"></a>
<!-- /ko -->

<!-- ko if: editable -->
<input type="button" class="remove_button" data-bind="click: function() {$root[field_name](null)}" value="x" />
<!-- /ko -->
Expand Down

0 comments on commit 83c939f

Please sign in to comment.