TYPO3 Mask: language labels - typo3

I try to translate some labels in a mask content element (TYPO3 10). I first created the mask element and mask created a directory "typo3conf/ext/mask_project". I created the file "typo3conf/ext/mask_project/Resources/Private/Language/locallang.xlf" and put a label "read_more" in there.
In my FLUID template ("typo3conf/ext/mask_project/Resources/Private/Mask/Frontend/Templates/Staff.html") I tried:
<f:translate key="EXT:mask_project/Resources/Private/Language/locallang.xlf:read_more" />
<f:translate key="LLL:EXT:mask_project/Resources/Private/Language/locallang.xlf:read_more" />
Unfortunately nothing is printed out. Does anyone has an idea?

The LLL:EXT:...:... syntax is correct (https://docs.typo3.org/other/typo3/view-helper-reference/10.4/en-us/typo3/fluid/latest/Translate.html) for accessing full paths. For the default file location, you would usually not have to add the whole path (this depends a bit on the FLUIDTEMPLATE configuration). In your case you can also use the ViewHelpers extensionName= parameter.
Some hints if you still get no output:
For new labels to be known, you'll need to clear the system cache.
https://docs.typo3.org/m/typo3/reference-coreapi/10.4/en-us/ApiOverview/Internationalization/XliffApi.html
https://docs.typo3.org/m/typo3/book-extbasefluid/master/en-us/9-CrosscuttingConcerns/1-localizing-and-internationalizing-an-extension.html

Related

How to have multiple sections with images in a FluidTYPO3 flux form with TYPO3 10?

I have been using FluidTYPO3 (flux and vhs) to run TYPO3 web pages for many years now. With TYPO3 10, I face a major problem. I'll quickly write about my use case, how I solved it so far, and then what the problem with 10 LTS is.
Use case:
I want to have a content element template for a timeline using FluidTYPO3/flux. Each "point" on the timeline should have a heading, some text, and optionally some images. All in all, pretty basic (or so I thought).
Solution so far (TYPO3 <= 9):
Timeline elements are sections. Images are using flux:field.file.
Simplified example of the form:
<flux:form id="timeline" label="timeline">
<flux:form.section name="timeline" label="Timeline">
<flux:form.object name="element" label="Element">
<flux:field.input name="title" label="Heading" />
<flux:field.text name="label" label="Text" enableRichText="TRUE" />
<flux:field.file name="images" label="Pictures" allowed="jpg,png,svg" multiple="TRUE" maxItems="50" size="5" showThumbnails="TRUE"
/>
</flux:form.object>
</flux:form.section>
</flux:form>
With this, multiple elements can be created on the timeline and each of them can have its own set of images.
Problem in TYPO3 10:
The technology (TCA group fields to select files) that flux:field.file relies on was deprecated in TYPO3 9 and removed in TYPO3 10, see this notice. That is one of the reasons why flux:field.file was also marked deprecated and is going to be removed in TYPO3 10.
The TYPO3 deprecation notice says to use FAL relations instead. Of course, flux can also do this with flux:field.inline.fal. However, you can only have one FAL field per FlexForm. This precludes its usage in sections, since all sections would share the same images. This limitation is known for some time - see this bug report for example - but has never been fixed. It is also why I initially chose not to use FAL fields. Using bare file fields was the recommended workaround at the time.
Question:
So - how is everyone doing it? How to add multiple image fields to a flexform in TYPO3 10?
EDIT: More specifically, how to add an image field as part of a Flexform section that can contain multiple child records (resulting in multiple image fields)?
Note: I know that I can get a "file-like" field back by using an input field with inputLink renderType (like this), but as far as I can tell it does not allow to link multiple images.
I've found another workaround that might be appropriate for some use cases:
It is still possible to use flux:field.file fields if the useFalRelation parameter set to true, even on TYPO3 v10 LTS and in repeatable FlexForm sections. This will then put sys_file record IDs separated by comma into the field instead of raw filenames. They can be used as src argument for, e.g., f:image just as well as the filename, so the CE templates itself do not have to be modified. All existing CEs that had useFalRelation set to false need to be migrated though so that the filenames are replaced with sys_file UIDs.
This is a bit better than the inputLink workaround since it allows multiple images.
It seems the only workaround with TYPO3 core onboard methods is to go for a Flux-Container having a single column containing simple default "Text with image" or "text with media" elements and then to just ignore additional options of those elements and to just render the necessary fields.
With Gridelements this is called a "functional container", since the container determines the behaviour and appearance of those elements, while the elements themselves don't have to be custom elements at all.
Additionally this makes access to the content of those elements - i.e. while doing a search query - much easier.
The bug report you mentioned already contains the solutions, since the actual problem described there is that FAL fields in a flexform are using the same name.
So instead of
image
according to the bug report there should be
settings.foreground.image
which is of course not working, since the dot is part of the path but not of the name.
But actually replacing the dot with an underscore and using some suffixes within the same flexform tab should do the trick:
settings.foreground.settings_foreground_image
settings.foreground.settings_foreground_image2
This way you make sure that
The field names within your flexform are unique
The actual field name within the sys_file_reference entry already contains the full path information
You can use that information to fetch images i.e. within a DataProcessor and still know the FlexForm field they actually belong to
Sitll I would recommend to fully move away form FlexForms (and thus Flux too) in favor of "real" fields in the database table.
If you currently use the flux:field.file element at typo3 10 with the useFalRelation=1 you can replace it by the flux:field element. It is not deprecated and works in combination with the flux:form.object element
Following example:
<flux:field.file
allowed="jpg,png,svg,gif"
exclude="false"
label="MyLabel"
name="myname"
showThumbnails="1"
useFalRelation="1"
maxItems="1"
minItems="1"
/>
Can be replaced with:
<flux:field type="input" name="myname" label="MyLabel"
config="{
type: 'group',
size: 1,
internal_type: 'db',
use_fal_relation: 1,
allowed: 'sys_file',
maxitems: 1,
minitems: 0,
show_thumbs: 1,
appearance: {
elementBrowserAllowed: 'jpg,png,svg,gif',
elementBrowserType: 'file'
}
}
"/>

