Bug #79711

The CE File Links (fluid_styled_content) tries to create thumbs for non-image files

Added by Marco Huber over 2 years ago. Updated 12 months ago.

Status:
Closed
Priority:
Must have
Category:
Fluid Styled Content
Target version:
-
Start date:
2017-02-09
Due date:
% Done:

100%

TYPO3 Version:
7
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:
On Location Sprint

Description

In typo3/sysext/fluid_styled_content/Resources/Private/Templates/Uploads.html line 13 the if condition is true even for non-image files, because the f:uri.image returns an url. But then the f:media viewhelper can't handle this files and returns an <img> tag with an invalid src.

To reproduce:
Insert the content element File Links on a page, assign some non-image files (docx, xlsx, ...) and select "Filename and thumbnail (if possible)" in the field "Display file/icon/thumbnail".
For this files the generated <img> tag looks like this: <img src="path/to/my.docx" />

As a quick workaround I wrote a little viewhelper to check, if the file extension is in $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], and used this viewhelper in the if condition:

<?php
namespace Vendor\MyTheme\ViewHelpers;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;

/**
 * Checks if the file extension is in $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
 */
class IsImageViewHelper extends AbstractViewHelper
{

    /**
     * Checks if the file extension is in $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
     *
     * @param \TYPO3\CMS\Core\Resource\ResourceInterface $resource Either give this resource
     * @return boolean
     */
    public function render($resource)
    {
        return GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $resource->getExtension());
    }
}
<f:if condition="{data.uploads_type} == 2">
    <f:if condition="{vendor:isImage(resource:file)}">
        <f:then>
            <a href="{file.publicUrl}"{f:if(condition:data.target,then:' target="{data.target}"')}>
                <f:media file="{file}" width="150" alt="{file.properties.alternative}" />
            </a>
        </f:then>

But perhaps there is a better solution?

MediaRenderingIfFileTypeBiggerThan1.png View - If i use <f:if condition="{file.type} > 1"> (374 KB) Jonathan IROULIN, 2017-11-29 13:16

MediaRenderingIfFileTypeRestrictedToImages.png View - If i use <f:if condition="{file.type} == 2"> (237 KB) Jonathan IROULIN, 2017-11-29 13:17


Related issues

Related to TYPO3 Core - Bug #75552: wrong rendering of video and audio and text files in file links with thumbnail Closed 2016-04-12

Associated revisions

Revision 9a49dd44 (diff)
Added by Jonathan IROULIN almost 2 years ago

[BUGFIX] The CE File Links (fluid_styled_content) create thumbs for non-image files

This patch resolves problems with usage of {file.type} to determine
if the file type is "unknown" ({file.type =} = 0)
or "text" type ({file.type =} = 1)

Resolves: #79711
Releases: master
Change-Id: I05615b7f10bc5125705e952147696d4e402dd900
Reviewed-on: https://review.typo3.org/54856
Tested-by: TYPO3com <>
Reviewed-by: Joerg Boesche <>
Reviewed-by: Benni Mack <>
Tested-by: Benni Mack <>
Reviewed-by: Susanne Moog <>
Tested-by: Susanne Moog <>

History

#1 Updated by Marco Huber over 2 years ago

  • Category set to Fluid Styled Content

#2 Updated by Frans Saris over 2 years ago

  • Status changed from New to Needs Feedback

Hi Marco,

you can use the {file.type} for this. See AbstractFile for the available types.

Groet Frans

#3 Updated by Riccardo De Contardi over 2 years ago

Is this issue a duplicate of #75552 ?

#4 Updated by Mona Muzaffar about 2 years ago

adding the comment of Riccardo on #75552 here. (closed #75552 as a duplicate)

Riccardo De Contardi wrote:

The problem with the txt file is still present;

Steps to reproduce:

1) create a "filelinks" content element
2) add a .txt file
3) select "Display file/icon/thumbnail > display file name and thumbnail (if possible)"

Result: as "thumbnail" you will obtain

[...]

It is possible to avoid the generation of the thumbnail by selecting "Display file/icon/thumbnail > only fi

#5 Updated by Alexander Opitz almost 2 years ago

  • Status changed from Needs Feedback to New

#6 Updated by Benni Mack almost 2 years ago

  • Sprint Focus set to On Location Sprint

#7 Updated by Jonathan IROULIN almost 2 years ago

  • Assignee set to Jonathan IROULIN

#8 Updated by Gerrit Code Review almost 2 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/54856

#9 Updated by Jonathan IROULIN almost 2 years ago

If i make it more strict (<f:if condition="{file.type} == 2"> instead of <f:if condition="{file.type} > 1">) we could only allow image processing on image files. But we loose the video and sound player as shown on my two screenshot.

#10 Updated by Gerrit Code Review almost 2 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/54856

#11 Updated by Gerrit Code Review almost 2 years ago

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/54872

#12 Updated by Jonathan IROULIN almost 2 years ago

Gerrit Code Review wrote:

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/54872

I made a mistake in number of the ISSUE_NUMBER...

#13 Updated by Jonathan IROULIN almost 2 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

#14 Updated by Benni Mack 12 months ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF