How to integrate cropping variants in image manipulation tool in tx_news extension? - typo3

There's an awesome feature in TYPO3 8.7 called cropping variants in image manipulation tool. Details informations can be found in official feature description #75880. Thanks to this we can allow back-end user to crop one image in multiple variants, for exampple: for mobile and desktop. See image below.
Image from: https://techblog.sitegeist.de/responsive-images-with-typo3-8-7/
Configuration can be done in TCA:
'config' => [
'type' => 'imageManipulation',
'cropVariants' => [
'mobile' => [
'title' => 'LLL:EXT:ext_key/Resources/Private/Language/locallang.xlf:imageManipulation.mobile',
'allowedAspectRatios' => [
'4:3' => [
'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.4_3',
'value' => 4 / 3
],
'NaN' => [
'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.free',
'value' => 0.0
],
],
],
'desktop' => [
'title' => 'LLL:EXT:ext_key/Resources/Private/Language/locallang.xlf:imageManipulation.desktop',
'allowedAspectRatios' => [
'4:3' => [
'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.4_3',
'value' => 4 / 3
],
'NaN' => [
'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.free',
'value' => 0.0
],
],
],
]
]
I'm trying to integrate it into tx_news. I want to use existing field called fal_media. The configuration of this field you can find in the source file of tx_news in GitHub. Screenshot of the code snippet below:
Somebody have an idea how cropping variants in image manipulation can be implemented in tx_news extension for field fal_media?

Just to anwer this question and make it easy to find the solution (georgs link pointing to it)
$GLOBALS['TCA']['tx_news_domain_model_news']['columns']['fal_media']['config']['overrideChildTca']['columns']['crop'] = [
'config' => [
'cropVariants' => [
'mobile' => [
'title' => 'Mobile',
'allowedAspectRatios' => [
'4:3' => [
'title' => '4 zu 3',
'value' => 4 / 3
],
'NaN' => [
'title' => 'FREI',
'value' => 0.0
],
],
],
],
],
];
See: https://github.com/georgringer/news/issues/371

simply add cropVariant="mobile" to your f:image.

Related

TYPO3: add maxitems = 1 to an image selection for a backend module

I use the following code to make an image selection available in the backend:
(TYPO3 docs - inline - File Abstraction Layer)
'image' => [
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.images',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'image',
[
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference'
],
// custom configuration for displaying fields in the overlay/reference table
// to use the image overlay palette instead of the basic overlay palette
'overrideChildTca' => [
'types' => [
'0' => [
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => [
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
],
],
],
],
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
),
],
I want to limit the selection to 1 item which should be:
TYPO3 dosc - maxitems option
image => [
'config' => [
'maxitems' => 1,
],
],
I cannot find how to add that ... all I tried gives errors
Sometimes, you just have to find the matching part of documentation...
File abstraction layer (FAL)
The API call is \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(). The first argument is the name of the current field, the second argument is an override configuration array, (...)
So it should do with overriding a part of the generated configuration by:
'image' => [
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.images',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'image',
[
'maxitems' => 1
]
)
]

How to create a sys_file_reference inside another sys_file_reference?

I need to add some track files to a TYPO3 file reference. So I extended the TCA for sys_file_reference and added some fields. One of the fields should be a reference to another file.
It works as far that I can chose a file in the backend
Unfortunately, I can't save if I have a track added. TYPO3 throws me an exception.
#1300098528 InvalidArgumentException Incorrect reference to original file given for FileReference.
This exceptions happens because uid_local of the track reference is 0. But I don't know why this is 0 and how to fix it.
This is my TCA Configuration
'tx_eos_video_tracks' => [
'exclude' => 1,
'label' => 'Track files',
'description' => 'captions, chapters, descriptions, metadata, subtitles',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('tx_eos_video_tracks', [
'appearance' => [
'createNewRelationLinkTitle' => 'Add Track'
],
'overrideChildTca' => [
'types' => [
'0' => [
'showitem' => '
--palette--;;tx_eos_video_tracks_palette'
]
],
],
], 'vtt,srt')
],
Ok, I found the Solution. There must be always the fields uid_local, hidden, sys_language_uid, l10n_parent in the Child TCA.
There is a predefined palette ('filePalette') which adds the fields without showing them to the user.
So Changing
'overrideChildTca' => [
'types' => [
'0' => [
'showitem' => '
--palette--;;tx_eos_video_tracks_palette'
]
],
],
to
'overrideChildTca' => [
'types' => [
'0' => [
'showitem' => '
--palette--;;tx_eos_video_tracks_palette,
--palette--;;filePalette'
]
],
],
resolves my Issue

Problem with file upload TCA after upgrading to TYPO3 10

