Additional TCA fields and tools

This extension helps you to keep your TCA tidy and easy to maintain.

Features:

  • Provides methods for tab labels
  • Provides methods for recurring fields such as sys_language_uid, hidden, and more
  • Provides configuration presets for markdown t3editor, percent fields, currency fields, and more

Using the full configurations

return [
   'columns' => [
        'information' => \CodingMs\AdditionalTca\Tca\Configuration::full('information', $table, $extKey),
        'sys_language_uid' => \CodingMs\AdditionalTca\Tca\Configuration::full('sys_language_uid'),
        'l10n_parent' => \CodingMs\AdditionalTca\Tca\Configuration::full('l10n_parent', $table),
        'l10n_diffsource' => \CodingMs\AdditionalTca\Tca\Configuration::full('l10n_diffsource'),
        't3ver_label' => \CodingMs\AdditionalTca\Tca\Configuration::full('t3ver_label'),
        'hidden' => \CodingMs\AdditionalTca\Tca\Configuration::full('hidden'),
        'starttime' => \CodingMs\AdditionalTca\Tca\Configuration::full('starttime'),
        'endtime' => \CodingMs\AdditionalTca\Tca\Configuration::full('endtime'),
    ],
];

Using labels

return [
   'types' => [
        '1' => ['showitem' => '
        --div--;' . \CodingMs\AdditionalTca\Tca\Configuration::label('tab_general') . ',
        --div--;' . \CodingMs\AdditionalTca\Tca\Configuration::label('tab_language') . ',
            sys_language_uid,
            l10n_parent,
            l10n_diffsource,
        --div--;' . \CodingMs\AdditionalTca\Tca\Configuration::label('tab_access') . ',
            hidden,
            starttime,
            endtime,
        --div--;' . \CodingMs\AdditionalTca\Tca\Configuration::label('tab_notes') . ',
        --div--;' . \CodingMs\AdditionalTca\Tca\Configuration::label('tab_extended') . ',
        --div--;' . \CodingMs\AdditionalTca\Tca\Configuration::label('tab_seo') . ',
        --div--;' . \CodingMs\AdditionalTca\Tca\Configuration::label('tab_relations') . ',
        --div--;' . \CodingMs\AdditionalTca\Tca\Configuration::label('tab_images') . ',
        --div--;' . \CodingMs\AdditionalTca\Tca\Configuration::label('tab_files') . ',
        --div--;' . \CodingMs\AdditionalTca\Tca\Configuration::label('tab_markdown') . ',
        '],
    ],
];

Using field configuration

return [
   'columns' => [
        'slug' => [
            // field: ... -> Database field for auto generate the slug
            'config' => \CodingMs\AdditionalTca\Tca\Configuration::get('slug', false, false, '', ['field' => 'answer']),
        ],
        'rte' => [
            'config' => \CodingMs\AdditionalTca\Tca\Configuration::get('rte'),
            'defaultExtras' => 'richtext:rte_transform[flag=rte_enabled]',
        ],
        'textareaSmall' => [
            'config' => \CodingMs\AdditionalTca\Tca\Configuration::get('textareaSmall'),
        ],
        'textareaLarge' => [
            'config' => \CodingMs\AdditionalTca\Tca\Configuration::get('textareaLarge'),
        ],
        'markdown' => [
            'config' => \CodingMs\AdditionalTca\Tca\Configuration::get('markdown'),
            'defaultExtras' => 'fixed-font:enable-tab',
        ],
        'int' => [
            'config' => \CodingMs\AdditionalTca\Tca\Configuration::get('int'),
        ],
        'coordinate' => [
            'config' => \CodingMs\AdditionalTca\Tca\Configuration::get('coordinate'),
        ],
        'currency' => [
            'config' => \CodingMs\AdditionalTca\Tca\Configuration::get('currency'),
        ],
        'percent' => [
            'config' => \CodingMs\AdditionalTca\Tca\Configuration::get('percent'),
        ],
        'string' => [
            'config' => \CodingMs\AdditionalTca\Tca\Configuration::get('string'),
        ],
        'email' => [
            'config' => \CodingMs\AdditionalTca\Tca\Configuration::get('email'),
        ],
        'checkbox' => [
            'config' => \CodingMs\AdditionalTca\Tca\Configuration::get('checkbox', false, false, 'Checkbox label'),
        ],
        'link' => [
            'config' => \CodingMs\AdditionalTca\Tca\Configuration::get('link'),
        ],
        'date' => [
            // dbType: timestamp -> Database field is an integer for timestamps
            // without dbType -> Database field is a date string
            'config' => \CodingMs\AdditionalTca\Tca\Configuration::get('date', false, false, '', ['dbType' => 'timestamp']),
        ],
        'dateTime' => [
            // dbType: timestamp -> Database field is an integer for timestamps
            // without dbType -> Database field is a date string
            'config' => \CodingMs\AdditionalTca\Tca\Configuration::get('dateTime', false, false, '', ['dbType' => 'timestamp']),
        ],
        'select' => [
            'config' => \CodingMs\AdditionalTca\Tca\Configuration::get('select', true, false, '', [
                [$lll . '.template_default', 'Default'],
                [$lll . '.template_with_single_view', 'WithSingleView'],
            ]),
        ],
        'fileSingle' => [
            'config' => \CodingMs\AdditionalTca\Tca\Configuration::get('fileSingle'),
        ],
        'fileCollectionSingleInline' => [
            'config' => \CodingMs\AdditionalTca\Tca\Configuration::get('fileCollectionSingleInline'),
        ],
        'imageSingleAltTitle' => [
            // field: ... -> Database field for foreign_match_fields.fieldname
            // table: ... -> Database field for foreign_match_fields.tablenames
            'config' => \CodingMs\AdditionalTca\Tca\Configuration::get('imageSingleAltTitle', false, false, '', ['field' => 'image', 'table' => 'tx_openimmo_domain_model_anhang']),
        ],
        'imageSingleTitleDescription' => [
            // field: ... -> Database field for foreign_match_fields.fieldname
            // table: ... -> Database field for foreign_match_fields.tablenames
            'config' => \CodingMs\AdditionalTca\Tca\Configuration::get('imageSingleTitleDescription', false, false, '', ['field' => 'image', 'table' => 'tx_openimmo_domain_model_anhang']),
        ],
    ],
];

Using custom field configuration

EXT:questions/Classes/Tca/Configuration.php

<?php declare(strict_types=1);
namespace CodingMs\Questions\Tca;
use CodingMs\AdditionalTca\Tca\Configuration as ConfigurationDefaults;

class Configuration extends ConfigurationDefaults
{

    /**
     * @param string $type
     * @param bool $required
     * @param bool $readonly
     * @param string $label
     * @param array $options
     * @return array
     */
    public static function get($type, $required = false, $readonly = false, $label = '', array $options=[]): array
    {
        switch ($type) {
            case 'questionCategories':
                $config = [
                    'type' => 'select',
                    'renderType' => 'selectMultipleSideBySide',
                    'foreign_table' => 'tx_questions_domain_model_questioncategory',
                    'MM' => 'tx_questions_question_questioncategory_mm',
                    'foreign_table_where' => 'ORDER BY title',
                    'size' => 10,
                    'autoSizeMax' => 30,
                    'minitems' => 1,
                    'maxitems' => 9999,
                    'multiple' => 0,
                ];
                break;
            case 'anotherCustom':
                // ...
                break;
            default:
                $config = parent::get($type, $required, $readonly, $label, $options);
                break;
        }
        if ($readonly) {
            $config['readOnly'] = true;
        }
        return $config;
    }
}

Usage in your own TCA:

return [
   'columns' => [
        'category' => [
            'exclude' => 0,
            'label' => $lll . '.category',
            'config' => \CodingMs\Questions\Tca\Configuration::get('questionCategories'),
        ],
    ],
];

Using information fields

FlexForm

<information>
    <TCEforms>
        <exclude>0</exclude>
        <label>Support</label>
        <config>
            <type>user</type>
            <renderType>Information</renderType>
            <parameters>
                <extensionKey>questions</extensionKey>
            </parameters>
        </config>
    </TCEforms>
</information>

ext_conf_template.txt

# cat=extension/updateService/10; type=boolean; label= LLL:EXT:additional_tca/Resources/Private/Language/locallang.xlf:tx_additionaltca_ext_conf_template.extension_update_service_active
extension.updateService.active = 1

# cat=extension/updateService/20; type=string; label= LLL:EXT:additional_tca/Resources/Private/Language/locallang.xlf:tx_additionaltca_ext_conf_template.extension_update_service_email
extension.updateService.email = typo3(at)coding(dot)ms

Example of a simple TCA file

<?php
$extKey = 'questions';
$table = 'tx_questions_domain_model_questioncategory';
$lll = 'LLL:EXT:' . $extKey . '/Resources/Private/Language/locallang_db.xlf:' . $table;

return [
    'ctrl' => [
        'title' => $lll,
        'label' => 'title',
        'label_alt' => 'description',
        'label_alt_force' => true,
        'tstamp' => 'tstamp',
        'crdate' => 'crdate',
        'cruser_id' => 'cruser_id',
        'sortby' => 'sorting',
        'versioningWS' => true,
        'languageField' => 'sys_language_uid',
        'transOrigPointerField' => 'l10n_parent',
        'transOrigDiffSourceField' => 'l10n_diffsource',
        'delete' => 'deleted',
        'enablecolumns' => [
            'disabled' => 'hidden',
        ],
        'searchFields' => 'title,description',
        'iconfile' => 'EXT:questions/Resources/Public/Icons/iconmonstr-help-3.svg'
    ],
    'interface' => [
        'showRecordFieldList' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, title, description',
    ],
    'types' => [
        '1' => ['showitem' => '
            information,
            title,
            description,
        --div--;' . \CodingMs\Questions\Tca\Configuration::label('tab_language') . ',
            sys_language_uid,
            l10n_parent,
            l10n_diffsource,
        --div--;' . \CodingMs\Questions\Tca\Configuration::label('tab_access') . ',
            hidden,
            starttime,
            endtime
        '],
    ],
    'columns' => [
        'information' =>  \CodingMs\Questions\Tca\Configuration::full('information', '', $extKey),
        'sys_language_uid'  => \CodingMs\Questions\Tca\Configuration::full('sys_language_uid'),
        'l10n_parent' => \CodingMs\Questions\Tca\Configuration::full('l10n_parent'),
        'l10n_diffsource' => \CodingMs\Questions\Tca\Configuration::full('l10n_diffsource'),
        't3ver_label' => \CodingMs\Questions\Tca\Configuration::full('t3ver_label'),
        'hidden' => \CodingMs\Questions\Tca\Configuration::full('hidden'),
        'title' => [
            'exclude' => 0,
            'label' => $lll . '.title',
            'config'  => \CodingMs\Questions\Tca\Configuration::get('string', true),
        ],
        'description' => [
            'exclude' => 0,
            'label' => $lll . '.description',
            'config'  => \CodingMs\Questions\Tca\Configuration::get('string'),
        ],
    ],
];

Migration tasks

  • SupportRow entfernen:
    • ext_conf_template.txt
    • Translations (locallang_support.xlf)
    • Im TCA support-row durch information-row ersetzen
    • Tca/InformationRow.php entfernen
    • Service/UpdateService.php entfernen
  • TCA
    • ConfigurationPreset.php entfernen
    • ConfigurationPresetCustom.php wird zu Configuration.php use CodingMs\AdditionalTca\Tca\Configuration as ConfigurationDefaults;
  • Allgemein
    • Dependencies in composer.json + ext_emconf.php