Crop variants for tt_content image - typo3

I tried the first time the new image manipulation feature in TYPO3 and stumbled upon some problems. I am using TYPO3 8.7.16. The image processing is working correctly (tested in install tool using ImageMagick).
For testing purposes I overrided the TCA of tt_content:
$GLOBALS['TCA']['tt_content']['columns']['image']['config'] ['overrideChildTca']['columns']['crop'] = [
'config' => [
'cropVariants' => [
'desktop' => [
'title' => 'Desktop',
'selectedRatio' => '4:3',
'allowedAspectRatios' => [
'4:3' => [
'title' => '4:3',
'value' => 4 / 3,
],
],
],
'tablet' => [
'title' => 'Tablet',
'selectedRatio' => '16:9',
'allowedAspectRatios' => [
'16:9' => [
'title' => '16:9',
'value' => 16 / 9,
],
],
],
'mobile' => [
'title' => 'Mobile',
'selectedRatio' => '2:3',
'allowedAspectRatios' => [
'16:9' => [
'title' => '2:3',
'value' => 2 / 3,
],
],
],
],
],
];
When I use the editor for image manipulation I can crop the different formats and after accepting the manipulation I see the cropped images as preview in the content element:
After saving the content element I see the following (the cropped images are not shown anymore):
Is this a bug? But that doesn't bother me much for now.
Now I tried to show e.g. the cropped desktop image in frontend. I copied the Media/Rendering/Image.html partial and changed the content to:
<f:image image="{file}" cropVariant="desktop" width="480" alt="{file.alternative}" title="{file.title}" />
I thought that is enough to show the cropped image, but it was not. I see the original file. When I debugged the file reference I see, that the configuration for the cropped images are stored correctly in sys_file_reference:
Now I have no clue what to do to get the cropped images in frontend.
Any ideas?
Edit: Now I found the problem, I had some issues with ImageMagick, so that the cropped images cannot be created.

i would recommend you to look at the article from Clickstorm
Clickstorm CropVariant Images
You can easily access the cropVariants with srcset.
<f:if condition="{files}">
<f:image src="{image.id}" treadIdAsReference="1" srcset="{f:uri.image(image:image.id,width:'2500',height:'816',cropVariant:'desktop')}" alt="{files.0.alternative}" />
</f:if>
Maybe you use the Picture Element like this:
<picture>
<source media="(min-width: 1400px)" srcset="{f:uri.image(src:'{image.uid}',treatIdAsReference:'1',width:'1400',cropVariant:'default')}">
<source media="(max-width: 1399px) and (min-width:1025px)" srcset="{f:uri.image(src:'{image.uid}',treatIdAsReference:'1',cropVariant:'default-md')}">
<source media="(max-width: 1024px) and (orientation:portrait)" srcset="{f:uri.image(src:'{image.uid}',treatIdAsReference:'1',width:'768',cropVariant:'tablet-portrait')}">
<source media="(max-width: 1024px) and (orientation:landscape)" srcset="{f:uri.image(src:'{image.uid}',treatIdAsReference:'1',width:'768',cropVariant:'tablet-landscape')}">
<source media="(max-width: 667px) and (orientation:portrait)" srcset="{f:uri.image(src:'{image.uid}',treatIdAsReference:'1',width:'667',cropVariant:'smartphone-portrait')}">
<source media="(max-width: 667px) and (orientation:landscape)" srcset="{f:uri.image(src:'{image.uid}',treatIdAsReference:'1',width:'667',cropVariant:'smartphone-landscape')}">
<img src="{f:uri.image(crop: image.crop, src: image.id, cropVariant:'default')}"title="{image.title}" alt="{image.alternative}" />
</picture>
I hope that help you in getting started for the Frontend part.

Related

How to output og:image (sysext:seo) without cropping or processing?

If you store an Open Graph Image in the page properties, it will automatically be cropped to a ratio of 1.91 / 1 and even if you upload an image in exactly these proportions, it will still be reprocessed (and slightly trimmed).
I have already managed to get the cropping tool to accept a free ratio as the default:
/ext/sitepackage/Configuration/TCA/Overrides/pages.php
<?php
defined('TYPO3') or die();
$GLOBALS['TCA']['pages']['columns']['og_image']['config']['overrideChildTca']['columns']['crop']['config'] = [
'cropVariants' => [
'social' => [
'title' => 'Social media',
'cropArea' => [
'x' => '0.0',
'y' => '0.0',
'width' => '1.0',
'height' => '1.0'
],
'allowedAspectRatios' => [
'NaN' => [
'title' => 'Free',
'value' => 0.0
],
],
],
],
];
This creates the following entry in the database (sys_file_reference , column crop):
{"social":{"cropArea":{"x":0,"y":0,"width":1,"height":1},"selectedRatio":"NaN","focusArea":null}}
That looks fine to me.
Still, TYPO3 does not output my already optimized original image (fileadmin/media/1200x630.png) but one generated by the image processor (/fileadmin/processed/7/a/csm_….png , same pixel dimensions as the original). I have also manually removed the crop entry from the database as a test and still the URL of the original image is not output.
How can I prevent this?
Addendum: I created a bug report
The social images (open graph and twitter) are always processed. see https://github.com/TYPO3/typo3/blob/main/typo3/sysext/seo/Classes/MetaTag/MetaTagGenerator.php#L68.
You can create your own MetaTagManager for og:image, example is here: https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/MetaTagApi/Index.html#creating-your-own-metatagmanager.
Don't know if that's a good way as there are special rules regarding dimensions of open graph images, see https://simplified.co/blog/design-hacks/open-graph-image-everything-you-need-to-know/

