Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicates if parent-child record is not following same naming convention #9

Closed
mkarulin opened this issue Apr 13, 2023 · 5 comments
Closed

Comments

@mkarulin
Copy link
Contributor

TYPO3 version 11.5
l10nmgr version: 11.0.0 alpha

Description:
The naming of the record tables seems to have an impact of the order of localization which can cause broken relations and duplicates:

Parent record of "tx_a_b" with inline field with "foreign_table" of "tx_a_a" creates 2 new child records, an invalid one that is attached to the default record of "tx_a_a", and another (the correct one) that is attached to the localization of "tx_a_a".

If i change the table and tca to more appropriate naming convention of tx_a_b and tx_a_b_a the file imports correctly with 1 new parent record and 1 new child record localizations.

In a single package it is possible to follow the correct naming convention but what if i require tables from another package?
I think there should be a more elegant way to determine the order of localization.

How to reproduce:
create 2 new TCA files and ext_tables.sql file:

test/Configuration/TCA/tx_a_b.php

<?php

return [
    'ctrl' => [
        'title' => 'tx_a_b (PARENT)',
        'label' => 'input_1',
        'tstamp' => 'tstamp',
        'crdate' => 'crdate',
        'cruser_id' => 'cruser_id',
        'delete' => 'deleted',
        'sortby' => 'sorting',
        'iconfile' => 'EXT:styleguide/Resources/Public/Icons/tx_styleguide.svg',
        'versioningWS' => true,
        'origUid' => 't3_origuid',
        'languageField' => 'sys_language_uid',
        'transOrigPointerField' => 'l10n_parent',
        'transOrigDiffSourceField' => 'l10n_diffsource',
        'translationSource' => 'l10n_source',
        'enablecolumns' => [
            'disabled' => 'hidden',
        ],
    ],

    'columns' => [
        'hidden' => [
            'exclude' => 1,
            'config' => [
                'type' => 'check',
                'items' => [
                    ['Disable'],
                ],
            ],
        ],
        'sys_language_uid' => [
            'exclude' => true,
            'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.language',
            'config' => [
                'type' => 'language',
            ],
        ],
        'l10n_parent' => [
            'displayCond' => 'FIELD:sys_language_uid:>:0',
            'label' => 'Translation parent',
            'config' => [
                'type' => 'select',
                'renderType' => 'selectSingle',
                'items' => [
                    [
                        '',
                        0,
                    ],
                ],
                'foreign_table' => 'tx_a_b',
                'foreign_table_where' => 'AND {#tx_a_b}.{#pid}=###CURRENT_PID### AND {#tx_a_b}.{#sys_language_uid} IN (-1,0)',
                'default' => 0,
            ],
        ],
        'l10n_source' => [
            'exclude' => true,
            'displayCond' => 'FIELD:sys_language_uid:>:0',
            'label' => 'Translation source',
            'config' => [
                'type' => 'select',
                'renderType' => 'selectSingle',
                'items' => [
                    [
                        '',
                        0,
                    ],
                ],
                'foreign_table' => 'tx_a_b',
                'foreign_table_where' => 'AND {#tx_a_b}.{#pid}=###CURRENT_PID### AND {#tx_a_b}.{#uid}!=###THIS_UID###',
                'default' => 0,
            ],
        ],
        'l10n_diffsource' => [
            'config' => [
                'type' => 'passthrough',
                'default' => '',
            ],
        ],
        'input_1' => [
            'exclude' => 1,
            'label' => 'input_1 name',
            'config' => [
                'type' => 'input',
                'size' => '30',
            ],
        ],
        'inline_1' => [
            'exclude' => 1,
            'label' => 'inline_1 description',
            'description' => 'field description',
            'config' => [
                'type' => 'inline',
                'foreign_table' => 'tx_a_a',
                'foreign_field' => 'parentid',
                'foreign_table_field' => 'parenttable',
                'appearance' => [
                    'showSynchronizationLink' => true,
                    'showAllLocalizationLink' => true,
                    'showPossibleLocalizationRecords' => true,
                ],
            ],
        ],

    ],

    'types' => [
        '0' => [
            'showitem' => '
                input_1,inline_1,
                --div--;meta,
                    disable, sys_language_uid, l10n_parent, l10n_source,

            ',
        ],
    ],

];

test/Configuration/TCA/tx_a_a.php

<?php