Typo3 change how objects are rendered (typo3 beginner)

I'm fairly new to typo3 and I have an issue that i don't find an explanation on how to change it. I'm sure there are already some helpful tutorials but i have issues finding them.
I am making a website and I have already made a template for fontend and backend.
It is a very simple test template that consists only of one slider and one text element.
The slider is handmade and should have the following layout:
<section class="custom-slider">
<img src="img1.jpg">
<img src="img2.jpg">
...
</section>
Thought easy, i have my slider place in my template, just need to add plain images.
but typo3 gives me:
<section class="custom-slider">
<div id="c3" class="frame frame-default frame-type-image frame-layout-0"><header><h2 class=""></h2></header><div class="ce-image ce-center ce-above"><div class="ce-gallery" data-ce-columns="1" data-ce-images="1"><div class="ce-outer"><div class="ce-inner"><div class="ce-row"><div class="ce-column"><figure class="image"><img class="image-embed-item" src="fileadmin/_processed_/1/2/csm_slider1_c3fdcdcaf5.jpg" width="600" height="187" alt="" /></figure></div></div></div></div></div></div></div>
</section>
Now i search how i can make my own custom elements or render existing elements different. I have found a lot of tutorials but they all are based on 'Extension Builder' or 'Builder' and require a custom extention. These don't seem to work on Typo3 8.7.x. Is there a different solution or can someone give me a good tutorial link?
Thank you in advanst:)
Ps: since i will have the same problem with styled text elements i would like to ask if there is a way to declare in the themplate how different predeterment elements are rendered?
In TYPO3 8.7 (I assume) your rendering is done with FSC (fluid_styled_content), so you have to understand the mechanism of FSC to render a CE (ContentElement).
As the name suggests Fluid is used. Fluid uses different templates organized in three categories (each with it's own folder):
Layouts
Templates
Partials
The call goes to a template (in the folder 'templates') where a tag can be inserted to use a specific layout (from floder 'Layouts'). if this tag is given the rendering starts with the given layout. In the layout different sections and partials can be called. Sections belong to the template, partials need to have an own partial file (in folder 'Partials').
You can override single files from the given declaration to individulize the behaviour.
In your example you may evaluate the field layout in layout, template and partial to avoid the default wrapping of any content (your images) in different div tags.

Crop image in Fluid Template with image viewhelper

I want to crop images in Fluid with the f:image or the f:uri.image viewhelper (TYPO3 8.7). Since TYPO3 7.2 the usual way does not work anymore:
This:
<f:image image="{file}" width="500c" height="500" />
does not work.
In the fluid guide I found the hint that since TYPO3 7.2 I have to use crop. I found this in the change log:
https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Feature-65584-AddImageCropping.html
So this should work, but it doesnt:
<f:image image="{file}" crop="0,0,500,500" />
The images are rendered but in default size.
Any ideas? Anything changed in later versions?
I tried with a fresh installation and found my fault.
cropping with c and m does indeed work in TYPO3 8 - the hint in the fluid manual is wrong.
in short syntax you have to use '' in order to send the c or m correct.
This syntax is wrong:
<img src="{f:uri.image(image:file, width:200c, height:200)}">
there is no error message and the images are rendered but the letter c is ignored. You have to use this syntax:
<img src="{f:uri.image(image:file, width:'200c', height:'200')}">
this will work.
One additional hint: after changing the syntax the images are not rendered every time but only when the size has changed. Sometimes you get simply the cached images ... Deleting the content on /fileadmin/_temp does help.
Well - perhaps it will help some one :-)
You can use f:image like below. it's work for me.
<f:image src="{file.originalResource.publicUrl}" width="770c" height="517c" height="350c" />
You could also specify the crop settings in tca and use this settings in the FE, for an example look at the repository : https://github.com/frans-beech-it/t3ext-config_examples.
Besides that, in the install tool you can check if cropping works on your machine. It can happen that there are already processed images for your size, if you adjust the cropping information of image with 1px a new processed image is created. If then the image works, clear the processed files to generate a new image for your desired formats.