TYPO3 TCA: Add CSS class selection to inputLink

I'm trying to add a CSS class selection in a TCA inputLink Field. I was able to create the selection in the RTE Editor and now I want to be able to select the same CSS classes in TCA link input fields.
Here is my current code:
'link' => [
'exclude' => 1,
'label' => 'foo label',
'config' => [
'type' => 'input',
'renderType' => 'inputLink',
'size' => 50,
'max' => 1024,
'eval' => 'trim',
'fieldControl' => [
'linkPopup' => [
'options' => [
'title' => 'foo title',
'class' => [
'valuePicker' => [
'mode' => 'blank',
'items' => [
['button', 'Button Style'],
],
],
],
],
],
],
'softref' => 'typolink',
],
],
I couldn't find anything in the TCA Docs. I thought I would give it a try with the LinkPopup --> options --> class. But (as expected) nothing happens.
How am I able to define such a selection dropdown in the link input field?
I'm using TYPO3 LTS 11.
Not sure if you have configured, what you are describing...
A valuePicker can be placed next to an input field of RenderTypes default, colorpicker, inputLink (-> TCAref). The class field in the linkPopup is a simple (hardcoded) form field without a defined renderType or other TCA configuration (Code insight).
There are only a few options for configuring a linkpopup (-> TCAref):
pid
allowedExtensions
blindLinkFields
blindLinkOptions
Setting a prefilled (not selectable) class seems to be possible via TCAMAIN.linkHandler-options (-> LinkBrowser-API). I found an example in an issue of EXT:bootstrap_package.

How to add custom wizards in TYPO3 9 TCA?

Related to How to add custom wizards in typo3 7 TCA? how can costum wizards in TYPO3 9 be implemented? I've added my entry to the Routes.php
return [
'tx_csseo_preview' => [
'path' => '/wizard/tx_csseo/preview',
'target' => \Clickstorm\CsSeo\UserFunc\PreviewWizard::class . '::render'
],
'tx_csseo_permalink' => [
'path' => '/wizard/tx_csseo/permalink',
'target' => \Clickstorm\CsSeo\UserFunc\PermalinkWizard::class . '::render'
]
];
How can I add them now to my TCA field?
'tx_csseo_title' => [
'label' => 'LLL:EXT:cs_seo/Resources/Private/Language/locallang_db.xlf:pages.tx_csseo_title',
'exclude' => 1,
'config' => [
'type' => 'input',
'max' => $extConf['maxTitle'],
'eval' => 'trim',
'fieldWizard' => [
'tx_csseo_preview' => [
'disabled' => false,
]
]
]
],
This does not work. What do I miss? Thanks in advance.
Related to your kind of wizard the registration-process is different and extensive explained here. You can leave the entries in Routes.php away (perhaps even the whole file if nothing else is inside).
Registration is done in ext_localconf.php:
$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][1485351217] = [
'nodeName' => 'importDataControl',
'priority' => 30,
'class' => \T3G\Something\FormEngine\FieldControl\ImportDataControl::class
];
Then reference the new wizard in TCA:
'somefield' => [
'label' => $langFile . ':pages.somefield',
'config' => [
'type' => 'input',
'eval' => 'int, unique',
'fieldControl' => [
'importControl' => [
'renderType' => 'importDataControl'
]
]
]
],
Then finally the class with the "magic"
declare(strict_types=1);
namespace T3G\Something\FormEngine\FieldControl;
use TYPO3\CMS\Backend\Form\AbstractNode;
class ImportDataControl extends AbstractNode
{
public function render()
{
$result = [
'iconIdentifier' => 'import-data',
'title' => $GLOBALS['LANG']->sL('LLL:EXT:something/Resources/Private/Language/locallang_db.xlf:pages.importData'),
'linkAttributes' => [
'class' => 'importData ',
'data-id' => $this->data['databaseRow']['somefield']
],
'requireJsModules' => ['TYPO3/CMS/Something/ImportData'],
];
return $result;
}
}
In the linked example there is still an Ajax Route with corresponding files, including a special defined route, but that's not required to get the basic wizard shown.
Concerning the registration in ext_localconf.php there is above the number 1485351217 as array-key shown. For an own registered node just calculate once the current time as unix-timestamp and enter that instead. So it's unique and can't be mistaken with other definitions of any registered nodes.
In contrast to the linked example I used slightly different descriptions, so I call the process in ext_localconf.php registering, and the inclusion in TCA referencing. Perhaps this small difference makes it a bit more clear.
Icons
Concerning Icons there is still a difference to earlier TYPO3 versions, they have to be registered now too and in TCA they are only referenced too by the registered name. Here in the TCA-file is no icon referenced but the class below makes usage of it. Here is an example how an icon has to be registered in ext_tables.php:
$systemIconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class);
$systemIconRegistry->registerIcon(
'imagemapwizard_link_edit',
\TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider::class,
[
'source' => 'EXT:imagemap_wizard/Resources/Public/Icons/link_edit.png'
]
);
The new icon registry is implemented starting with TYPO3 version 7.5
Don't forget the configuration in YourExtension/Configuration/Backend/AjaxRoutes.php. See the documentation

