dora
dora

Reputation: 1344

In TYPO3 can BE TCA forms be created as Partials and be used in Multiple Plugins?

I have two different FE Plugins A and B (for saying) with TCA forms in their respective configuration/tca/ folders.

For plugin "A" TCA form is A_TCA.php and for "B" it is 'B_TCA.php`. These two forms have many input fields in common. (like title,name,description and category)

Is there a way I can define something like _partial.php which can be rendered by A_TCA.php and B_TCA.php and re-used?

It would be amazing if something like this is possible

I'm using TYPO3 V 6.1 and extension builder

Upvotes: 1

Views: 248

Answers (1)

biesior
biesior

Reputation: 55798

Why not? TCA config is nothing more than PHP array, so you can include_once() your partial file and just combine it with 'main' TCA, just always try to make sure that the name of variable is unique in whole system especially when you wanna to make many partials (ie: $TxMyextTCApartForAandB):

_partial.php

<?php

$TxMyextCommonPartial = array(
    'interface'=> array(
        'showRecordFieldList' => 'name, url',
    ),
    'types'    => array(
        '1' => array('showitem' => 'name, url'),
    ),
    'columns'  => array(
        'name' => array(
            'exclude' => 0,
            'label'   => 'Name of item',
            'config'  => array(
                'type' => 'input',
                'size' => 30,
                'eval' => 'trim'
            ),
        ),
        'url'  => array(
            'exclude' => 0,
            'label'   => 'URL of item',
            'config'  => array(
                'type' => 'input',
                'size' => 30,
                'eval' => 'trim'
            ),
        ),
    ),
);

A_TCA.php:

<?php
if (!defined ('TYPO3_MODE')) {
    die ('Access denied.');
}

include_once('_partial.php');

$TCA['tx_myext_domain_model_atable'] = array(
    'ctrl' => $TCA['tx_myext_domain_model_atable']['ctrl'],
    'interface' => array(
        'showRecordFieldList' => $TxMyextCommonPartial['interface']['showRecordFieldList'].', additional_field_only_in_a_tca',
    ),
    'types' => array(
        '1' => $TxMyextCommonPartial['types']['1']['showitem'].', additional_field_only_in_a_tca',
    ),
    'palettes' => array(
        '1' => array('showitem' => ''),
    ),
    'columns' => array(

        'name' => $TxMyextCommonPartial['columns']['name'],

        'url' => $TxMyextCommonPartial['columns']['url'],

        'additional_field_only_in_a_tca' => array(
            'exclude' => 0,
            'label' => 'Additional field in A only',
            'config' => array(
                'type' => 'input',
                'size' => 4,
                'eval' => 'int'
            ),
        ),

    ),
);

or even...

include_once('_partial.php');

$TCA['tx_myext_domain_model_atable'] = array(
    'ctrl' => $TCA['tx_myext_domain_model_atable']['ctrl'],
    'interface' => $TxMyextCommonPartial['interface'],
    'types'     => $TxMyextCommonPartial['types'],
    'palettes'  => $TxMyextCommonPartial['palettes'],
    'columns'   => $TxMyextCommonPartial['columns'],
);

Upvotes: 1

Related Questions