Search code examples
typo3typo3-10.x

Typo3 10.4.1 extend pages with an file ref


hope a knowing being reads this.

The task is simple but something went wrong. Ive wrote an extension to extend the pages table for every page with some new props.

These values are: 1 boolean value (is extension active) 1 Text value (e.g css class name) 1 Filelink to sys_file for uploaded images

The fields itself are working as expected in backend. fields in backend But if i try to access them via fluid in frontend, there is only a lony 1 (Int) saved?

In Fluid: {data.tx_mnadditionalpagefields_extended_background_image}

leads to this -> 1 (Integer)

What iam doing wrong?

my ext_tables.sql

CREATE TABLE pages (
    tx_mnadditionalpagefields_custom_css_class varchar(255) DEFAULT '' NOT NULL,
    tx_mnadditionalpagefields_activate_extended_rules TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL,
    tx_mnadditionalpagefields_extended_background_image int(11) unsigned NOT NULL default '0'
);

my ext.../Configuration/TCA/Overrides/pages.php

<?php

defined('TYPO3_MODE') or die();

// Configure new fields:
$fields = [
    'tx_mnadditionalpagefields_custom_css_class' => [
        'label' => 'LLL:EXT:nm_addtional_page_fields/Resources/Private/Language/locallang_db.xlf:pages.tx_mnadditionalpagefields_custom_css_class',
        'exclude' => 1,
        'config' => [
            'type' => 'input',
            'max' => 255
        ],
    ],
    'tx_mnadditionalpagefields_activate_extended_rules' => [
        'exclude' => 1,
        'label' => 'LLL:EXT:nm_addtional_page_fields/Resources/Private/Language/locallang_db.xlf:pages.tx_mnadditionalpagefields_activate_extended_rules',
        'config' => [
            'type' => 'check',
            'default' => 0
        ]
    ],
    'tx_mnadditionalpagefields_extended_background_image' => [
        'exclude' => 1,
        'label' => 'LLL:EXT:nm_addtional_page_fields/Resources/Private/Language/locallang_db.xlf:pages.tx_mnadditionalpagefields_extended_background_image',
        'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
            'tx_mnadditionalpagefields_extended_background_image',
            [
                'maxitems' => 1,
                'minitems' => 0,
                'appearance' => [
                    'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference'
                ],
                //'foreign_match_fields' => array(
                //    'fieldname' => 'tx_mnadditionalpagefields_extended_background_image',
                //    'tablenames' => 'pages',
                //    'table_local' => 'sys_file',
                //),
            ],
            $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
        ),
    ]
];

// Add new fields to pages:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('pages', $fields);

// Make fields visible in the TCEforms:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
    'pages', // Table name
    '--palette--;LLL:EXT:nm_addtional_page_fields/Resources/Private/Language/locallang_db.xlf:pages.palette_title;nm_addtional_page_fields', // Field list to add
    '1', // List of specific types to add the field list to. (If empty, all type entries are affected)
    'after:nav_title' // Insert fields before (default) or after one, or replace a field
);

// Add the new palette:
$GLOBALS['TCA']['pages']['palettes']['nm_addtional_page_fields'] = [
    'showitem' => 'tx_mnadditionalpagefields_activate_extended_rules,tx_mnadditionalpagefields_custom_css_class,tx_mnadditionalpagefields_extended_background_image'
];

Extension download (WIP): download


Solution

  • For images/files, the local table stores only the count of references to files. (int)1 means, there's one reference.

    Have a look at DataProcessing for how to use these filereferences with Fluid: https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/7.4/Feature-67662-DataProcessorForFiles.html