TYPO3 - Accessing detail page of record via url GET parameter

I developed an extbase extension with list and detail view (list and show action). Without using realurl ... the link of a detail view looks like this:
domain/index.php?id=43&/?tx_abc_abc[record]=1&tx_abc_abc[action]=show&tx_abc_abc[controller]=Abc
And when I change the record id in the url I can dynamically change the content on the detail page and access the record:
domain/index.php?id=43&/?tx_abc_abc[record]=2&tx_abc_abc[action]=show&tx_abc_abc[controller]=Abc
domain/index.php?id=43&/?tx_abc_abc[record]=3&tx_abc_abc[action]=show&tx_abc_abc[controller]=Abc
domain/index.php?id=43&/?tx_abc_abc[record]=4&tx_abc_abc[action]=show&tx_abc_abc[controller]=Abc
The final goal is having a url looking like this and access the record via the GET parameter in the url:
domain/abc/?abc=1
domain/abc/?abc=2
domain/abc/?abc=3
domain/abc/?abc=4
But when activating realurl ... I cannot directly access the record if its not available in tx_realurl_urldata. Or how should the realurl setup look like?
What's the best solution for this? I have too many records (plus 2 languages) for the links to be written and always available in tx_realurl_urldata.
So my thought was to deactivate realurl for this specific extension? But how?
Or I thought to exclude the detail page in realurl_conf.php: 'excludePageIds' => 42,43 but that did not work.
I made a realurl configuration for my own extension for detail pages like this:
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'] = [
'www.domain.ch' => [
...
],
'fixedPostVars' => [
'extYourextensionDetailConfiguration' => [
[
'GETvar' => 'tx_yourextension_abc[action]',
'noMatch' => 'bypass',
],
[
'GETvar' => 'tx_yourtextension_abc[abc]',
'lookUpTable' => [
'table' => 'tx_yourextension_domain_model_abc',
'id_field' => 'uid',
'alias_field' => 'title',
'addWhereClause' => ' AND deleted=0 AND hidden=0',
'useUniqueCache' => true,
'useUniqueCache_conf' => [
'strtolower' => true,
'spaceCharacter' => '-',
],
'enable404forInvalidAlias' => true,
],
],
],
...,
'99' => 'extYourextensionDetailConfiguration',
...,
],
...,
],
];
Where
www.domain.ch is your domain
extYourextensionDetailConfiguration is a name to use later
alias_field is the content of the segment. can be ID if you want to switch between changing the URL handmade
99 is the ID of the page with the detail view

TYPO3 8.7.8 Custom content element with custom fields in backend