return [
    'ctrl' => [
        'title' => 'tx_a_a (CHILD)',
        'label' => 'input_1',
        'tstamp' => 'tstamp',
        'crdate' => 'crdate',
        'cruser_id' => 'cruser_id',
        'delete' => 'deleted',
        'sortby' => 'sorting',
        'iconfile' => 'EXT:styleguide/Resources/Public/Icons/tx_styleguide.svg',
        'languageField' => 'sys_language_uid',
        'transOrigPointerField' => 'l10n_parent',
        'transOrigDiffSourceField' => 'l10n_diffsource',
        'translationSource' => 'l10n_source',
        'enablecolumns' => [
            'disabled' => 'disable',
        ],
    ],

    'columns' => [

        'l10n_diffsource' => [
            'config' => [
                'type' => 'passthrough',
                'default' => '',
            ],
        ],
        'disable' => [
            'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.disable',
            'config' => [
                'type' => 'check',
            ],
        ],
        'sys_language_uid' => [
            'exclude' => true,
            'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.language',
            'config' => [
                'type' => 'language',
            ],
        ],
        'l10n_parent' => [
            'displayCond' => 'FIELD:sys_language_uid:>:0',
            'label' => 'Translation parent',
            'config' => [
                'type' => 'select',
                'renderType' => 'selectSingle',
                'items' => [
                    [
                        '',
                        0,
                    ],
                ],
                'foreign_table' => 'tx_a_a',
                'foreign_table_where' => 'AND {#tx_a_a}.{#pid}=###CURRENT_PID### AND {#tx_a_a}.{#sys_language_uid} IN (-1,0)',
                'default' => 0,
            ],
        ],
        'l10n_source' => [
            'exclude' => true,
            'displayCond' => 'FIELD:sys_language_uid:>:0',
            'label' => 'Translation source',
            'config' => [
                'type' => 'select',
                'renderType' => 'selectSingle',
                'items' => [
                    [
                        '',
                        0,
                    ],
                ],
                'foreign_table' => 'tx_a_a',
                'foreign_table_where' => 'AND {#tx_a_a}.{#pid}=###CURRENT_PID### AND {#tx_a_a}.{#uid}!=###THIS_UID###',
                'default' => 0,
            ],
        ],

        'parentid' => [
            'config' => [
                'type' => 'passthrough',
            ],
        ],
        'parenttable' => [
            'config' => [
                'type' => 'passthrough',
            ],
        ],
        'input_1' => [
            'l10n_mode' => 'prefixLangTitle',
            'label' => 'input_1',
            'config' => [
                'type' => 'input',
                'size' => '30',
            ],
        ],

    ],
    'types' => [
        '0' => [
            'showitem' => '
                --div--;General, input_1,
                --div--;meta, disable, sys_language_uid, l10n_parent, l10n_source,
            ',
        ],
    ],

];
#
# Table structure for table 'tx_a_b'
#
CREATE TABLE tx_a_b (
    input_1 text,
    inline_1 int(11) DEFAULT '0' NOT NULL

);

#
# Table structure for table 'tx_a_a'
#
CREATE TABLE tx_a_a (
   parentid int(11) DEFAULT '0' NOT NULL,
   parenttable text,

   input_1 text,
);

Create record a_b (PARENT) and add to it a_a (CHILD).
Export and import in another language

Expected results:
1 new localized parent + 1 new localized child

Actual results:
1 new localized parent + 2 new localized children, one connected to the wrong (default) languge.

@Bunnyfield
Copy link
Contributor

Could it be, that you are in the wrong repository? There is no 11.0.0 version in here, but there is one in the private repository, that you should have access to. So could you please report bugs about that version there, so we don't get lost?

@Bunnyfield
Copy link
Contributor

Bunnyfield commented Apr 13, 2023

Additionally you might want to check the inlineTablesConfig feature, which can be found in Classes/Model/L10nBaseService.php

/*
* Special handling for 1:n relations
*
* Example: Inline elements (1:n) with tt_content as parent
*
* Config example:
* $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['l10nmgr']['inlineTablesConfig'] = [
*    'tx_myext_myelement' => [
*       'parentField' => 'content',
*       'childrenField' => 'myelements',
*   ]];
*/

It was introduced with 4cd1b70

@Bunnyfield
Copy link
Contributor

Since I am convinced that inlineTablesConfig will do the job here, I will close the issue. Feel free to reopen it, if it doesn't.

@mkarulin
Copy link
Contributor Author

mkarulin commented Apr 14, 2023

@Bunnyfield thanks, but how would that work in this case:
The parent record is named: "tx_lp_product"
Child records tx_lp_domain_model_section and tx_lp_domain_model_keyfeature.
Configuration i tried (In yaml format):

    inlineTablesConfig:
      tx_lp_domain_model_keyfeature:
        parentField: 'product'
        childrenField: 'keyfeature_sections'
      tx_lp_domain_model_section:
        parentField: 'product'
        childrenField: 'custom_sections'

parent (tx_lp_product.php)

...
'custom_sections' => [
    'exclude' => true,
    'label' => 'custom_sections',
    'config' => [
        'type' => 'inline',
        'allowed' => 'tx_lp_domain_model_section',
        'foreign_table' => 'tx_lp_domain_model_section',
        'foreign_sortby' => 'sorting',
        'foreign_field' => 'product',
        'minitems' => 0,
        'maxitems' => 99,
    ],
],
'keyfeature_sections' => [
    'exclude' => true,
    'label' => 'keyfeature_sections',
    'config' => [
        'type' => 'inline',
        'foreign_table' => 'tx_lp_domain_model_keyfeature',
        'foreign_sortby' => 'sorting',
        'foreign_field' => 'product',
        'minitems' => 0,
        'maxitems' => 99,
    ],
],...

parentField in tx_lp_domain_model_section.php & tx_lp_domain_model_keyfeature.php:

...
'product' => [
    'config' => [
        'type' => 'passthrough',
    ],
],
...

@Bunnyfield
Copy link
Contributor

The point is, that a field of type "passthrough" by definition does not contain any information, that would be necessary to determine the actual relation for an automated translation process.

So actually this is the same problem as described in the other issue #8 : You have to provide additional knowledge, that is only available to you as an editor because you can see the given structure in the backend. The L10nmgr is somehow comparable to a blind user, who needs additional information about the relations between elements. If this is not given properly, it can not work the same way you would as a user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants