Project

General

Profile

Actions

Bug #86876

closed

TCA columnsOverrides ignores default value

Added by Roman Büchler over 5 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
FormEngine aka TCEforms
Target version:
-
Start date:
2018-11-07
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
9
PHP Version:
7.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

Defining a differnet default value for a field in the 'types' array doesn't work.

For example it would be useful to set the default frame for a content element of type gridelement_pi1 to none. To do so the TCA might be overriden as following:

File: ext/myplugin/Configuration/TCA/Overrides/gridelements.php
File content:

$columnsOverrides = [];
$columnsOverrides['frame_class']['config'] = [
    'default' => 'none',
];
$GLOBALS['TCA']['tt_content']['types']['gridelements_pi1'] = array_merge(
    $GLOBALS['TCA']['tt_content']['types']['gridelements_pi1'],
    ['columnsOverrides' => $columnsOverrides]
);

Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Bug #76661: Suggest Wizard ajax response ignores columnsOverridesClosed2016-06-16

Actions
Related to TYPO3 Core - Bug #99381: TCA columnsOverrides overrides default values set via defValsResolved2022-12-15

Actions
Actions #1

Updated by Michael Stucki over 5 years ago

  • Status changed from New to Closed

Wrong project!

Actions #2

Updated by Michael Stucki over 5 years ago

  • Project changed from 9 to TYPO3 Core
  • Status changed from Closed to New
  • TYPO3 Version set to 9
Actions #3

Updated by Thomas Anders over 5 years ago

  • Subject changed from TCA columnsOverrides default to TCA columnsOverrides ignores default value
  • PHP Version set to 7.2

I have the same problem. I've defined the field `author` in tt_content table:

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
    'tt_content',
    [
        'author' => [
            'config' => [
                'type' => 'input',
                'size' => 30,
            ],
            'exclude' => '1',
            'label' => 'Autor',
        ],
    ]
);

I added this field to my own CE 'myext_quotation'.
When I add 'default' => 'Test' into the `addTCAcolumns`, it is perfectly working with my CE.

But now I override the filed for my CE `myext_quotation` like this:

$GLOBALS['TCA']['tt_content']['types']['myext_quotation'] = [
    'columnsOverrides' => [
        'author' => [
            'config' => [
                'type' => 'input',
                'default' => 'Hallo',
            ],
        ],
    ],
];

When I now add a new element of this Type, the field has the value of the 'addTCAcolumns' block.
If i leave the default value initially empty and then override the filed it gets ignored.

Actions #4

Updated by Daniel Siepmann about 5 years ago

  • Related to Bug #76661: Suggest Wizard ajax response ignores columnsOverrides added
Actions #5

Updated by Daniel Siepmann about 5 years ago

Same Issue for suggest wizard: #76661
There is already a patch attached. This should be the same in this case. There is a small piece of code missing, which merges the arrays.

I guess someone only has to find the accordingly place, we then could refactor the patch to provide a new method to merge the columnsOverrides and use this new method.

For Content Element Wizard, the default Value can already be added. See: https://docs.typo3.org/typo3cms/TSconfigReference/PageTsconfig/Mod.html#newcontentelement-wizarditems it's mod.wizards.newContentElement.wizardItems.[group].elements.[name].tt_content_defValues.

I'm not sure when default from TCA is applied, is it also applied if one changes the CType? Or is a field unchanged in that case? If so, it doesn't make sense to use default for tt_content depending on type I guess.

Actions #6

Updated by David Gurk over 4 years ago

The value for the backend form field is set in backend/Classes/Form/Container/SingleFieldContainer

Even if $parameterArray['fieldConf']['config']['default'] contains the correct value (including columnsOverrides), the defined default value for the fields comes from $this->data['databaseRow'][$fieldName]. But this data depends on the processing within backend/Classes/Form/FormDataProvider
which a defined in ['formEngine']['formDataGroup']['tcaDatabaseRecord'] within the DefaultConfiguration

"DatabaseRowDefaultValues" sets the value. But the issue here is, that the "TcaColumnsOverrides" comes after "DatabaseRowDefaultValues".
I've tried simply changing the dependency, so that "DatabaseRowDefaultValues" depends on "TcaColumnsOverrides", but it didn't worked out. I run into a dependency cycle exception.

I currently have no clue how to resolve this dependency hell. :-/

Actions #7

Updated by Gianluigi Martino over 4 years ago

Push...
Have the same problem but no solutions :-(

Actions #8

Updated by Hendrik no-lastname-given over 4 years ago

It looks like the dependencies of the dataproviders are a bit messed up here.

I solved it by adding my own dataprovider at the end of the list which puts again the default value from processedTCa into the databaseRow default values (tested only in TYPO3 8.7 yet)

DatabaseRecordSetColumnDefaultValue.php:

namespace Ruhmesmeile\RmCustomElements\DataProviders;

use TYPO3\CMS\Backend\Form\FormDataProviderInterface;

class DatabaseRecordSetColumnDefaultValue implements FormDataProviderInterface
{
    public function addData(array $result)
    {

        foreach ($result['processedTca']['columns'] as $columnName => $column) {

            $default = $column['config']['default'] ?? null;
            if (!$result['databaseRow'][$columnName] || empty($result['databaseRow'][$columnName])) {
                if ($default) {
                    $result['databaseRow'][$columnName] = [$default];
                }
            }
        }

        return $result;
    }
}

ext_localconf.php:

$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['tcaDatabaseRecord'][\Ruhmesmeile\RmCustomElements\DataProviders\DatabaseRecordSetColumnDefaultValue::class] = [
    'depends' => [
        \TYPO3\CMS\Backend\Form\FormDataProvider\TcaColumnsOverrides::class,
    ]
];

Actions #9

Updated by Susanne Moog about 4 years ago

  • Category set to FormEngine aka TCEforms
Actions #10

Updated by Gerrit Code Review about 4 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64081

Actions #11

Updated by Gerrit Code Review almost 4 years ago

Patch set 1 for branch 9.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64352

Actions #12

Updated by Oliver Bartsch almost 4 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #13

Updated by Benni Mack almost 4 years ago

  • Status changed from Resolved to Closed
Actions #14

Updated by Helmut Hummel over 1 year ago

  • Related to Bug #99381: TCA columnsOverrides overrides default values set via defVals added
Actions

Also available in: Atom PDF