I've been searching for quite a while but couldn't find what I was looking for.
I've created two custom content-elements: parallax_content and bg_image.
In the backend for the time being I have the fields of a standard textmedia-element the code for which is as follows (from tt_content):
array('showitem' => '
--palette--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.general;
general,
--palette--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.header;
header,
rowDescription,
bodytext;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:bodytext_formlabel,
--div--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.media,
assets,
--palette--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.imagelinks;
imagelinks,
--div--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.appearance,
layout;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:layout_formlabel,
--palette--;
LLL:EXT:fluid_styled_content/Resources/Private/Language/Database.xlf:tt_content.palette.mediaAdjustments;mediaAdjustments,
--palette--;
LLL:EXT:fluid_styled_content/Resources/Private/Language/Database.xlf:tt_content.palette.gallerySettings;
gallerySettings,
--palette--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.appearanceLinks;appearanceLinks,
--div--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.access,
hidden;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:field.default.hidden,
--palette--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.access;
access,
--div--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.extended,
--div--;
LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category,
categories',
'columnsOverrides' => array(
'bodytext' => array(
'defaultExtras' => 'richtext:rte_transform[mode=ts_css]'
)
)
)
For my element parallax_content I would need the following fields:
Header
a checkbox "insert Logo"
a bodytext
an image selecting field
For image_bg I would need:
an image selecting field
a dropdown list with 2 items
But I'm struggling with understanding the code and how I would neet to adapt it so it would work. I've looked at the documentation but it doesn't really answer my question as it only shows one example of code with some lines but no explanation. I couldn't find the other documentation again where I gained just as "much" information as in the one linked above. I do understand some parts, for example the palette.header creates the whole header palette with header, header-link, alignment, date etc.
So my questions are:
Can someone explain to me how the code above works exaclty? Where does one element start and where does it end? what do "--palette--" and "--div--" do? how are the tabs created (e.g. general, media etc)? Is it possible to create my fields as listed above with these palettes? Can I create my own palette? If yes how? Or is there maybe a typoscript I can use/make to create my custom fields? Or would I need to create an extension for each of these elements? If possible I'd like to avoid this.
Yes, it's quite a lot of questions, I'm a novice in TYPO3 and not only trying to work with TYPO3 but also understand it as far as possible (at least for the things I need). My utmost priority is to understand the code above, but any pointers, explanations, help or even links to documentations (which I might not have seen so far) which could lead to a solution for my request I would greatly appreciate. Thanks in advance!
in my current project I added a parallax effect to the textmedia element in the tt_content.
First I override the tt_content TCA:
'background_media' => array(
'exclude' => 1,
'l10n_mode' => 'mergeIfNotBlank',
'label' => 'LLL:EXT:extension/Resources/Private/Language/locallang.xml:background_media',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'background_media',
array(
'minitems' => 0,
'maxitems' => 1,
'appearance' => array(
'createNewRelationLinkTitle' => 'LLL:EXT:extension/Resources/Private/Language/locallang.xml:add_media',
'showAllLocalizationLink' => 1,
),
'foreign_match_fields' => array(
'fieldname' => 'background_media',
'tablenames' => 'tt_content',
'table_local' => 'sys_file',
),
// custom configuration for displaying fields in the overlay/reference table
// to use the newsPalette and imageoverlayPalette instead of the basicoverlayPalette
'foreign_types' => array(
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => array(
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette,
--palette--;;imageoverlayPalette,
--palette--;;filePalette'
),
)
),
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
)
),
'effects' => [
'exclude' => true,
'label' => 'LLL:EXT:extension/Resources/Private/Language/locallang.xml:effects',
'config' => [
'type' => 'select',
'itemsProcFunc' => 'VENDOR\Extension\UserFunction\ProviderField->createEffectItems',
'renderType' => 'selectCheckBox',
'multiple' => true,
'minitems' => 0,
'maxitems' => 999,
'items' => []
]
],...
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tt_content', $additionalColumns);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('tt_content', 'background_media,effects', 'textmedia', 'after:layout');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('tt_content', 'image_classes,text_classes', 'textmedia', 'after:layout');
Now I have 2 additional fields:
- Background Image (FAL)
- Selct Box (UserFunc) for own styles
My UserFunc (VENDOR\Extension\UserFunction\ProviderField->createEffectItems)
/**
* #param ConfigurationService $configurationService
* #return void
*/
public function injectConfigurationService(ConfigurationService $configurationService) {
$this->configurationService = $configurationService;
}
public function createEffectItems($config) {
$settings = $this->configurationService->getSettingsForExtensionName('extension');
$classNames = json_decode($settings['container']['effects'],true);
if (!is_array($classNames)) return $config;
$optionList = array();
foreach ($classNames as $key => $val) {
$optionList[] = [$val, $key];
}
$config['items'] = array_merge($config['items'], $optionList);
return $config;
}
Now I can define my own CSS classes in Typoscript setting...
Last but not least the FluidStyleContent Part:
I overrride the Fluid_tyled_content template Textmedia.html and Layout Detaulf.html.
<v:content.resources.fal uid="{data.uid}" table="tt_content" field="background_media" as="ceBackground">
<f:if condition="{ceBackground}">
{v:uri.image(treatIdAsReference: 1, src: ceBackground.0.id, maxW: 1920) -> v:variable.set(name: 'parallaxBg')}
</f:if>
</v:content.resources.fal>
<div id="c{data.uid}" {f:if(condition: '{parallaxBg}', then: 'style="background-image: url(\'{parallaxBg}\');" ')}">
</div>
For a multiple classes use: {data.effects -> v:format.replace(substring: ',', replacement: ' ')}
Best regards