In a fluid template, how to output the linked file's size?

In a fluid template, I would like to output a linked file's size.
I'm using f:link.page to link to the file, as I think this is the way to do it (please correct if not).
<f:link.page class="download" pageUid="fileadmin/redaktion/download/papers/{paper.download}" {paper.author}">PDF</f:link.page>
As I'm already using the extension ml_links on the site, I thought I could pass the link through lib.parseFunc_RTE, but
<f:format.html parseFuncTSPath="lib.parseFunc_RTE"><f:link.page class="download" pageUid="fileadmin/redaktion/download/papers/{paper.download}" {paper.author}">PDF</f:link.page></f:format.html>
just wraps it into p.bodytext.
Do I have to use a different syntax to apply f:format.html TO f:link.page - or is there a better way to do it (via a fluid or vhs viewhelper)?
Actually custom VH is fastest way to achieve that, i.e. basing on this VH, you'll need to replace size param with a file path, and then use i.e. filesize function of PHP to fetch the size in bytes.
Here's my VH:
https://gist.github.com/ursbraem/9645542
I've simplified the original a little, outputting "KiB" for file size is too technical for me.
The easiest way is to use native TYPO3 FAL parameter originalFile.size :
{audio.0.originalFile.size -> f:format.bytes()}
When i use fluidcontent i have vhs extension installed aswell and then just use:
<f:format.bytes decimals="1">{v:media.size(path: '{file}')}</f:format.bytes>
This outputs clean readable sizes like "28.2 MB".
If you are using VHS you may consider https://fluidtypo3.org/viewhelpers/vhs/master/Media/SizeViewHelper.html (in combination with f:format.bytes).
In newer TYPO3 versions you can use the originalResource.size attribute of a FileReference object.
{file.originalResource.size -> f:format.bytes()}
or in your case:
{paper.download.originalResource.size -> f:format.bytes()}
TYPO3 10
I needed a file size output for a DCE module in TYPO3 10, this is what I came up with, using VHS:
<f:format.bytes><v:media.size><v:format.trim characters="/"><f:uri.typolink parameter="{item.link}" /></v:format.trim></v:media.size></f:format.bytes>
Explained:
f:uri.typolink generates the full path I need for v:media.size
v:media.size requires the path without a leading slash, v:format.trim removes this character.
f:format.bytes displays the output from v:media.size in KB or MB.

TYPO3: get path out of file reference in Extbase

i've created a Custom Content Element with Fluid and Extbase (TYPO3 6.1), in which you can define a picture.
In the picture-settings i can set a img-link, which is targetting a file.
In my Controller i can access this data with
$this->configurationManager->getContentObject();
But i just get a file-reference for this setting and no path. like this:
file:1206
I've googled a lot and i didn't find a solution to access the path. Has anybody a solution or knows maybe a function in the configurationmanager or something else? I've spend hours on this problem...
Thanks a lot!
If you need to get image from FAL than use following image view helper
<f:image src="{object.image_field.uid}" alt="{object.image_field.originalResource.title}" width="640" height="291" treatIdAsReference="1" />
If you just need url of image than use following line
{object.image.originalResource.publicUrl}..
Hurray.
What you have there, is a file reference of FAL, the file abstraction layer.
First things first, if you use FlexForms in combination with ActionController (or any realisation of AbstractController) you should be able to access the settings property to compute your FlexForm values.
To compute sys_file_reference records, you should refer to the FAL docs on typo3.org (and the perma-linked section about file and folder handling).
In general, you should be able to call getOriginalResource() on a \TYPO3\CMS\Extbase\Domain\Model\FileReference object. For more concrete examples, either refer to the doc links or have a look at the wiki for a example handling FileReferences.
If you want to compute such reference via fluid templating, you can use the treatIdAsReference argument on f:image:
<f:image src="{imageObj.uid}" width="150" height="100" treatIdAsReference="1" />
He is asking for a path and not for an image. This prints the path in fluid templates:
{f:uri.image(src:'{object.uid}',treatIdAsReference:'1')}