README.md 4.72 KB
Newer Older
Thomas Löffler's avatar
Thomas Löffler committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# The TCA Builder

## What does it do?

With the TCA builder you have the possibility to create
or change the fields in type list in an easy and speaking way.

Times of semicolons within field names are gone.

For example:
1. Compose the field list for the form of a content element or any other record
1. Change the types of existing definitions

## Installation

`composer require spooner-web/tcabuilder`

## Usage

Thomas Löffler's avatar
Thomas Löffler committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
### General usage

1. Instantiiate the `TcaBuilder` class
1. Set the table and type to configure (may also be a not existing type yet)
1. Use the methods to manipulate
1. Save to the TCA
1. Flush caches
1. See result

### Methods

#### Main methods

| Method name | Description | Parameters |
| ----------- | ----------- | ---------- |
| `setTable` | Sets the table to load configuration from | `string` $tableName |
| `setType` | Sets the type to load configuration from | `string` $typeName |
| `load` | Loads configuration if it's an existing type |  |
| `loadConfiguration` | Shorter method to run `setTable`, `setType` and `load` at once | `string` $tableName <br> `string` $typeName |
| `saveToTca` | Saves the manipulated configuration to TCA |  |
| `addField` | Adds a field to selected type | `string` $typeName <br> `string` $position (optional) <br> `string` $alternativeLabel (optional) |
| `addPalette` | Adds an existing palette to selected type | `string` $paletteName <br> `string` $position (optional)<br> `string` $alternativeLabel (optional) |
| `addDiv` | Adds a div (tab) to selected type | `string` $divName <br> `string` $label |
| `removeField` | Removes a field from selected type | `string` $fieldName |
| `removePalette` | Removes a palette from selected type | `string` $paletteName |
| `removeDiv` | Removes a div (tab) from selected type, either by position (index, beginning with 0) or by label | `string`&#124;`int` $positionOrLabel |
| `moveField` | Moves a field to a new position (alternatively with a new label) | `string` $fieldName <br> `string` $newPosition <br> `string` $newLabel (optional) |
| `movePalette` | Moves a palette to a new position (alternatively with a new label) | `string` $paletteName <br> `string` $newPosition <br> `string` $newLabel (optional) |
| `addOverride` | Adds a custom override of a field | `string` $fieldName <br> `array` $configuration |

#### Helper methods

| Method name | Description | Parameters | Returns |
| ----------- | ----------- | ---------- | ------- |
| `getPaletteString` | Finds the complete palette string which is used in list (for using it in position strings) | `string` $paletteName | `string` The complete palette string with `--palette--` and the possible label config |
| `getDivString` | Finds the complete div string which is used in list (for using it in position strings), either by position (index, beginning with 0) or by label | `string`&#124;`int` $positionOrLabel | `string` The complete palette string with `--div--` and the div's label |

## Examples

Thomas Löffler's avatar
Thomas Löffler committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
### Add an own content element

```php
$tcaBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\SpoonerWeb\TcaBuilder\TcaBuilder::class);
$tcaBuilder
    ->setTable('tt_content') // define table
    ->setType('test') // define type
    ->addDiv('General')
    ->addField('header', '', 'Top header!!')
    ->addField('bodytext')
    ->addField('subheader', 'after:header')
    ->addField('layout', 'before:header')
    ->addDiv('Extra')
    ->addPalette('access')
    ->addPalette('hidden', 'after:bodytext', 'Alternative label')
Thomas Löffler's avatar
Thomas Löffler committed
74
    ->saveToTca(); // save to TCA
Thomas Löffler's avatar
Thomas Löffler committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
```

### Change existing configurations

```php
$tcaBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\SpoonerWeb\TcaBuilder\TcaBuilder::class);
$tcaBuilder
    ->setTable('pages') // define table
    ->setType(3) // define type
    ->load() // load definitions
    ->removeField('doktype')
    ->removePalette('external')
    ->removeDiv(1)
    ->addPalette('external', 'after:--palette--;;layout')
    ->saveToTca(); // save back to TCA
```

Thomas Löffler's avatar
Thomas Löffler committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
```php
$tcaBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\SpoonerWeb\TcaBuilder\TcaBuilder::class);
$tcaBuilder
    ->loadConfiguration('pages', 7)
    ->removeDiv('LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.tabs.metadata')
    ->movePalette('title', 'after:' . $tcaBuilder->getPaletteString('abstract'), 'New title')
    ->addOverride(
        'title',
        [
            'label' => 'New title',
            'config' => [
                'renderType' => 'inputLink'
            ]
        ]
    )
    ->saveToTca();
```

Thomas Löffler's avatar
Thomas Löffler committed
110 111 112 113 114 115 116 117 118
### Do minimal changes

```php
$tcaBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\SpoonerWeb\TcaBuilder\TcaBuilder::class);
$tcaBuilder
    ->loadConfiguration('tt_content', 'textmedia')
    ->removePalette('headers')
    ->saveToTca();
```