TYPO3 Agentur Hacks

The challenge we faced at our agency was this: How can we create custom `cropVariants` (for `fal_media`) within the TYPO3 `news` extension (TYPO3 v9) to provide specific cropping templates or masks—such as aspect ratios of 12:1, 8:3, or others of our choice? The standard solution—like the one shown at https://github.com/georgringer/news/issues/371—did not work for us.

 

 

We needed the cropVariants for a type that was previously created in

 

/typo3conf/ext/DEINEEXTENSION/Configuration/TCA/Overrides/tx_news_domain_model_news.php

 

with

 

$GLOBALS['TCA']['tx_news_domain_model_news']['columns']['type']['config']['items']['DEINEEXTENSION\DEINHERSTELLER\Domain\Model\DEINTYPENAME'] =$GLOBALS['TCA']['tx_news_domain_model_news']['columns']['type']['config']['items']['DEINEEXTENSION\DEINHERSTELLER\Domain\Model\DEINTYPENAME'] =['DEINE-BESCHREIBUNG, 'DEINEEXTENSION\DEINHERSTELLER\Domain\Model\DEINTYPENAME'] ;

 

In the same file, we then add the desired variants using (for example!)

 

$GLOBALS['TCA']['tx_news_domain_model_news']['types'][''DEINEEXTENSION\DEINHERSTELLER\Domain\Model\DEINTYPENAME']['columnsOverrides']['fal_media']['config'] = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(

    'fal_media',

    [

                               'overrideChildTca' => ['columns' => ['crop' => ['config' => [ 'cropVariants' => [

                                               'default' => [

                                                               'title' => 'Default',

                                                               'allowedAspectRatios' => [

                                                                                              '16:9' => [

                                                                                                              'title' => '16 zu 9',

                                                                                                              'value' => 16 / 9

                                                                                              ],

                                                                                              '3:2' => [

                                                                                                              'title' => '3 zu 2',

                                                                                                              'value' => 3 / 2

                                                                                              ],

                                                                                              '4:3' => [

                                                                                                              'title' => '4 zu 3',

                                                                                                              'value' => 4 / 3

                                                                                              ],

                                                                                              '1:1' => [

                                                                                                              'title' => '1 zu 1',

                                                                                                              'value' => 1 / 1

                                                                                              ],

                                                                                              '945:275' => [

                                                                                                              'title' => '945 zu 275',

                                                                                                              'value' => 945 / 275

                                                                                              ],

                                                                                              'NaN' => [

                                                                                                              'title' => 'FREI',

                                                                                                              'value' => 0.0

                                                                                              ],

                                                               ],

                                               ],

                               ],],],],],

                ]

);

 

Clear the caches, reload the backend, and that’s it! Observed at our agency on a website using the TYPO3 9.5 CMS.