The file field in combination with the file_entity module and the file type specific view modes in D8 are the new way to go with files in general for the future. So the quote of some top contributors of D8 to this issue. That was one of the reasons why the file_entity module has been separated from the Media project. To fully be able to use this way in combination with views or other rendering logic, we need the same option to get the URL of a certain file type > image > view-mode > image style as a clear output to prevent users applying logic on the wrong places (like themes).

From the original issue OT:
I was surprised to see that it didn't have support for Media file types (this is not Media module specific) the file field of type image formatting in view modes. More specifically, the general file field (which happen to upload image file types)

In the forthcoming patch, you'll see that I added field formatter support for the general "file" field type. That alone does the trick, but URLs that request image style processing (on non-image files) totally fails. So I added a condition to using the image style processing URL to only apply to file types of "image". This has worked out smashingly for my use-case. I hope it's helpful for others as well.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

helior’s picture

Status: Active » Needs review
StatusFileSize
new1.2 KB
g089h515r806’s picture

Status: Needs review » Fixed

commited.

ahlofan’s picture

I found that image style is not working,
Line 213 in the module file:
if ($variables['image_style'] && ($variables['item']['type'] == 'image' || $variables['item']['type'] == 'imagefield_crop')) {

$variables['item']['type'] actually doesn't exist.

g089h515r806’s picture

Status: Fixed » Active

I have not test it. I will test it tomorrow.

g089h515r806’s picture

Version: 7.x-1.x-dev » 7.x-1.3
Category: feature » bug

Another developer also report this issue.

g089h515r806’s picture

revert this patch.

Maybe this code :
$variables['item']['type'] == 'image'
only works with Media module. Image module does not have it.

ahlofan’s picture

probably need to have some module detection? I temporary patched your module, should I use your dev version for now?

corbacho’s picture

Issue summary: View changes
StatusFileSize
new1.37 KB

I'm using this patch to be able to use URI format for files. I reordered the code a bit to avoid 'undefined' warnings

pcambra’s picture

Status: Active » Needs review
dqd’s picture

I know at least from 3 project maintainers here who would love to see this in 7 and 8. Under admin/structure/file-types/manage/image/edit/display you can choose file format "File image" which gives you a choice for a certain image style to use in this file view mode, but sadly there is no chance to get the image style url only to the regarding image to the choosen style. This is useful for custom views view settings and has been solved for the image field but not for the file field > type image sadly.

dqd’s picture

Title: Support for Media file types » Support for the file field of type "image" and its view modes and formatters
Version: 7.x-1.3 » 8.x-1.x-dev
Issue summary: View changes
Status: Needs review » Needs work

Maybe we have a chance on D8 now?

astonvictor made their first commit to this issue’s fork.

astonvictor’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
astonvictor’s picture

Status: Needs work » Needs review

Hi there,

Created a similar field formatter for file types.

astonvictor’s picture

Status: Needs review » Fixed

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.