On typo3v9 i had working file upload field with this TCA configuration:
'image' => [
'exclude' => 0,
'label' => 'image upload',
'config' => [
'type' => 'group',
'internal_type' => 'db',
'uploadfolder' => 'uploads/folder',
'show_thumbs' => 1,
'size' => 5,
'allowed' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
'disallowed' => '',
],
],
i get this result:
but after migration to typo3v10 it does not work properly and give this result:
Someone have working solution for single file upload field?
I guess you mean internal_type=file ? That's deprecated. Here an example for image upload. However you can allow other types here too, I am sure you can find more info on that.
'photos' => [
'exclude' => true,
'label' => 'LLL:EXT:xxx/Resources/Private/Language/locallang_db.xlf:tx_xxx_domain_model_activity.photos',
'config' =>
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'photos',
[
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference'
],
'foreign_types' => [
'0' => [
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
]
],
'maxitems' => 30
],
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
),
],

Override TCA config for imageManipulation/crop for only one content type (CType)

I have three type of content elements (tt_content|types) which all use an image-column with each one FAL-relations for one image.
I'd like to use for 2 content elements the type = 'imageManipulation' (Docs) with 2 different configurations and for one just the image as it is.
Since the type = 'imageManipulation' is defined normally for sys_file_reference, so for all usages.
Is it possible with TCA overrides to archive different configurations for different content elements?
I tried a combination of columnsOverrides and overrideChildTca, but this doesn't work in the moment:
<?php
defined('TYPO3_MODE') or die();
(function () {
if (is_array($GLOBALS['TCA']['tt_content']['types']['mask_teaser_hero'])) {
$GLOBALS['TCA']['tt_content']['types']['mask_teaser_hero']['columnsOverrides'] = [
'tx_maskproject_teaserimage' => [
'config' => [
'overrideChildTca' => [
'columns' => [
'crop' => [
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.crop',
'config' => [
'type' => 'imageManipulation',
'cropVariants' => [
'mobile' => [
'title' => 'Mobile',
'selectedRatio' => '4:3',
'allowedAspectRatios' => [
'4:3' => [
'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.4_3',
'value' => 4 / 3
],
],
],
'desktop' => [
'title' => 'Desktop',
'selectedRatio' => '16:9',
'allowedAspectRatios' => [
'16:9' => [
'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.16_9',
'value' => 16 / 9
],
],
],
]
],
],
]
],
]
]
];
}
})();
I first thought about Typoscript TCEFORM:
https://metinyilmaz.de/artikel/typo3-image-cropvariants/
But this would also appear in each content element.
I found the mistake. The TCA override is correct. But the type was not.
I use EXT:mask_export for the content elements. In the example from the question I override the content elements which EXT:mask adds. But the exported content elements are different content elements.
The correct one is:
<?php
defined('TYPO3_MODE') or die();
(function () {
if (is_array($GLOBALS['TCA']['tt_content']['types']['myextname_teaser_hero'])) {
$GLOBALS['TCA']['tt_content']['types']['myextname_teaser_hero']['columnsOverrides'] = [
'tx_myextname_teaserimage' => [
'config' => [
'overrideChildTca' => [
'columns' => [
'crop' => [
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.crop',
'config' => [
'type' => 'imageManipulation',
'cropVariants' => [
'mobile' => [
'title' => 'Mobile',
'selectedRatio' => '4:3',
'allowedAspectRatios' => [
'4:3' => [
'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.4_3',
'value' => 4 / 3
],
],
],
'desktop' => [
'title' => 'Desktop',
'selectedRatio' => '16:9',
'allowedAspectRatios' => [
'16:9' => [
'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.16_9',
'value' => 16 / 9
],
],
],
]
],
],
]
],
]
]
];
}
})();

How to set focusArea for only one specific ctype?

I want to set different focus areas (cropVariants) for different content elements.
I found a solution for this here: https://docs.typo3.org/typo3cms/extensions/core/8.7/Changelog/8.6/Feature-75880-ImplementMultipleCroppingVariantsInImageManipulationTool.html
This works for the standard ctypes like textmedia but not for my own content element. Does anybody have a idea what the problem could be?
As I found out via Slack channel you can achieve that by overriding TCA as follows:
<?php
$originalTtContent = $GLOBALS['TCA']['tt_content'];
$overridesForTtContent = [
'types' => [
'ENTER_YOUR_CTYPE' => [
'columnsOverrides' => [
'ENTER_YOUR_IMAGE_FIELD' => [
'config' => [
'overrideChildTca' => [
'columns' => [
'crop' => [
'config' => [
'cropVariants' => [
'CROPVARIANT_TO_DISABLE' => [
'disabled' => true,
],
'YOUR_NEW_CROPVARIANT' => [
'title' => 'YOUR_NEW_CROPVARIANT',
'allowedAspectRatios' => [
'1:1' => [
'title' => 'Square',
'value' => 1 / 1
],
],
'selectedRatio' => '1:1',
'cropArea' => [
'x' => 0.0,
'y' => 0.0,
'width' => 1.0,
'height' => 1.0,
],
],
],
],
],
]
]
]
]
]
]
]
];
$GLOBALS['TCA']['tt_content'] = array_merge_recursive($originalTtContent, $overridesForTtContent);
Thanks to #kevin-appelt!